Skip to content

DevCycleHQ/python-server-sdk

Repository files navigation

DevCycle Python Server SDK

The DevCycle Python SDK used for feature management.

This SDK allows your application to interface with the DevCycle Bucketing API.

Requirements.

  • Python 3.8+

Installation

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.

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='[email protected]',
    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 Provider interface. Use the get_openfeature_provider() function on the DevCycle SDK client to obtain a provider for OpenFeature.

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 guide.

⚠️ 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.

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:

pip install -r requirements.test.txt

To run the example app against the local version of the API for testing and development, run:

pip install --editable .

from the top level of the repo (same level as setup.py). Then run the example app as normal.

Linting & Formatting

Linting checks on PRs are run using ruff, and are configured using .ruff.toml. To run the linter locally, run this command from the top level of the repo:

ruff check .

Ruff can automatically fix simple linting errors (the ones marked with [*]). To do so, run:

ruff check . --fix

Formatting checks on PRs are done using black. To run the formatter locally, run this command from the top level of the repo:

black .

Unit Tests

To run the unit tests, run:

pytest

Benchmarks

To run the benchmarks, run:

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.

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.