Registry / devops / openfeature-sdk

openfeature-sdk

JSON →
library0.10.0pypypi✓ verified 23d ago

The OpenFeature Python SDK is a vendor-agnostic abstraction library for evaluating feature flags in Python applications. It supports multiple data types for flags (booleans, strings, numbers, objects), integrates with various backend providers, and offers hooks to extend the flag evaluation lifecycle. The current version is 0.8.4, with active development and regular minor releases.

pip install openfeature-sdk
INSTALL
IMPORT
SIG · OPENFEATURE-SDK
O
openfeature-sdk
devopspythonv0.10.0
Install
2.7s avg
Import
117ms
Disk
43MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 3.15s
py 3.11
✓ —
✓ 2.8s
py 3.12
✓ —
✓ 2.35s
py 3.13
✓ —
✓ 2.45s
py 3.9
1/2 runs
1/2 runs
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

api
from openfeature import api
InMemoryProvider
from openfeature.provider.in_memory_provider import InMemoryProvider
Required for a basic, self-contained example without external providers.
EvaluationContext
from openfeature import EvaluationContext
from openfeature.api import EvaluationContext
EvaluationContext is a top-level import from the openfeature package itself.

This quickstart demonstrates how to initialize the OpenFeature SDK with a basic in-memory provider, create a client, and evaluate a boolean and a string feature flag. It also shows how to provide an evaluation context for flag targeting. In a production environment, you would replace `InMemoryProvider` with a specific feature flag management system's provider (e.g., `FlagdProvider`, `LaunchDarklyProvider`).

from openfeature import api, EvaluationContext from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider import os # Configure a simple in-memory provider for demonstration # In a real application, you would typically use an external provider (e.g., Flagd, LaunchDarkly) my_flags = { "new-feature-enabled": InMemoryFlag("on", {"on": True, "off": False}), "welcome-message": InMemoryFlag("greeting", {"greeting": "Hello, OpenFeature!", "default": "Welcome!"}) } api.set_provider(InMemoryProvider(my_flags)) # Create a client, optionally with a domain client = api.get_client() # Define an evaluation context for targeting user_id = os.environ.get('USER_ID', 'default_user') eval_context = EvaluationContext(targeting_key=user_id, attributes={"region": "us-east-1"}) # Evaluate a boolean flag is_new_feature_enabled = client.get_boolean_value("new-feature-enabled", False, eval_context) if is_new_feature_enabled: print(f"New feature is enabled for user {user_id}!") else: print(f"New feature is disabled for user {user_id}.") # Evaluate a string flag message = client.get_string_value("welcome-message", "Fallback Message", eval_context) print(f"Retrieved message: {message}") # It's good practice to shut down providers gracefully api.shutdown()
Debug
Known issues
breakingPython 3.8 support was dropped in OpenFeature Python SDK v0.8.0. Applications must be running Python 3.9 or newer to upgrade to v0.8.0 and beyond.
fix
Upgrade Python environment to 3.9 or higher. For example, use `python -m venv .venv` with Python 3.9+.
affects: >=0.8.0
breakingThe signature of the `finally_after` hook stage changed in v0.7.5. It now requires `evaluation_details` as the second argument.
fix
Update any custom hooks implementing `finally_after` to accept `evaluation_details` as the second argument: `finally_after(flag_details: FlagResolutionDetails, evaluation_details: dict) -> None`.
affects: >=0.7.5
gotchaThe core `openfeature-sdk` package does not include any flag providers by default. A provider, which connects to a feature flag management system (like Flagd, LaunchDarkly, Split.io), must be installed and configured separately.
fix
Install a specific provider package (e.g., `pip install openfeature-provider-flagd`) and then configure it using `api.set_provider(YourProvider())`.
affects: all
gotchaIf no provider is explicitly set, OpenFeature will default to a 'No-Op' provider. This provider always returns the default value provided in the flag evaluation call, which can lead to unexpected behavior if you expect flags to be dynamic.
fix
Always ensure a provider is set via `api.set_provider()` early in your application's lifecycle, before attempting to evaluate flags, unless intentionally using the No-Op behavior.
affects: all
gotchaWhen providing an `EvaluationContext`, ensure a `targeting_key` is always included. Many providers rely on this for correct flag evaluation and targeting logic, and its absence can lead to incorrect or default flag values.
fix
Populate the `targeting_key` in the `EvaluationContext` with a unique identifier relevant to the user or entity being targeted, e.g., `EvaluationContext(targeting_key='user123')`.
affects: all
Errors
Common errors & fixes
openfeature-sdk flag always returns default value
No feature flag provider has been registered with the OpenFeature SDK, or the registered provider is in a NOT_READY state, causing the SDK to use the No-op provider which always returns the default value.
fix
Register a feature flag provider (e.g., `InMemoryProvider` or a specific vendor provider) using `api.set_provider(MyProvider())` before evaluating flags.
AttributeError: module 'openfeature' has no attribute 'set_provider'
The core OpenFeature API methods, such as `set_provider`, are exposed through the `api` object within the `openfeature` package, not directly on the `openfeature` module itself.
fix
Change the import statement to `from openfeature import api` to access the global API object.
openfeature.exception.ProviderError: Provider failed to initialize
The configured feature flag provider encountered an issue during its setup, such as network problems, invalid configuration, or an unavailable backend service.
fix
Check the provider's specific configuration parameters, ensure any external services it relies on are accessible and running, and review provider-specific logging for detailed error messages during initialization.
openfeature.exception.TypeMismatchError: Flag 'my-flag' has type STRING, expected BOOLEAN
The type of the flag value returned by the provider does not match the expected type specified in the flag evaluation method (e.g., calling `get_boolean_value` for a flag configured as a string).
fix
Verify the flag key exists and ensure the correct `get_TYPE_value` method (e.g., `get_boolean_value`, `get_string_value`, `get_number_value`) is used based on the flag's configured type.
Upgrade
Version history
0.10.0latest on PyPI · released Jun 1, 2026
Audit
Dependencies
pythonrequiredPython 3.9 or later is required since v0.8.0.
Agent activity
7 hits · last 30 days
node
6
Resources
openfeature-sdk — pip install openfeature-sdk · libregistry