OpenFeature Provider for Python SDK
Integrate your Python applications with Harness FME using the Python OpenFeature ProviderAn OpenFeature Provider wraps the Harness FME SDK, acting as a bridge between the OpenFeature SDK and the FME SDK. It translates OpenFeature function calls into operations handled by the FME SDK, which communicates with Harness services to evaluate flags and retrieve configuration updates., a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME Python SDK.
This page walks you through installing, configuring, and using the Python OpenFeature provider to evaluate feature flagsA feature flag is a conditional toggle in Harness FME that enables or disables specific functionality without deploying new code. It allows for controlled feature rollouts, A/B testing, and quick rollbacks if issues arise. in your Python applications.
Prerequisites
Before you begin, ensure you have the following:
- A valid Harness FME SDK key for your project
- Python 3.9 or later
- Access to
pipto install dependencies
Version compatibility
| Component | Minimum Version |
|---|---|
| Python | 3.9 + |
@splitsoftware/split-openfeature-provider | ≥ 1.0.0 |
| OpenFeature Python SDK | ≥ 0.8.1 |
Install the provider and dependencies
Install the Harness FME OpenFeature provider using pip:
pip install split-openfeature-provider==1.0.0
Configure the provider
You can register the provider with OpenFeature in one of several ways, depending on your setup.
- SDK API Key
- Split Client
This example demonstrates how to use the SplitProvider:
from openfeature import api
from split_openfeature_provider import SplitProvider
config = {
'impressionsMode': 'OPTIMIZED',
'impressionsRefreshRate': 30,
}
provider = SplitProvider({"SdkKey": "<YOUR_SDK_API_KEY>", "ConfigOptions": config, "ReadyBlockTime": 5})
api.set_provider(provider)
If you want access to additional initialization options, you can provide a Split client to the constructor:
from openfeature import api
from split_openfeature_provider import SplitProvider
from splitio import get_factory
config = {
'impressionsMode': 'OPTIMIZED',
'impressionsRefreshRate': 30,
}
factory = get_factory("<YOUR_SDK_API_KEY>", config=config)
factory.block_until_ready(5)
api.set_provider(SplitProvider({"SplitClient": factory.client()}))
Construct an evaluation context
Provide an evaluation contextThe Evaluation Context holds contextual information used during flag evaluation. It can include static data (like application or host identifiers) and dynamic data (such as a client IP address), which can be passed explicitly or propagated automatically. Static and dynamic values can be merged for richer, more targeted evaluations. with a targeting keyA unique identifier used to target specific users or entities when evaluating feature flags. It helps determine which variation of a flag should be served based on predefined rules and conditions. to evaluate flags. The evaluation context passes targeting information such as user IDs, email addresses, or plan types for flag targeting.
For example:
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
client = api.get_client("CLIENT_NAME")
context = EvaluationContext(targeting_key="TARGETING_KEY")
value = client.get_boolean_value("FLAG_NAME", False, context)
If the same targeting key is reused across evaluations, set the context at the client level:
context = EvaluationContext(targeting_key="TARGETING_KEY")
client.context = context
Or at the API level:
context = EvaluationContext(targeting_key="TARGETING_KEY")
api.set_evaluation_context(context)
Once the context is set at the client or API level, you don't need to provide it for each evaluation.
Asyncio mode
The Harness FME OpenFeature provider also supports asyncio mode.
For example:
from openfeature import api
from split_openfeature_provider import SplitProviderAsync
config = {
'impressionsMode': 'OPTIMIZED',
'impressionsRefreshRate': 30,
}
provider = SplitProvider({"SdkKey": "<YOUR_SDK_API_KEY>", "ConfigOptions": config, "ReadyBlockTime": 5})
await provider.create()
api.set_provider(provider)
To create a Split client externally for asyncio:
from openfeature import api
from split_openfeature_provider import SplitProviderAsync
from splitio import get_factory_async
config = {
'impressionsMode': 'OPTIMIZED',
'impressionsRefreshRate': 30,
}
factory = get_factory_async("<YOUR_SDK_API_KEY>", config=config)
await factory.block_until_ready(5)
provider = SplitProviderAsync({"SplitClient": factory.client()})
await provider.create()
api.set_provider(provider)
For asyncio flag evaluation:
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
client = api.get_client("CLIENT_NAME")
context = EvaluationContext(targeting_key="TARGETING_KEY")
value = await client.get_boolean_value_async("FLAG_NAME", False, context)
Logging
The Harness FME OpenFeature provider uses Python's logging library.
For example, this code sample sets all libraries using logging (including the provider itself) to use DEBUG mode:
import logging
logging.basicConfig(level=logging.DEBUG)
Shutting down the Split SDK factory
Before terminating the OpenFeature object, ensure the internal Split client shuts down properly.
For example:
from threading import Event
destroy_event = Event()
provider._split_client_wrapper._factory.destroy(destroy_event)
destroy_event.wait()
For asyncio mode:
await provider._split_client_wrapper._factory.destroy()
For more information, go to the Harness FME Python OpenFeature Provider GitHub repository.