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 mixpanel import Mixpanel
from openfeature import api
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()
 
# Register the provider
api.set_provider(MixpanelProvider(mp.local_flags))
 
client = api.get_client()
show_new_ui = client.get_boolean_value("new-ui", False)

With Remote Evaluation

mp = Mixpanel("YOUR_PROJECT_TOKEN", remote_flags_config={
    "api_host": "api.mixpanel.com"
})
 
api.set_provider(MixpanelProvider(mp.remote_flags))
 
client = api.get_client()
variant = client.get_string_value("checkout-flow", "control")

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

Context is set globally when registering the provider, not per-evaluation. Per-evaluation context passed to individual flag evaluations is ignored.

  • 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() is a no-op. The Mixpanel SDK manages its own lifecycle.
  • The reason code for successful evaluations is STATIC.

Was this page useful?