Feature flags in Python: SDKs compared, Flask and Django, and gunicorn pitfalls
How to use feature flags in Python: the PyPI packages and evaluation modes of 17 SDKs, tested OpenFeature code with Flask and per-request context, what forking servers like gunicorn and uWSGI do to SDK threads, and Django-only libraries.
Short answer: Most Python flag SDKs download the rules and evaluate flags in your process, refreshed by a background thread. That thread is the main thing to plan for: threads don't survive a fork, so if your server loads the app before forking workers (gunicorn with --preload, uWSGI without lazy-apps), initialize the SDK in each worker or follow the SDK's post-fork instructions.
Which Python SDKs are there, and how do they evaluate?
Package versions from PyPI and evaluation modes from each vendor's docs, checked on 15 November 2026.
| Tool | PyPI package | How the Python SDK evaluates |
|---|---|---|
| OpenFeature | openfeature-sdk 0.10.0, plus a provider |
Depends on the provider |
| LaunchDarkly | launchdarkly-server-sdk 9.21.0 |
Locally, with the ruleset streamed by background threads (an experimental async client has none) |
| Unleash | UnleashClient 6.9.1 |
Locally, refreshing every 15 seconds by default |
| GrowthBook | growthbook 4.0.1 |
Locally, from cached feature definitions |
| Flagsmith | flagsmith 6.5.1 |
Remotely by default; local evaluation is opt-in (enable_local_evaluation) and refreshes every 60 seconds |
| ConfigCat | configcat-client 10.0.1 |
Locally, auto polling in a thread every 60 seconds by default |
| PostHog | posthog 7.91.1 |
Remotely by default; local evaluation polls every 30 seconds and needs a project secret key (or the legacy feature flags secure API key) |
| Statsig | statsig-python-core 0.24.2 (the legacy statsig package receives only critical bug fixes) |
Locally after initialization |
| DevCycle | devcycle-python-server-sdk 3.14.0 |
Locally with DevCycleLocalClient (polls every 30 seconds by default), or a cloud client |
| Split / Harness FME | splitio_client 10.7.1 |
Locally, with changes pushed or polled |
| Optimizely | optimizely-sdk 5.8.0 |
Locally, from a synced datafile |
| FeatBit | fb-python-sdk 1.2.1 |
Locally, with changes synced over WebSocket |
| Tggl | tggl 1.1.2 (last released 2023) |
Remote client shown in the Python docs; a Python local client isn't documented |
| Flipt | flipt-client 1.5.0 |
In the SDK, polling every 120 seconds by default |
| flagd | openfeature-provider-flagd 0.6.1 |
Remote over gRPC, in-process, or from a local file |
| GO Feature Flag | gofeatureflag-python-provider 1.3.0 |
In-process by default (WASM, config polled every 120 seconds), or remote |
| Azure App Configuration | featuremanagement 2.2.0, azure-appconfiguration-provider 2.5.1 |
Locally; flags refresh when the app calls refresh(), at most every 30 seconds by default |
Sources: each tool profile has an evaluation row with its source. Python details: LaunchDarkly Python, Unleash Python, Flagsmith server-side SDKs, ConfigCat Python, PostHog local evaluation, Statsig Python Core and migration guide, DevCycle Python, FeatBit Python, Tggl Python, Flipt Python client, GO Feature Flag Python provider, Azure Python quickstart.
How do I check flags in a Flask app?
With OpenFeature, the user goes in an evaluation context. Setting it once per request with transaction context means helper functions can check flags without receiving the user. We ran this with openfeature-sdk 0.10.0, openfeature-provider-flagd 0.6.1 and Flask on Python 3.12, with flagd reading a local file, so no server is needed:
from flask import Flask, request
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from openfeature.transaction_context import ContextVarsTransactionContextPropagator
from openfeature.contrib.provider.flagd import FlagdProvider
from openfeature.contrib.provider.flagd.config import ResolverType
api.set_transaction_context_propagator(ContextVarsTransactionContextPropagator())
api.set_provider_and_wait(FlagdProvider(resolver_type=ResolverType.FILE, offline_flag_source_path="flags.json"))
client = api.get_client()
app = Flask(__name__)
@app.before_request
def set_flag_context():
api.set_transaction_context(
EvaluationContext(
targeting_key=request.headers.get("X-User-Id", "anonymous"),
attributes={"plan": request.headers.get("X-Plan", "free")},
)
)
@app.teardown_request
def clear_flag_context(exc):
api.set_transaction_context(EvaluationContext())
def checkout_label():
# No user passed in: the context comes from the current request
return "New checkout" if client.get_boolean_value("new-checkout", False) else "Old checkout"
@app.get("/checkout")
def checkout():
return checkout_label()
With a flags.json whose new-checkout rule is on for plan equal to pro, requests with X-Plan: pro returned "New checkout" and others "Old checkout", and api.shutdown() closed the provider cleanly. A fact-check run sent 200 overlapping requests to Flask's threaded server and every one got its own user's result.
Points that matter in production:
- Clear the context after each request. Flask doesn't give each request a fresh
contextvarscontext, so on servers that reuse threads (gunicorn's threaded workers, waitress, mod_wsgi) the last request's user stays on the thread. Without theteardown_requestreset, a flag checked later on that thread, outside a request, got the previous user's value in our test; with it, the default. - Threads you start don't inherit the context. The propagator "works for threads and asyncio" per the OpenFeature Python README, meaning each thread has its own context; for work in a thread pool, use
contextvars.copy_context().run(...)or pass the context explicitly. - Wait for the provider.
set_provider_and_waitblocks until the provider is ready; with plainset_provider, checks return the default until then. - FastAPI: set the context in a middleware.
- Use real identity: take the user from your session, not from headers the client controls.
What happens with gunicorn and uWSGI?
Pre-forking servers start a parent process and fork workers. Background threads don't survive a fork, so an SDK initialized in the parent keeps serving its last rules in each worker but stops receiving updates. This happens when the app is loaded before the fork: gunicorn imports the app in each worker after forking by default, but not with --preload, while uWSGI loads it in the master unless you set lazy-apps. What the SDK docs say:
| SDK | Guidance |
|---|---|
| LaunchDarkly | Create the client before the fork and call postfork() in each worker; with uWSGI, also set enable-threads. The experimental async client has no background threads |
| Statsig Python Core | Initialize after the fork (its gunicorn example uses post_fork). 0.24.0 and later can recover forked instances: automatically for Celery prefork, or by calling recover_after_fork in the child elsewhere; not for macOS child forks, spawn or forkserver |
| Unleash | uWSGI needs enable-threads to poll in the background, and may need lazy-apps with several processes; in Celery, initialize in worker_process_init |
| ConfigCat | uWSGI disables Python threading by default: enable it or use a different polling mode |
| Flagsmith, PostHog | Local evaluation uses a polling thread; fork guidance isn't stated |
Sources: LaunchDarkly Python, Statsig Python Core, Unleash Python, ConfigCat Python, Flagsmith server-side SDKs, PostHog Python.
The general rule: if the SDK has no documented post-fork step, create the client in each worker: in gunicorn, don't use --preload or create it in the post_fork hook; in uWSGI, use lazy-apps or a @uwsgidecorators.postfork function.
Are there Django-only flag libraries?
Yes, for teams that want flags stored in their own database without a separate service:
- django-waffle 5.0.0 (June 2025): flags, switches and samples managed in the Django admin (GitHub).
- django-flags 5.2.0 (February 2026), from the US Consumer Financial Protection Bureau: flags with conditions, configurable in settings or the admin (docs).
They suit simple on/off and per-user rules inside one Django app. For several services, percentage rollouts with consistent bucketing, experiments or audit logs, a dedicated tool fits better; see self-hosted vs SaaS feature flags.
What else should I watch?
- Remote evaluation by default. Flagsmith and PostHog call their API on every check unless you turn on local evaluation; do that for flags checked on hot paths.
- Legacy packages. Statsig's legacy
statsigpackage is in maintenance mode; new features are instatsig-python-core. - One client per process. FeatBit's README says you "SHOULD instantiate a single FBClient instance for the lifetime of the application"; the same applies to most SDKs, which hold connections and caches.
- Shut down cleanly. Call
api.shutdown()or the vendor's close method so pending events are sent; Unleash'sdestroy()flushes metrics.
For other languages, see feature flags in Node.js, Go and Java. On speed and outages, see local vs remote evaluation. To pick a tool, see the best feature flag tools or the directory.