Skip to main content

FeatureFlow

A realtime, distributed feature flag engine for Django. Flags are evaluated in-process from a local in-memory cache, kept consistent across all workers via Redis pub/sub. Zero network hops on the hot path.


Requirements

  • Python 3.11+
  • Django 5.2+
  • PostgreSQL 14+ (uses ArrayField)
  • Redis 6+

Installation

pip install -r requirements.txt

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "rest_framework",
    "rest_framework.authtoken",
    "featureflow.apps.FeatureFlowConfig",
]

Mount the API in your root URLconf:

from django.urls import include, path

urlpatterns = [
    path("api/", include("featureflow.urls")),
]

Configuration

Add a FEATUREFLOW block to your Django settings:

FEATUREFLOW = {
    "REDIS_URL": "redis://localhost:6379",   # Redis connection string
    "ENV": "production",                     # Default environment label
    "CACHE_TTL": 300,                        # Seconds before a full cache refresh
    "DEFAULT_VALUE": False,                  # Returned when a flag key is missing
}

Database setup

# Create the PostgreSQL database
createdb featureflow

# Run migrations
python manage.py migrate

Usage

Python SDK

from featureflow import feature_enabled, enable, disable

# Basic check (no user context)
if feature_enabled("dark-mode"):
    ...

# Per-user evaluation with conditions + rollout
if feature_enabled("new-checkout", user=request.user):
    ...

# Pass extra context attributes not on the user object
if feature_enabled("beta-search", user=request.user, context={"country": "NG"}):
    ...

# Programmatically flip flags
enable("dark-mode")    # sets enabled=True, rollout_percentage=100
disable("dark-mode")   # sets enabled=False

Evaluation order

  1. Fetch flag from local in-memory cache (never DB directly).
  2. Flag missing or enabled=False → return DEFAULT_VALUE.
  3. rollout_percentage == 100 → return True.
  4. user.id in targeted_user_ids → return True.
  5. User attributes don't satisfy conditions → return False.
  6. HMAC-based deterministic bucket: hmac(flag_key, user_id) % 100 < rollout_percentage.

REST API

All endpoints require authentication (Token or Session).

Method URL Description
POST /api/flags/ Create a flag
GET /api/flags/ List all flags (?environment=production)
GET /api/flags/<key>/ Retrieve a flag
PATCH /api/flags/<key>/ Partial update
DELETE /api/flags/<key>/ Delete
POST /api/flags/<key>/enable/ Enable + set 100% rollout
POST /api/flags/<key>/disable/ Disable
GET /api/flags/<key>/audit/ Audit log for this flag

Create a flag

curl -X POST http://localhost:8000/api/flags/ \
  -H "Authorization: Token <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "key": "dark-mode",
    "name": "Dark Mode",
    "enabled": true,
    "rollout_percentage": 50,
    "conditions": {"subscription": "premium"},
    "targeted_user_ids": [1, 2, 3],
    "environment": "production"
  }'

Obtain an auth token

python manage.py drf_create_token <username>

Flag model fields

Field Type Description
key slug Unique identifier used in code
name string Human-readable label
description string Optional notes
enabled bool Master switch
rollout_percentage 0–100 % of users who see the feature
conditions JSON User attribute filters (all must match)
targeted_user_ids int[] Users who always get the feature
environment enum development / staging / production

How caching and pub/sub work

  1. On startup (AppConfig.ready), all flags are loaded from PostgreSQL into a thread-safe in-memory dict.
  2. A background daemon thread subscribes to the Redis channel featureflow:flags.
  3. Every time a flag is saved or deleted, a post_save / post_delete signal publishes the updated payload to that channel.
  4. All workers receive the message and update their local caches atomically via threading.RLock.
  5. If Redis is unavailable, each worker continues serving the last known cached state with no interruption.

Running tests

# Create the test database
createdb featureflow_test

# Run the full suite
pytest

Tests mock Redis pub/sub interactions and require a live PostgreSQL connection for API and model tests.


Django Admin

Visit /admin/ to manage flags and view immutable audit logs. The audit log admin is read-only.

Metadata

Release files for django-featureflow 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-featureflow 0.1.0
File Size Uploaded Provenance Actions
django_featureflow-0.1.0.tar.gz 12.2 kB Without provenance Details for django_featureflow-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-featureflow 0.1.0
File Interpreter ABI Platform Actions
django_featureflow-0.1.0-py3-none-any.whl Python 3 none any Details for django_featureflow-0.1.0-py3-none-any.whl

Total release size: 25.9 kB

Release files / django_featureflow-0.1.0.tar.gz

Download URL django_featureflow-0.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dbe67239fc7b75c3ed37cdac64e88ad94dfa89bdba72ed5c5a67700b56b83ecd
BLAKE2b-256 checksum
How to use checksums
6520af39a1a781dc940d50ca54102172738cb9dcd97c68699d7c145b3220517c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / django_featureflow-0.1.0-py3-none-any.whl

Download URL django_featureflow-0.1.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc7165f1f0f9c21214e23c469bee8dacf2ba16e585ebb3a15d37fd9804cd8218
BLAKE2b-256 checksum
How to use checksums
df716b21e769be2d0a482e28ab28fb16a893e04f2b3ed7c7facba7019c9c77ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for django-featureflow 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page