OpenFeature provider for Unleash
Project description
Unleash Provider for OpenFeature
This provider is designed to use Unleash.
Installation
pip install openfeature-provider-unleash
Requirements
- Python 3.9+
openfeature-sdk>=0.8.2UnleashClient>=6.3.0
Configuration and Usage
Instantiate a new UnleashProvider instance and configure the OpenFeature SDK to use it:
from openfeature import api
from openfeature.contrib.provider.unleash import UnleashProvider
# Initialize the provider with your Unleash configuration
provider = UnleashProvider(
url="https://my-unleash-instance.com",
app_name="my-python-app",
api_token="my-api-token",
)
# Initialize the provider (required before use)
provider.initialize()
api.set_provider(provider)
Configuration options
url: The URL of your Unleash serverapp_name: The name of your applicationapi_token: The API token for authentication
Evaluation context mapping
When evaluating flags, the OpenFeature EvaluationContext is mapped to the Unleash context as follows:
EvaluationContext.targeting_key→ UnleashuserIdEvaluationContext.attributes→ merged into the Unleash context as-is
Event handling
The Unleash provider supports OpenFeature events for monitoring provider state changes:
from openfeature.event import ProviderEvent
def on_provider_ready(event_details):
print(f"Provider {event_details['provider_name']} is ready")
def on_provider_error(event_details):
print(f"Provider error: {event_details['error_message']}")
def on_configuration_changed(event_details):
print(f"Configuration changed, flags: {event_details.get('flag_keys', [])}")
# Add event handlers
provider.add_handler(ProviderEvent.PROVIDER_READY, on_provider_ready)
provider.add_handler(ProviderEvent.PROVIDER_ERROR, on_provider_error)
provider.add_handler(
ProviderEvent.PROVIDER_CONFIGURATION_CHANGED, on_configuration_changed
)
# Remove event handlers
provider.remove_handler(ProviderEvent.PROVIDER_READY, on_provider_ready)
Supported events:
ProviderEvent.PROVIDER_READY: Emitted when the provider is ready to evaluate flagsProviderEvent.PROVIDER_ERROR: Emitted when the provider encounters an errorProviderEvent.PROVIDER_CONFIGURATION_CHANGED: Emitted when flag configurations are updated
Note: ProviderEvent.PROVIDER_STALE handlers can be registered but are not currently emitted by this provider.
Supported flag types
This provider supports resolving the following types via the OpenFeature client:
- Boolean (
get_boolean_value/details): usesUnleashClient.is_enabled - String (
get_string_value/details): from variant payload - Integer (
get_integer_value/details): from variant payload - Float (
get_float_value/details): from variant payload - Object (
get_object_value/details): from variant payload, JSON-parsed if needed
Example usage
from openfeature import api
from openfeature.contrib.provider.unleash import UnleashProvider
from openfeature.evaluation_context import EvaluationContext
# Initialize the provider
provider = UnleashProvider(
url="https://your-unleash-instance.com",
app_name="my-python-app",
api_token="my-token"
)
provider.initialize()
api.set_provider(provider)
# Get a client and evaluate flags
client = api.get_client()
# Boolean flag evaluation
is_enabled = client.get_boolean_value("my-feature", False)
print(f"Feature is enabled: {is_enabled}")
# String flag evaluation with context
context = EvaluationContext(targeting_key="user123", attributes={"sessionId": "session456"})
variant = client.get_string_value("my-variant-flag", "default", context)
print(f"Variant: {variant}")
# Shutdown when done
provider.shutdown()
Development
Running tests
uv run test --frozen
Integration tests require Docker to be installed and running. To run only integration tests:
uv run test -m integration --frozen
To skip integration tests:
uv run test -m "not integration" --frozen
Type checking
uv run mypy-check
Linting
Run Ruff checks:
uv run ruff check
License
Apache 2.0 - See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openfeature_provider_unleash-0.1.2.tar.gz.
File metadata
- Download URL: openfeature_provider_unleash-0.1.2.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb4698f7c0227fa222b4e4c7e030b8fbe7086c726ebe7aac5e3ffcdd2b746538
|
|
| MD5 |
446fcee559e2b19ed0f85b29aec7bf6a
|
|
| BLAKE2b-256 |
5b85a1aaf9e86934c397d58111c999ca91c958d7febd886850bad457b7a6421e
|
Provenance
The following attestation bundles were made for openfeature_provider_unleash-0.1.2.tar.gz:
Publisher:
release.yml on open-feature/python-sdk-contrib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openfeature_provider_unleash-0.1.2.tar.gz -
Subject digest:
cb4698f7c0227fa222b4e4c7e030b8fbe7086c726ebe7aac5e3ffcdd2b746538 - Sigstore transparency entry: 1109807564
- Sigstore integration time:
-
Permalink:
open-feature/python-sdk-contrib@2dea4112057e558e59ba4beee17e5fad716c35b9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-feature
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2dea4112057e558e59ba4beee17e5fad716c35b9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file openfeature_provider_unleash-0.1.2-py3-none-any.whl.
File metadata
- Download URL: openfeature_provider_unleash-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc91ef907998e7518c6955b2d9a526c75d09cd14566dd12b5c79468bc061e55
|
|
| MD5 |
21a36f3bf07c5f8c29e96d049adb788b
|
|
| BLAKE2b-256 |
0187813d6c9bd50c5e5c9022d8fa392009b9712ef3d8e5e171855cf530dd5919
|
Provenance
The following attestation bundles were made for openfeature_provider_unleash-0.1.2-py3-none-any.whl:
Publisher:
release.yml on open-feature/python-sdk-contrib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openfeature_provider_unleash-0.1.2-py3-none-any.whl -
Subject digest:
5fc91ef907998e7518c6955b2d9a526c75d09cd14566dd12b5c79468bc061e55 - Sigstore transparency entry: 1109807565
- Sigstore integration time:
-
Permalink:
open-feature/python-sdk-contrib@2dea4112057e558e59ba4beee17e5fad716c35b9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/open-feature
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2dea4112057e558e59ba4beee17e5fad716c35b9 -
Trigger Event:
push
-
Statement type: