Registry / http-networking / statsig-python-core

statsig-python-core

JSON →
library0.22.0pypypi✓ verified 24d ago

The Statsig Python Core SDK (`statsig-python-core`) provides server-side Python bindings for integrating Statsig's feature flagging, A/B testing, and experimentation platform into your applications. It enables evaluating feature gates, dynamic configs, and experiments, and logging exposures without requiring a client-side Statsig SDK. It's currently at version 0.18.1 and receives regular updates, typically aligning with feature releases.

pip install statsig-python-core
INSTALL
IMPORT
SIG · STATSIG-PYTHON-COR
S
statsig-python-core
http-networkingpythonv0.22.0
Install
2.7s avg
Import
Disk
28MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.22.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 29.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.000s · 30MB
28MB installed
● package 28MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StatsigServer
from statsig_python_core import StatsigServer
from statsig_python_core import StatsigServer

This quickstart demonstrates how to initialize the Statsig server SDK, define a user, check a feature gate, retrieve dynamic configs and experiments, and properly shut down the SDK. Ensure you replace `YOUR_SERVER_SECRET_KEY_HERE` with your actual Statsig server secret key and adjust gate/config/experiment names.

import asyncio import os from statsig import StatsigServer async def main(): # Replace with your actual Server Secret Key, or set as STATSIG_SERVER_SECRET_KEY env var sdk_key = os.environ.get("STATSIG_SERVER_SECRET_KEY", "YOUR_SERVER_SECRET_KEY_HERE") if sdk_key == "YOUR_SERVER_SECRET_KEY_HERE": print("Please set your STATSIG_SERVER_SECRET_KEY environment variable or replace the placeholder.") return await StatsigServer.initialize(sdk_key) # Define a user object using a dictionary (StatsigUser class is deprecated) user = { "userID": "test-user-123", "email": "test@example.com", "custom": {"plan": "enterprise"} } # Check a feature gate if await StatsigServer.check_gate(user, "my_feature_gate"): # Replace with your gate name print("my_feature_gate is ON for this user!") else: print("my_feature_gate is OFF for this user.") # Get a dynamic config config = await StatsigServer.get_config(user, "my_dynamic_config") # Replace with your config name string_value = config.get("string_param", "default_string") int_value = config.get("int_param", 0) print(f"Config values: string_param={string_value}, int_param={int_value}") # Get an experiment experiment = await StatsigServer.get_experiment(user, "my_experiment") # Replace with your experiment name variant_value = experiment.get("variant_param", "control") print(f"Experiment variant: {variant_value}") # IMPORTANT: Call shutdown when your application exits to ensure metrics are flushed await StatsigServer.shutdown() if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingThe `StatsigServer.initialize()` and `StatsigServer.shutdown()` methods are now asynchronous and must be awaited.
fix
Prefix calls to `initialize()` and `shutdown()` with `await` and ensure they are run within an async context (e.g., `asyncio.run(main())`).
affects: 0.16.0+
gotchaYou must use a 'Server Secret Key' (prefixed with `secret-`) for `StatsigServer`. Using a 'Client Key' (prefixed with `client-`) will lead to authentication errors and incorrect behavior.
fix
Ensure your `sdk_key` provided to `StatsigServer.initialize()` is a server-side secret key obtained from your Statsig console.
affects: All versions
gotchaFailing to call `StatsigServer.shutdown()` when your application exits can result in unsent metrics and exposures, leading to incomplete data in Statsig.
fix
Always call `await StatsigServer.shutdown()` as part of your application's graceful exit process to ensure all queued events are flushed.
affects: All versions
breakingThe `StatsigUser` class has been removed. User data should now be passed as a dictionary.
fix
Instead of `StatsigUser('user-id')`, use a dictionary like `{'userID': 'user-id', 'email': 'example@example.com'}`.
affects: 0.10.0+
Upgrade
Version history
0.22.0latest on PyPI · released Aug 14, 2026
Audit
Dependencies
httpxrequiredHTTP client for API communication
pydanticrequiredData validation and settings management
pycryptodomexrequiredCryptographic operations for payload decryption
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources