{"id":4147,"library":"openfeature-sdk","title":"OpenFeature Python SDK","description":"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.","status":"active","version":"0.8.4","language":"en","source_language":"en","source_url":"https://github.com/open-feature/python-sdk","tags":["feature flags","feature management","openfeature","sdk","feature toggles"],"install":[{"cmd":"pip install openfeature-sdk","lang":"bash","label":"Install core SDK"},{"cmd":"pip install openfeature-provider-flagd","lang":"bash","label":"Example: Install a provider (e.g., Flagd)"}],"dependencies":[{"reason":"Python 3.9 or later is required since v0.8.0.","package":"python","optional":false}],"imports":[{"symbol":"api","correct":"from openfeature import api"},{"note":"Required for a basic, self-contained example without external providers.","symbol":"InMemoryProvider","correct":"from openfeature.provider.in_memory_provider import InMemoryProvider"},{"note":"EvaluationContext is a top-level import from the openfeature package itself.","wrong":"from openfeature.api import EvaluationContext","symbol":"EvaluationContext","correct":"from openfeature import EvaluationContext"}],"quickstart":{"code":"from openfeature import api, EvaluationContext\nfrom openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider\nimport os\n\n# Configure a simple in-memory provider for demonstration\n# In a real application, you would typically use an external provider (e.g., Flagd, LaunchDarkly)\nmy_flags = {\n    \"new-feature-enabled\": InMemoryFlag(\"on\", {\"on\": True, \"off\": False}),\n    \"welcome-message\": InMemoryFlag(\"greeting\", {\"greeting\": \"Hello, OpenFeature!\", \"default\": \"Welcome!\"})\n}\napi.set_provider(InMemoryProvider(my_flags))\n\n# Create a client, optionally with a domain\nclient = api.get_client()\n\n# Define an evaluation context for targeting\nuser_id = os.environ.get('USER_ID', 'default_user')\neval_context = EvaluationContext(targeting_key=user_id, attributes={\"region\": \"us-east-1\"})\n\n# Evaluate a boolean flag\nis_new_feature_enabled = client.get_boolean_value(\"new-feature-enabled\", False, eval_context)\nif is_new_feature_enabled:\n    print(f\"New feature is enabled for user {user_id}!\")\nelse:\n    print(f\"New feature is disabled for user {user_id}.\")\n\n# Evaluate a string flag\nmessage = client.get_string_value(\"welcome-message\", \"Fallback Message\", eval_context)\nprint(f\"Retrieved message: {message}\")\n\n# It's good practice to shut down providers gracefully\napi.shutdown()","lang":"python","description":"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`)."},"warnings":[{"fix":"Upgrade Python environment to 3.9 or higher. For example, use `python -m venv .venv` with Python 3.9+.","message":"Python 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.","severity":"breaking","affected_versions":">=0.8.0"},{"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`.","message":"The signature of the `finally_after` hook stage changed in v0.7.5. It now requires `evaluation_details` as the second argument.","severity":"breaking","affected_versions":">=0.7.5"},{"fix":"Install a specific provider package (e.g., `pip install openfeature-provider-flagd`) and then configure it using `api.set_provider(YourProvider())`.","message":"The 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.","severity":"gotcha","affected_versions":"all"},{"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.","message":"If 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.","severity":"gotcha","affected_versions":"all"},{"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')`.","message":"When 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}