@@ -8,6 +8,12 @@ This provider is designed to use [Unleash](https://www.getunleash.io/).
88pip install openfeature-provider-unleash
99```
1010
11+ ### Requirements
12+
13+ - Python 3.9+
14+ - ` openfeature-sdk>=0.8.2 `
15+ - ` UnleashClient>=6.3.0 `
16+
1117## Configuration and Usage
1218
1319Instantiate a new UnleashProvider instance and configure the OpenFeature SDK to use it:
@@ -20,7 +26,8 @@ from openfeature.contrib.provider.unleash import UnleashProvider
2026provider = UnleashProvider(
2127 url = " https://my-unleash-instance.com" ,
2228 app_name = " my-python-app" ,
23- api_token = " my-api-token"
29+ api_token = " my-api-token" ,
30+ environment = " development" , # optional, defaults to "development"
2431)
2532
2633# Initialize the provider (required before use)
@@ -34,6 +41,14 @@ api.set_provider(provider)
3441- ` url ` : The URL of your Unleash server
3542- ` app_name ` : The name of your application
3643- ` api_token ` : The API token for authentication
44+ - ` environment ` : The Unleash environment to connect to (default: ` development ` )
45+
46+ ### Evaluation context mapping
47+
48+ When evaluating flags, the OpenFeature ` EvaluationContext ` is mapped to the Unleash context as follows:
49+
50+ - ` EvaluationContext.targeting_key ` → Unleash ` userId `
51+ - ` EvaluationContext.attributes ` → merged into the Unleash context as-is
3752
3853### Event handling
3954
@@ -66,7 +81,8 @@ provider.remove_handler(ProviderEvent.PROVIDER_READY, on_provider_ready)
6681- ` ProviderEvent.PROVIDER_READY ` : Emitted when the provider is ready to evaluate flags
6782- ` ProviderEvent.PROVIDER_ERROR ` : Emitted when the provider encounters an error
6883- ` ProviderEvent.PROVIDER_CONFIGURATION_CHANGED ` : Emitted when flag configurations are updated
69- - ` ProviderEvent.PROVIDER_STALE ` : Emitted when the provider's cached state is no longer valid
84+
85+ Note: ` ProviderEvent.PROVIDER_STALE ` handlers can be registered but are not currently emitted by this provider.
7086
7187### Tracking support
7288
@@ -103,6 +119,16 @@ provider.track("conversion", context, event_details)
103119- ** Event Details** : Add numeric values and custom fields for analytics
104120- ** Unleash Integration** : Uses UnleashClient's impression event infrastructure
105121
122+ ### Supported flag types
123+
124+ This provider supports resolving the following types via the OpenFeature client:
125+
126+ - Boolean (` get_boolean_value ` /` details ` ): uses ` UnleashClient.is_enabled `
127+ - String (` get_string_value ` /` details ` ): from variant payload
128+ - Integer (` get_integer_value ` /` details ` ): from variant payload
129+ - Float (` get_float_value ` /` details ` ): from variant payload
130+ - Object (` get_object_value ` /` details ` ): from variant payload, JSON-parsed if needed
131+
106132### Example usage
107133
108134``` python
@@ -152,12 +178,32 @@ provider.shutdown()
152178uv run test --frozen
153179```
154180
181+ Integration tests require Docker to be installed and running. To run only integration tests:
182+
183+ ``` bash
184+ uv run test -m integration --frozen
185+ ```
186+
187+ To skip integration tests:
188+
189+ ``` bash
190+ uv run test -m " not integration" --frozen
191+ ```
192+
155193### Type checking
156194
157195``` bash
158196uv run mypy-check
159197```
160198
199+ ### Linting
200+
201+ Run Ruff checks:
202+
203+ ``` bash
204+ uv run ruff check
205+ ```
206+
161207## License
162208
163209Apache 2.0 - See [ LICENSE] ( ./LICENSE ) for more information.
0 commit comments