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-sdkVerified import paths — ran on the pinned version, not inferred.
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`).
Upgrade Python environment to 3.9 or higher. For example, use `python -m venv .venv` with Python 3.9+.
Update any custom hooks implementing `finally_after` to accept `evaluation_details` as the second argument: `finally_after(flag_details: FlagResolutionDetails, evaluation_details: dict) -> None`.
Install a specific provider package (e.g., `pip install openfeature-provider-flagd`) and then configure it using `api.set_provider(YourProvider())`.
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.
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')`.
Register a feature flag provider (e.g., `InMemoryProvider` or a specific vendor provider) using `api.set_provider(MyProvider())` before evaluating flags.
Change the import statement to `from openfeature import api` to access the global API object.
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.
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.