Skip to main content

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) with eq/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

Metadata

Release files for larzflags 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 larzflags 0.1.0
File Size Uploaded
larzflags-0.1.0.tar.gz 5.4 kB Details

Built distribution (wheel)

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

Total release size: 10.7 kB

Release files / larzflags-0.1.0.tar.gz

Download URL larzflags-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4b2382168a5c0961ed183dc8945a107395028ee2caf5be4b2cfabc5ea27d78cb
BLAKE2b-256 checksum
How to use checksums
61c470f39ebb5033a38df572ed0e59e57060f141938842ef9b2e5af35cc3c7cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL larzflags-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6918c71931c92d7bfaa97631d7574caf9a28e1f639278d8b24a1166706dd9d9
BLAKE2b-256 checksum
How to use checksums
39aa07137ca82eaaca00c641111ed016d9faa54ebc0aa9eee26aa79227b8ef19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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