https://github.com/devcyclehq/python-server-sdk
DevCycle - Python Server SDK
https://github.com/devcyclehq/python-server-sdk
continuous-delivery continuous-deployment devcycle devops feature-flags feature-toggles openfeature
Last synced: 9 months ago
JSON representation
DevCycle - Python Server SDK
- Host: GitHub
- URL: https://github.com/devcyclehq/python-server-sdk
- Owner: DevCycleHQ
- License: mit
- Created: 2021-11-23T20:29:36.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T14:57:44.000Z (about 1 year ago)
- Last Synced: 2025-01-18T16:12:10.592Z (12 months ago)
- Topics: continuous-delivery, continuous-deployment, devcycle, devops, feature-flags, feature-toggles, openfeature
- Language: Python
- Homepage: https://docs.devcycle.com/
- Size: 569 KB
- Stars: 19
- Watchers: 7
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DevCycle Python Server SDK
The DevCycle Python SDK used for feature management.
This SDK allows your application to interface with the [DevCycle Bucketing API](https://docs.devcycle.com/bucketing-api/#tag/devcycle).
## Requirements
* Python 3.9+
## Installation
```sh
pip install devcycle-python-server-sdk
```
(you may need to run `pip` with root permission: `sudo pip install devcycle-python-server-sdk`)
## Getting Started
The core DevCycle objects are in the `devcycle_python_sdk` package. To get started, import the `DevCycleLocalClient` class and the `DevCycleLocalOptions` class. The `DevCycleLocalClient` class is used to interact with the DevCycle API. The `DevCycleLocalOptions` class is used to configure the client.
```python
from devcycle_python_sdk import DevCycleLocalClient, DevCycleLocalOptions
from devcycle_python_sdk.models.user import DevCycleUser
options = DevCycleLocalOptions()
# create an instance of the client class
client = DevCycleLocalClient('DEVCYCLE_SERVER_SDK_KEY', options)
user = DevCycleUser(
user_id='test',
email='example@example.ca',
country='CA'
)
value = client.variable_value(user, 'variable-key', 'default-value')
```
The DevCycle client is designed to work as a singleton in your application. You should create a single instance of the client during application initialization
## OpenFeature Support
This SDK provides an alpha implementation of the [OpenFeature](https://openfeature.dev/) Provider interface. Use the `get_openfeature_provider()` function on the DevCycle SDK client to obtain a provider for OpenFeature.
```python
from openfeature import api
devcycle_client = DevCycleLocalClient('DEVCYCLE_SERVER_SDK_KEY', options)
api.set_provider(devcycle_client.get_openfeature_provider())
```
More details are in the [DevCycle Python SDK OpenFeature Provider](OpenFeature.md) guide.
> :warning: **OpenFeature support is in an early release and may have some rough edges**. Please report any issues to us and we'll be happy to help!
## Usage
To find usage documentation, visit our [docs](https://docs.devcycle.com/docs/sdk/server-side-sdks/python#usage).
## Development
When developing the SDK it is recommended that you have both a 3.8 and 3.12 python interpreter installed in order to verify changes across different versions of python.
### Dependencies
To set up dependencies for local development, run:
```bash
pip install -r requirements.test.txt
```
To run the example app against the local version of the API for testing and development, run:
```bash
pip install --editable .
```
from the top level of the repo (same level as setup.py). Then run the example app as normal:
```bash
python example/local_bucketing_client_example.py
```
### Linting & Formatting
Linting checks on PRs are run using [ruff](https://github.com/charliermarsh/ruff), and are configured using `.ruff.toml`. To run the linter locally, run this command from the top level of the repo:
```bash
ruff check .
```
Ruff can automatically fix simple linting errors (the ones marked with `[*]`). To do so, run:
```bash
ruff check . --fix
```
Formatting checks on PRs are done using [black](https://github.com/psf/black). To run the formatter locally, run this command from the top level of the repo:
```bash
black .
```
### Unit Tests
To run the unit tests, run:
```bash
pytest
```
### Benchmarks
To run the benchmarks, run:
```bash
pytest --benchmark-only
```
### Protobuf Code Generation
To generate the protobuf source files run the following from the root of the project. Ensure you have `protoc` installed.
```bash
protoc --proto_path=./protobuf/ --python_out=devcycle_python_sdk/protobuf --pyi_out=devcycle_python_sdk/protobuf variableForUserParams.proto
```
This will rebuild the `variableForUserParams_pb2.py` file. DO NOT edit this file directly.