Skip to content

Commit eed4273

Browse files
efahkKwame Efah
andauthored
Update python SDK docs for feature flagging (#2207)
* Update python SDK docs for feature flagging * typo --------- Co-authored-by: Kwame Efah <kwameefah@h7d9gc72q4-kwameefah.corp.mixpanel.com>
1 parent 3526130 commit eed4273

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

pages/docs/tracking-methods/sdks/python/python-flags.mdx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { Callout } from 'nextra/components'
22

33
# Implement Feature Flags (Python)
44

5-
<Callout type="info">
6-
The Python server-side SDK is currently in Beta.
7-
</Callout>
8-
95
## Overview
106

117
This developer guide will assist you in configuring your server-side Python platform for [Feature Flags](/docs/featureflags) using the [Mixpanel Python SDK](/docs/tracking-methods/sdks/python). Feature Flags allow you to control the rollout of your features, conduct A/B testing, and manage application behavior without deploying new code.
@@ -14,17 +10,19 @@ This developer guide will assist you in configuring your server-side Python plat
1410

1511
Before implementing [Feature Flags](/docs/featureflags), ensure:
1612

17-
- You are on an Enterprise subscription plan and have the appropriate version of the SDK installed (minimum supported version is [`v5.0.0b2`](https://github.com/mixpanel/mixpanel-python). If not, please follow [this doc](/docs/quickstart/install-mixpanel) to install the SDK.
13+
- You are on an Enterprise subscription plan and have the appropriate version of the SDK installed (minimum supported version is [`v5.0.0`](https://github.com/mixpanel/mixpanel-python). If not, please follow [this doc](/docs/quickstart/install-mixpanel) to install the SDK.
1814
- You have your Project Token from your [Mixpanel Project Settings](/docs/orgs-and-projects/managing-projects#find-your-project-tokens)
1915

20-
## Flag Evaluation Modes
16+
## Flag Evaluation Scenarios
2117

22-
There are two modes available for using the python SDK for feature flagging, Local Evaluation and Remote Evaluation.
18+
There are two scenarios available for using the python SDK for feature flagging, Local Evaluation and Remote Evaluation.
2319

2420
For local evaluation, the SDK will poll Mixpanel servers for feature flag configurations. Assignment of user contexts to variants will be done locally within the SDK. This mode is recommended for low latency since there is no network call made at assignment time.
2521

2622
For remote evaluation, the SDK will make a network call to Mixpanel servers at assignment time. This mode is recommended for use cases where you want to leverage Mixpanel cohorts for user targeting or sticky variants for persistent variant assignments.
2723

24+
In either case there is also the capability to evaluate all flags for a given user context at once, to avoid needing to make multiple calls to get individual flag variants for the same user. This is particularly useful for remote evaluation to avoid incurring additional network calls.
25+
2826
## Local Evaluation
2927

3028
<Callout type="warning">
@@ -66,6 +64,8 @@ user_context = {
6664
}
6765
}
6866

67+
# Gets the assigned variant for the flag for the given user context.
68+
# This will return the fallback_variant if the user context is not in an assignment group for the flag.
6969
variant_value = mixpanel.local_flags.get_variant_value(flag_key, fallback_variant, user_context)
7070
```
7171

@@ -76,15 +76,31 @@ variant_value = mixpanel.local_flags.get_variant_value(flag_key, fallback_varian
7676
```python
7777
remote_config = mixpanel.RemoteFlagsConfig(api_host=API_HOST, request_timeout_in_seconds=5)
7878

79-
mixpanel = mixpanel.Mixpanel(PROJECT_TOKEN, remote_flags_config=remote_config) as mp:
79+
mixpanel = mixpanel.Mixpanel(PROJECT_TOKEN, remote_flags_config=remote_config)
8080

8181
# get_variant_value usage is the same as for local evaluation, but will make a network call to Mixpanel servers at assignment time.
82-
variant_value = mp.remote_flags.get_variant_value(flag_key, fallback_variant, user_context)
83-
print(f"Variant value: {variant_value}")
84-
82+
variant_value = mixpanel.remote_flags.get_variant_value(flag_key, fallback_variant, user_context)
8583
```
8684

85+
## Evaluate all flags at once
86+
87+
Below is a remote evaluation sample of evaluating all flags for a given user context at once.
88+
89+
```python
90+
user_context = {
91+
"distinct_id": "1234",
92+
}
93+
94+
remote_config = mixpanel.RemoteFlagsConfig(api_host=API_HOST, request_timeout_in_seconds=5)
95+
mixpanel = mixpanel.Mixpanel(PROJECT_TOKEN, remote_flags_config=remote_config)
96+
97+
# Returns a dictionary, mapping flag keys to assigned variants ONLY for flags that the user context is in an assignment group for.
98+
# By default, this will not track an exposure event.
99+
variants = mixpanel.remote_flags.get_all_variants(user_context)
87100

101+
# Given a flag key and the selected variant for that key, manually track an exposure event for a given flag and assigned variant, after exposing the user to the variant
102+
mixpanel.remote_flags.track_exposure_event(flagKey, selected_variant, user_context)
103+
```
88104

89105

90106

0 commit comments

Comments
 (0)