Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:DataExpert io Data engineer handbook Statsig API Environment

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Experimentation
Last Updated 2026-02-09 06:00 GMT

Overview

Python Flask environment with Statsig SDK for server-side A/B testing and experimentation.

Description

This environment provides a Python web server stack using Flask for HTTP endpoints and the Statsig SDK for server-side experiment management. It supports initializing A/B test experiments, assigning users to experiment variants, and logging events for analysis. The Statsig SDK requires a server-side API key that must be obtained from the Statsig console.

Usage

Use this environment for any A/B Experimentation workflow that requires server-side experiment assignment and event tracking. It is the mandatory prerequisite for running the Statsig_Initialize, Statsig_Get_experiment, and Statsig_Log_event implementations.

System Requirements

Category Requirement Notes
OS Linux, macOS, or Windows Any OS with Python support
Language Python 3.11+ As per bootcamp prerequisites
Network Internet access Required for Statsig API communication

Dependencies

Python Packages

  • `Flask` — Web framework for HTTP server
  • `requests` — HTTP client library
  • `statsig` — Statsig server-side SDK for A/B testing
  • `jsonify` — JSON response formatting (bundled with Flask)

Credentials

The following environment variable must be set:

  • `STATSIG_API_KEY`: Server-side API key from the Statsig console (required for SDK initialization)

WARNING: This must be a server-side secret key, not a client SDK key. Obtain it from the Statsig dashboard under Project Settings.

Quick Install

# Install Python dependencies
pip install Flask requests statsig

# Set the Statsig API key
export STATSIG_API_KEY="your-server-secret-key"

# Run the Flask server
python src/server.py

Code Evidence

SDK initialization from `server.py:8-9`:

API_KEY = os.environ.get('STATSIG_API_KEY')
statsig.initialize(API_KEY)

Experiment assignment from `server.py:50-76`:

user = StatsigUser(user_id=user_id)
experiment = statsig.get_experiment(user, experiment_name)
variant = experiment.get("experiment_group", "control")

Event tracking from `server.py:34-46`:

event = StatsigEvent(
    user=StatsigUser(user_id=user_id),
    event_name=event_name
)
statsig.log_event(event)

Common Errors

Error Message Cause Solution
`statsig.initialize()` returns None/error Invalid or missing API key Set `STATSIG_API_KEY` environment variable with a valid server-side key
`ModuleNotFoundError: No module named 'statsig'` Statsig SDK not installed Run `pip install statsig`
`ConnectionError` during initialize No internet access Statsig SDK requires network access to fetch experiment configurations

Compatibility Notes

  • API Key Type: Must use a server-side secret key, not a client SDK key. Client keys will not work with the Python SDK.
  • Network Dependency: The Statsig SDK makes HTTP calls during initialization and event logging. A stable internet connection is required.
  • Flask Development Server: The included `server.py` uses Flask's built-in development server, which is not suitable for production. Use a WSGI server (e.g., Gunicorn) for production deployments.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment