Overview
This guide covers using Mixpanel’s Feature Flags through the OpenFeature standard with the Mixpanel Python OpenFeature provider. OpenFeature provides a vendor-agnostic API for feature flag evaluation, allowing you to switch between providers without changing your application code.
For the native Mixpanel SDK approach, see the Feature Flags (Python) guide.
Prerequisites
- Enterprise subscription plan with Feature Flags enabled
- Python 3.9 or higher
- Project Token from your Mixpanel Project Settings
Installation
Quick Start
Initialization
The provider supports three initialization methods depending on your evaluation strategy.
Local Evaluation (Recommended)
Evaluates flags locally using cached flag definitions polled from Mixpanel. This minimizes latency since there is no network call at evaluation time.
Targeting by Mixpanel cohorts and sticky variants are not supported in Local Evaluation mode.
Remote Evaluation
Evaluates flags by making a request to Mixpanel’s servers for each evaluation. Use this when you need real-time flag values or cohort-based targeting.
Using an Existing Mixpanel Instance
If your application already has a Mixpanel instance configured for tracking, you can wrap its flags provider:
Usage
Flag Types and Evaluation Methods
| Mixpanel Flag Type | Variant Values | OpenFeature Method |
|---|
| Feature Gate | True / False | get_boolean_value() |
| Experiment | boolean, string, number, or JSON object | get_boolean_value(), get_string_value(), get_integer_value(), get_float_value(), or get_object_value() |
| Dynamic Config | JSON object | get_object_value() |
Evaluation Context
Pass context to provide user attributes for targeting:
Unlike some providers, targetingKey is not used as a special bucketing key. It is passed as another context property. Mixpanel’s server-side configuration determines which properties are used for targeting and bucketing.
Full Resolution Details
Accessing the Underlying Mixpanel Instance
When using from_local_config or from_remote_config, you can access the Mixpanel instance for tracking:
Shutdown
Error Handling
The provider uses OpenFeature’s standard error codes:
| Error Code | When |
|---|
PROVIDER_NOT_READY | Flags evaluated before local provider has finished loading definitions |
FLAG_NOT_FOUND | The requested flag does not exist in Mixpanel |
TYPE_MISMATCH | The flag value type does not match the requested type |
Troubleshooting
Flags Always Return Default Values
- Provider not ready (local evaluation): Flag definitions are polled asynchronously. Allow time for the initial fetch to complete.
- Invalid project token: Verify the token matches your Mixpanel project.
- Flag not configured: Verify the flag exists and is enabled in your Mixpanel project.
Type Mismatch Errors
- Verify the flag’s value type in Mixpanel matches your evaluation method (e.g., string
"true" requires get_string_value(), not get_boolean_value()).
- Use
get_object_value() for JSON objects.
- Integer evaluation accepts whole-number
float values. Float evaluation accepts any numeric type.