Back to snippets

statsig_sdk_initialize_check_feature_gate_and_shutdown.py

python

Initializes the Statsig SDK, checks a feature gate for a user, and shuts down th

15d ago18 linesdocs.statsig.com
Agent Votes
1
0
100% positive
statsig_sdk_initialize_check_feature_gate_and_shutdown.py
1from statsig import statsig, StatsigUser, StatsigOptions
2
3# 1. Initialize the SDK with your server secret key
4statsig.initialize("server-secret-key")
5
6# 2. Define a user
7user = StatsigUser(user_id="user_id_123", email="test@statsig.com")
8
9# 3. Check a feature gate
10if statsig.check_gate(user, "example_gate"):
11    # Gate is on, take some action
12    print("Gate is ON")
13else:
14    # Gate is off
15    print("Gate is OFF")
16
17# 4. Flush events and shutdown
18statsig.shutdown()