Confidence provider for the OpenFeature SDK
Project description
Confidence OpenFeature Python Provider
This repo contains the OpenFeature Python flag provider for Confidence.
OpenFeature
Before starting to use the provider, it can be helpful to read through the general OpenFeature docs and get familiar with the concepts.
Adding the dependency
pip install
pip install spotify-confidence-sdk==0.2.1
#### requirements.txt
```python
spotify-confidence-sdk==0.2.1
pip install -r requirements.txt
Creating and using the flag provider
Below is an example for how to create a OpenFeature client using the Confidence flag provider, and then resolve a flag with a boolean attribute. The provider is configured with an api key and a region, which will determine where it will send the resolving requests.
The flag will be applied immediately, meaning that Confidence will count the targeted user as having received the treatment.
You can retrieve attributes on the flag variant using property dot notation, meaning test-flag.boolean-key
will retrieve
the attribute boolean-key
on the flag test-flag
.
You can also use only the flag name test-flag
and retrieve all values as a map with resolve_object_details()
.
The flag's schema is validated against the requested data type, and if it doesn't match it will fall back to the default value.
from confidence.confidence import Region
from confidence.openfeature_provider import ConfidenceOpenFeatureProvider
from openfeature.api import EvaluationContext
from openfeature import api
provider = ConfidenceOpenFeatureProvider("client_secret", Region.EU)
api.set_provider(provider)
open_feature_client = api.get_client()
ctx = EvaluationContext(targeting_key="random", attributes={
"user": {
"country": "SE"
}
})
flag_value = open_feature_client.get_boolean_value(flag_key="test-flag.boolean-key", default_value=False,
evaluation_context=ctx)
print(flag_value)
Project details
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
File details
Details for the file spotify_confidence_sdk-0.2.1.tar.gz
.
File metadata
- Download URL: spotify_confidence_sdk-0.2.1.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01ad8fd48d68050c7a242dde6bfe306d40cfe810159d5c9ae57ac18744725e8a |
|
MD5 | 62340ba47d50cc3c462966525d0007ab |
|
BLAKE2b-256 | 5418b90be50fb76ee24b33f4fe4b3e1041af14bfb0316cde9c57f7a4d38beffc |
File details
Details for the file spotify_confidence_sdk-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: spotify_confidence_sdk-0.2.1-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0739b893ec4d5457414a17b4f94dac110eec918f2fc45558a32565a37a2a704b |
|
MD5 | c43b1e927bf9f01ba025fb4f38dd6d7e |
|
BLAKE2b-256 | ee7527eb305a3c1740e36d50e5fa03a79f1e13812add4f229cc8eef587a92735 |