Feature flags for Django, Flask, FastAPI, and any Python application
Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.
pip install requests
import requests
from functools import lru_cache
FLAGBIT_SDK_KEY = "your_sdk_key_here"
FLAGBIT_URL = "https://flagbit.anethoth.com/api/v1/evaluate"
def get_flag(flag_key: str, context: dict = None) -> bool:
"""Evaluate a feature flag via FlagBit API."""
resp = requests.post(FLAGBIT_URL, json={
"flag_key": flag_key,
"context": context or {}
}, headers={
"X-SDK-Key": FLAGBIT_SDK_KEY
}, timeout=5)
return resp.json().get("value", False)
# Django view example
def dashboard_view(request):
user_ctx = {"user_id": str(request.user.id), "plan": request.user.plan}
if get_flag("new-dashboard", user_ctx):
return render(request, "dashboard_v2.html")
return render(request, "dashboard.html")
# Flask example
@app.route("/checkout")
def checkout():
if get_flag("express-checkout", {"user_id": session["user_id"]}):
return render_template("express_checkout.html")
return render_template("checkout.html")
# FastAPI example
@app.get("/api/recommendations")
async def recommendations(user_id: str):
if get_flag("ml-recommendations", {"user_id": user_id}):
return await get_ml_recommendations(user_id)
return await get_basic_recommendations(user_id)
Gate new Django model fields or views behind flags — roll back instantly if the migration causes issues.
Gradually migrate API consumers from v1 to v2 by flagging users onto the new version.
A/B test a new ML model against the existing one with percentage-based rollouts.
Enable or disable Celery tasks without redeploying — useful for load management.
Define flags in your FlagBit dashboard with targeting rules and rollout percentages.
Call the evaluate endpoint from your Python app with user context for targeted rollouts.
Enable, disable, or adjust rollouts in real-time. No redeployment needed.
Yes — FlagBit is a simple HTTP API. Call it from views, middleware, or template tags. No Django-specific package required.
Yes — use functools.lru_cache with a TTL wrapper, or cache in Redis/memcached for distributed caching.
Always use a default value (usually False) and wrap the call in a try/except. Your app should work without feature flags.
Mock the get_flag function in tests. Use parametrize to test both flag states.
Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.
Get Your Free API Key