Simple feature flags with percentage rollout and user targeting.
Project description
philiprehberger-feature-flag
Simple feature flags with percentage rollout and user targeting.
Installation
pip install philiprehberger-feature-flag
Usage
Basic flags
from philiprehberger_feature_flag import flags
flags.load({"dark_mode": True, "beta_ui": False})
if flags.is_enabled("dark_mode"):
enable_dark_mode()
Percentage rollout
flags.load({
"new_checkout": {
"enabled": True,
"rollout": 25, # 25% of users
}
})
if flags.is_enabled("new_checkout", user_id="user-42"):
show_new_checkout()
User targeting
flags.load({
"admin_panel": {
"enabled": True,
"users": ["alice", "bob"],
}
})
if flags.is_enabled("admin_panel", user_id="alice"):
show_admin_panel()
Load from JSON file
flags.load("flags.json")
Load from environment variables
# Set FF_DARK_MODE=true, FF_BETA=0, etc.
flags.load() # reads FF_* env vars
Runtime overrides
flags.override("beta_ui", True) # force-enable for testing
flags.reset() # clear all overrides
Change callbacks
def on_flag_change(name, old, new):
print(f"Flag {name} changed from {old} to {new}")
flags.on_change(on_flag_change)
flags.load({"dark_mode": True})
# prints: Flag dark_mode changed from None to True
Flag groups
flags.load({
"ui_dark_mode": True,
"ui_sidebar": False,
"api_rate_limit": 100,
})
ui_flags = flags.group("ui_")
# {"ui_dark_mode": True, "ui_sidebar": False}
API
| Function / Method | Description |
|---|---|
FlagStore() |
Create a new flag store |
store.load(config) |
Load flags from dict, JSON file path, or env vars (None) |
store.is_enabled(name, **context) |
Check if a flag is enabled |
store.all() |
Return all loaded flags as a dict |
store.override(name, value) |
Set a runtime override |
store.reset() |
Clear all runtime overrides |
store.on_change(callback) |
Register a callback fired as callback(flag_name, old_value, new_value) on changes |
store.group(prefix) |
Return dict of flags whose name starts with prefix with resolved values |
flags |
Module-level FlagStore instance |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_feature_flag-0.2.1.tar.gz.
File metadata
- Download URL: philiprehberger_feature_flag-0.2.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7711b5e8393066b8ea26a1ca28e8b49a6456719bdba526b8212890a63eeaf03c
|
|
| MD5 |
c6a0dfec378591bd77ccd9a3798b9c83
|
|
| BLAKE2b-256 |
fe69298e73d571f32153c23cf3ffc78a4db27bcf17c42aefb4cde461fd1a8e99
|
File details
Details for the file philiprehberger_feature_flag-0.2.1-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_feature_flag-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d75681dd97b4bd19186c90d5eae45bd553572756034a2f006f53a65870508aa7
|
|
| MD5 |
09e37e6ff2142b88ce864a76bb7cdea0
|
|
| BLAKE2b-256 |
8b9f7e27c5804b2cc04072585e620069c444f0d4feb72954ca32a2dfc0f2b96c
|