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 confidence-openfeature-provider==0.1.3
requirements.txt
confidence-openfeature-provider==0.1.3
pip install 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.provider import Region
from confidence.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 confidence_openfeature_provider-0.1.3.tar.gz
.
File metadata
- Download URL: confidence_openfeature_provider-0.1.3.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9399ae01a6497eb1f8c0f9809faad0dc747866dae19f172481e4d9ca25e0336 |
|
MD5 | 3df10e2594b942581a7ca59063530341 |
|
BLAKE2b-256 | 3175a6319c2801579c4727904835cdf8cf431087c5dda402ef0d4ee93ab170c8 |
File details
Details for the file confidence_openfeature_provider-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: confidence_openfeature_provider-0.1.3-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43017eda45756951b99bc5a362e0ae636127b2bcec047a047c7bb885252c04b5 |
|
MD5 | d230fd043e466df87c5a00655b655d11 |
|
BLAKE2b-256 | 7fcce73fb9be4b0e8f8ce7fd60290681295185c359bbdb804dc9f528a73c131d |