@@ -8,6 +8,12 @@ This provider is designed to use [Unleash](https://www.getunleash.io/).
8
8
pip install openfeature-provider-unleash
9
9
```
10
10
11
+ ### Requirements
12
+
13
+ - Python 3.9+
14
+ - ` openfeature-sdk>=0.8.2 `
15
+ - ` UnleashClient>=6.3.0 `
16
+
11
17
## Configuration and Usage
12
18
13
19
Instantiate a new UnleashProvider instance and configure the OpenFeature SDK to use it:
@@ -20,7 +26,8 @@ from openfeature.contrib.provider.unleash import UnleashProvider
20
26
provider = UnleashProvider(
21
27
url = " https://my-unleash-instance.com" ,
22
28
app_name = " my-python-app" ,
23
- api_token = " my-api-token"
29
+ api_token = " my-api-token" ,
30
+ environment = " development" , # optional, defaults to "development"
24
31
)
25
32
26
33
# Initialize the provider (required before use)
@@ -34,6 +41,14 @@ api.set_provider(provider)
34
41
- ` url ` : The URL of your Unleash server
35
42
- ` app_name ` : The name of your application
36
43
- ` 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
37
52
38
53
### Event handling
39
54
@@ -66,7 +81,8 @@ provider.remove_handler(ProviderEvent.PROVIDER_READY, on_provider_ready)
66
81
- ` ProviderEvent.PROVIDER_READY ` : Emitted when the provider is ready to evaluate flags
67
82
- ` ProviderEvent.PROVIDER_ERROR ` : Emitted when the provider encounters an error
68
83
- ` 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.
70
86
71
87
### Tracking support
72
88
@@ -103,6 +119,16 @@ provider.track("conversion", context, event_details)
103
119
- ** Event Details** : Add numeric values and custom fields for analytics
104
120
- ** Unleash Integration** : Uses UnleashClient's impression event infrastructure
105
121
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
+
106
132
### Example usage
107
133
108
134
``` python
@@ -152,12 +178,32 @@ provider.shutdown()
152
178
uv run test --frozen
153
179
```
154
180
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
+
155
193
### Type checking
156
194
157
195
``` bash
158
196
uv run mypy-check
159
197
```
160
198
199
+ ### Linting
200
+
201
+ Run Ruff checks:
202
+
203
+ ``` bash
204
+ uv run ruff check
205
+ ```
206
+
161
207
## License
162
208
163
209
Apache 2.0 - See [ LICENSE] ( ./LICENSE ) for more information.
0 commit comments