DocsTracking MethodsSDKsPythonOpenFeature Provider (Python)

OpenFeature Provider (Python)

Overview

The Mixpanel OpenFeature provider allows you to use Mixpanel Feature Flags through the standardized OpenFeature API. This provider wraps the Mixpanel Python SDK’s feature flags, letting you use the OpenFeature Python SDK with Mixpanel as the backend.

For the core Feature Flags SDK guide, see Feature Flags (Python).

Prerequisites

Installation

pip install mixpanel-openfeature-provider openfeature-sdk

Usage

The provider wraps either a local or remote flags provider from the Mixpanel SDK.

With Local Evaluation

from openfeature import api
from mixpanel_openfeature import MixpanelProvider
from mixpanel.flags.types import LocalFlagsConfig
 
config = LocalFlagsConfig(
    enable_polling=True,
    polling_interval_in_seconds=60
)
 
# Create provider with local evaluation (automatically starts polling)
provider = MixpanelProvider.from_local_config("YOUR_PROJECT_TOKEN", config)
api.set_provider(provider)
 
client = api.get_client()
show_new_ui = client.get_boolean_value("new-ui", False)

With Remote Evaluation

from mixpanel.flags.types import RemoteFlagsConfig
 
config = RemoteFlagsConfig(
    api_host="api.mixpanel.com"
)
 
provider = MixpanelProvider.from_remote_config("YOUR_PROJECT_TOKEN", config)
api.set_provider(provider)
 
client = api.get_client()
variant = client.get_string_value("checkout-flow", "control")

With an Existing Flags Provider

If you already have a configured Mixpanel instance, you can wrap its flags provider directly:

from mixpanel import Mixpanel
from mixpanel_openfeature import MixpanelProvider
 
mp = Mixpanel("YOUR_PROJECT_TOKEN", local_flags_config={
    "enable_polling": True,
    "polling_interval_in_seconds": 60
})
 
mp.local_flags.start_polling_for_definitions()
 
provider = MixpanelProvider(mp.local_flags)
api.set_provider(provider)

Supported Flag Types

OpenFeature MethodPython Type
get_boolean_value / get_boolean_detailsbool
get_string_value / get_string_detailsstr
get_integer_value / get_integer_detailsint
get_float_value / get_float_detailsfloat
get_object_value / get_object_detailsdict

Context and Identity

The evaluation context passed to each flag evaluation is forwarded to the Mixpanel flags provider.

  • targeting_key has no special meaning in this provider. It is treated as a regular context property.
  • Identity should be managed through the Mixpanel SDK (e.g., setting distinct_id in the context).

Error Handling

The provider returns the default value on all errors, with an error code indicating the cause:

Error CodeCondition
PROVIDER_NOT_READYThe provider has not been initialized
FLAG_NOT_FOUNDThe requested flag does not exist
TYPE_MISMATCHThe flag value does not match the requested type

Use get_details() methods instead of get_value() to inspect error codes:

details = client.get_boolean_details("my-flag", False)
if details.error_code:
    print(f"Flag error: {details.error_code} - {details.error_message}")

Lifecycle

  • shutdown() delegates to the underlying flags provider to clean up resources (e.g., stop polling).
  • The reason code for successful evaluations is STATIC.

Was this page useful?