← Back to all products
$19
Feature Flags
Feature flag system with boolean flags, percentage rollouts, user targeting, and A/B tests.
PythonMarkdown
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 9 files
feature-flags/
├── LICENSE
├── README.md
├── examples/
│ └── basic_example.py
├── free-sample.zip
├── guide/
│ ├── 01_features.md
│ ├── 02_quick-start.md
│ └── 03_project-structure.md
├── index.html
└── src/
└── main.py
📖 Documentation Preview README excerpt
Feature Flags
A Python feature flag system for SaaS applications. Supports boolean flags, percentage rollouts, user targeting rules, A/B testing with deterministic variant assignment, kill switches, and scheduled activations — all built on Python's standard library.
Features
- Boolean flags — Simple on/off toggles for any feature
- Percentage rollouts — Gradual rollout via deterministic hashing (consistent per user)
- User targeting — Rules matching on user attributes (plan, email, role, etc.)
- A/B testing — Multiple variants with consistent assignment per user
- Kill switch — Emergency one-call disable for any flag
- Scheduled flags — Auto-enable/disable at specified times
- Match operators —
eq,neq,contains,in,gt,lt - Evaluate all — Bootstrap all flags for a user in one call (great for frontends)
- JSON persistence — Save/load flag configs and evaluation logs
Requirements
- Python 3.10+
- No external dependencies (stdlib only)
Quick Start
# Start with demo flags
python src/main.py --init-demo
# Custom port
python src/main.py --port 8003
Then try the API:
# List all flags
curl http://localhost:8003/api/flags
# Evaluate a flag for a user
curl -X POST http://localhost:8003/api/flags/new_dashboard/evaluate \
-H "Content-Type: application/json" \
-d '{"context": {"user_id": "user_123", "plan": "pro", "email": "user@docs.example.com"}}'
# Kill switch
curl -X POST http://localhost:8003/api/flags/new_dashboard/kill
# Revive
curl -X POST http://localhost:8003/api/flags/new_dashboard/revive
API Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /api/flags | List all flags |
| POST | /api/flags | Create a new flag |
| POST | /api/flags/:key/evaluate | Evaluate flag for a user context |
| POST | /api/flags/:key/evaluate-all | Evaluate ALL flags for a user |
| POST | /api/flags/:key/kill | Emergency kill switch |
| POST | /api/flags/:key/revive | Re-enable a killed flag |
... continues with setup instructions, usage examples, and more.
📄 Code Sample .py preview
examples/basic_example.py#!/usr/bin/env python3
"""
Feature Flags — Basic Usage Example
=====================================
Demonstrates:
1. Creating flags with different rollout strategies
2. Evaluating flags with user context
3. Percentage rollout consistency
4. A/B test variant assignment
5. Kill switch
Run: python3 basic_example.py
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
from main import FlagEngine, TargetingRule
def main() -> None:
print("=== Feature Flags — Basic Example ===\n")
engine = FlagEngine(data_dir=Path("/tmp/flags-demo"))
# --- 1. Simple boolean flag ---
engine.create_flag("dark_mode", name="Dark Mode", default_enabled=True)
result = engine.evaluate("dark_mode")
print(f"dark_mode: enabled={result.enabled}, reason={result.reason}")
# --- 2. Percentage rollout ---
engine.create_flag("new_editor", name="New Editor", rollout_percentage=30,
default_enabled=True)
# Simulate 10 users
print("\nnew_editor (30% rollout):")