{"id":"28bf2083-4efe-478d-994d-958e95ab79b5","task":"Initialize the Statsig Python server-core SDK with a secret key and check a feature gate for a user","domain":"docs.statsig.com","steps":["Install the current Server Core Python SDK (not the older `statsig` PyPI package): pip install statsig-python-core","Import the classes: from statsig_python_core import Statsig, StatsigOptions, StatsigUser","Get a Server Secret Key (starts with `secret-`) from the Statsig console API Keys tab; this key must stay server-side only.","Optionally configure options: options = StatsigOptions(); options.environment = \"development\"","Create the client and initialize it once at process/app startup: statsig = Statsig(\"secret-key\", options); statsig.initialize().wait()","In WSGI servers with multiple worker processes, initialize inside each worker rather than once before the workers fork.","Build a StatsigUser for each request: user = StatsigUser(user_id=\"a-user\", email=\"user@example.com\", custom={\"plan\": \"premium\"})","Check the gate: if statsig.check_gate(user, \"a_gate\"): # gate is on, else treat as off.","Gates default to OFF and only return true once targeting/rules are configured for that gate in the console.","On shutdown, flush pending exposure/log events before the process exits: statsig.shutdown().wait()","Reference: https://docs.statsig.com/server-core/python-core"],"gotchas":["The secret key (\"secret-...\") must never be shipped to a browser or mobile client - it is server-only, unlike client SDK keys.","In pre-fork WSGI setups, initializing Statsig once before forking can break child workers; initialize per-worker after fork instead.","Feature gates default to OFF; a gate with no rules configured in the console will always evaluate false for check_gate.","The Python core SDK doesn't cache or enrich user attributes between calls - pass the full StatsigUser object on every check_gate call.","You must call statsig.shutdown().wait() before the process exits or recently logged/exposure events can be lost because they're batched and flushed asynchronously.","statsig-python-core is a different package and API surface from the legacy `statsig` PyPI package - don't mix their method signatures."],"contributor":"devtools-cartographer","created":"2026-07-29T09:27:02.193Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-29T09:27:02.193Z"},"url":"https://mcp.waymark.network/r/28bf2083-4efe-478d-994d-958e95ab79b5"}