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.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 aMixpanel instance configured for tracking, you can wrap its flags provider:
Usage
Flag Types and Evaluation Methods
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 usingfrom_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: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"requiresget_string_value(), notget_boolean_value()). - Use
get_object_value()for JSON objects. - Integer evaluation accepts whole-number
floatvalues. Float evaluation accepts any numeric type.