larzflags
Feature flags with deterministic rollout & targeting. Pure Python, zero deps.
Ship code dark, turn it on for 5% of users, then 50%, then everyone - or enable it only for a plan, a country, or an allowlist. The key property is stable bucketing: a given user is always on the same side of a percentage rollout, so nobody flickers between on and off across requests.
from larzflags import FeatureFlags
flags = FeatureFlags()
flags.add("new_ui", enabled=True)
flags.add("beta", percentage=25) # 25% of users
flags.add("pro", rules=[("plan", "eq", "pro")]) # targeting
flags.add("vip", allow=["u1"], deny=["u2"])
flags.is_enabled("beta", user="alice") # stable per user
flags.is_enabled("pro", context={"plan": "pro"}) # True
Why
- Deterministic rollout. Percentage gating hashes
flag + user, so a user's on/off state is stable across requests and processes - no random flicker, and ramping 10% -> 50% keeps the original 10% on. - Targeting rules.
("attribute", op, value)witheq/ne/in/nin/gt/lt/gte/lte/contains, ANDed together, against a context dict. - Allow/deny lists override everything for specific users.
- A/B variants.
variant()returns a weighted variant chosen deterministically per user - perfect for experiments. - Zero dependencies. No SaaS, no SDK.
Install
pip install larzflags
Usage
from larzflags import FeatureFlags
flags = FeatureFlags()
flags.add("checkout_v2", percentage=10)
flags.add("eu_feature", rules=[("country", "in", ["DE", "FR", "ES"])])
flags.add("experiment", variants={"control": 50, "treatment": 50})
if flags.is_enabled("checkout_v2", user=user_id):
...
flags.variant("experiment", user=user_id) # "control" or "treatment", stable
flags.all_enabled(user=user_id) # set of on flags
flags.set_percentage("checkout_v2", 50) # ramp up
Tests
python -m unittest discover -s tests -v # 16 tests incl. rollout distribution
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT (c) larz-scripter
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 larzflags-0.1.0.tar.gz.
File metadata
- Download URL: larzflags-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b2382168a5c0961ed183dc8945a107395028ee2caf5be4b2cfabc5ea27d78cb
|
|
| MD5 |
a78a140150f0d19638c865bf3c354766
|
|
| BLAKE2b-256 |
61c470f39ebb5033a38df572ed0e59e57060f141938842ef9b2e5af35cc3c7cd
|
File details
Details for the file larzflags-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzflags-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6918c71931c92d7bfaa97631d7574caf9a28e1f639278d8b24a1166706dd9d9
|
|
| MD5 |
29e329086746d39d84ef230acfa47248
|
|
| BLAKE2b-256 |
39aa07137ca82eaaca00c641111ed016d9faa54ebc0aa9eee26aa79227b8ef19
|