Implementation:DataExpert io Data engineer handbook Statsig Get experiment
Appearance
Overview
Statsig Get Experiment is a Wrapper Doc implementation that documents the use of the external Statsig Python SDK to assign users to experiment variants and retrieve variant-specific parameters. This is the concrete realization of the Principle:DataExpert_io_Data_engineer_handbook_Experiment_User_Assignment principle.
Type
Wrapper Doc (external Statsig SDK)
Source
server.py:L50-76
Signature
statsig.get_experiment(user: StatsigUser, experiment_name: str) -> DynamicConfig
Then, to retrieve individual parameters from the returned config:
DynamicConfig.get(param_name: str, default: str) -> str
User Creation
Users are identified by creating a StatsigUser object. The application supports two identity strategies:
# Default: hash the client IP address for a pseudo-anonymous but deterministic ID
StatsigUser(str(hash(request.remote_addr)))
# Alternative: random ID via ?random query parameter for full anonymity
StatsigUser(random_id)
- IP hashing (default): Uses
str(hash(request.remote_addr))to create a deterministic user ID from the client's IP address. The same IP always produces the same hash, ensuring consistent variant assignment across visits. - Random ID (via
?randomquery parameter): Generates a random identifier, useful for testing or when IP-based bucketing is not desired.
Experiment Configuration
- Experiment name:
"button_color_v3" - Retrieved parameters:
| Parameter Name | Default Value | Description |
|---|---|---|
"Button Color" |
"blue" |
The color of the call-to-action button displayed to the user |
"Paragraph Text" |
"Data Engineering Boot Camp" |
The headline or paragraph text shown on the page |
Imports
from statsig import statsig
from statsig.statsig_user import StatsigUser
Inputs and Outputs
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | user | StatsigUser | A user object constructed from either a hashed IP address or a random ID |
| Input | experiment_name | str | The name of the experiment to evaluate (e.g., "button_color_v3")
|
| Output | DynamicConfig | DynamicConfig | A configuration object containing the variant parameters assigned to this user. Individual values are retrieved via .get(param_name, default).
|
Behavior
- The SDK evaluates the user against the experiment's bucketing rules to determine which variant the user belongs to
- The returned
DynamicConfigcontains all parameter values for the assigned variant - If the experiment does not exist or the user is not eligible, the default values are returned
- Assignment is deterministic — the same
StatsigUserID always receives the same variant
External Reference
Related Pages
- Principle:DataExpert_io_Data_engineer_handbook_Experiment_User_Assignment
- Environment:DataExpert_io_Data_engineer_handbook_Statsig_API_Environment
Metadata
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment