@@ -37,14 +37,14 @@ Targeting by Mixpanel cohorts and sticky variants are not supported in Local Eva
3737- The SDK will continue to poll for the lifetime of the SDK instance or until stopped.
3838
3939``` python
40- from mixpanel import Mixpanel
40+ import mixpanel
4141
4242local_config = mixpanel.LocalFlagsConfig(api_host = " https://api.mixpanel.com" , enable_polling = True , poll_interval = 60 )
4343
44- mixpanel = Mixpanel(" YOUR_PROJECT_TOKEN" , local_flags_config = local_config)
44+ mp = mixpanel. Mixpanel(" YOUR_PROJECT_TOKEN" , local_flags_config = local_config)
4545
4646# If enable_polling is set to false, this will fetch definitions only once for the lifetime of the SDK.
47- mixpanel .local_flags.start_polling_for_definitions()
47+ mp .local_flags.start_polling_for_definitions()
4848
4949# This should be the 'key' of the feature flag from Mixpanel's UX.
5050flag_key = " sample-flag"
@@ -66,40 +66,46 @@ user_context = {
6666
6767# Gets the assigned variant for the flag for the given user context.
6868# This will return the fallback_variant if the user context is not in an assignment group for the flag.
69- variant_value = mixpanel .local_flags.get_variant_value(flag_key, fallback_variant, user_context)
69+ variant_value = mp .local_flags.get_variant_value(flag_key, fallback_variant, user_context)
7070```
7171
7272## Remote Evaluation
7373
7474- The SDK is configured with a ` RemoteFlagsConfig ` object to use remote evaluation.
7575
76+ ### Get a specific variant
77+
7678``` python
79+ import mixpanel
80+
7781remote_config = mixpanel.RemoteFlagsConfig(api_host = API_HOST , request_timeout_in_seconds = 5 )
7882
79- mixpanel = mixpanel.Mixpanel(PROJECT_TOKEN , remote_flags_config = remote_config)
83+ mp = mixpanel.Mixpanel(PROJECT_TOKEN , remote_flags_config = remote_config)
8084
8185# 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 = mixpanel .remote_flags.get_variant_value(flag_key, fallback_variant, user_context)
86+ variant_value = mp .remote_flags.get_variant_value(flag_key, fallback_variant, user_context)
8387```
8488
85- ## Evaluate all flags at once
89+ ### Evaluate all flags at once
8690
8791Below is a remote evaluation sample of evaluating all flags for a given user context at once.
8892
8993``` python
94+ import mixpanel
95+
9096user_context = {
9197 " distinct_id" : " 1234" ,
9298}
9399
94100remote_config = mixpanel.RemoteFlagsConfig(api_host = API_HOST , request_timeout_in_seconds = 5 )
95- mixpanel = mixpanel.Mixpanel(PROJECT_TOKEN , remote_flags_config = remote_config)
101+ mp = mixpanel.Mixpanel(PROJECT_TOKEN , remote_flags_config = remote_config)
96102
97103# Returns a dictionary, mapping flag keys to assigned variants ONLY for flags that the user context is in an assignment group for.
98104# By default, this will not track an exposure event.
99- variants = mixpanel .remote_flags.get_all_variants(user_context)
105+ variants = mp .remote_flags.get_all_variants(user_context)
100106
101107# 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)
108+ mp .remote_flags.track_exposure_event(flagKey, selected_variant, user_context)
103109```
104110
105111
0 commit comments