Skip to main content

Fiicha is minimalistic mypy-friendly feature flag implementation with no external dependencies.

Installation

pip install fiicha

For Development

Clone the repo, change current working dir to the root of the repo and execute:

python -m venv env
. env/bin/activate
pip install -e .[test,lint]

Usage

Basic

Basic usage is simple:

  1. Sublcass from FeatureFlags

  2. Add FeatureFlag attributes representing individual feature flags.

from fiicha import FeatureFlag, FeatureFlags

class MyProjectFeatureFlags(FeatureFlags):
    release_x = FeatureFlag("Enable features from upcoming release X")
    use_new_algorithm = FeatureFlag("Use new algorithm for ...")

ff = MyProjectFeatureFlags({"release_x": True})

print(ff.release_x)  # True
print(ff.use_new_algorithm)  # False

In addition, you kan specify a key defining default state of the feature flags:

ff = MyProjectFeatureFlags({"all": True, "release_x": False}, default_key="all")

print(ff.release_x)  # False
print(ff.use_new_algorithm)  # True

Classes subclassed from FeatureFlags has full type hint support, so when you are accessing removed or otherwise non-existent feature flags, you can detect it before running tests:

ff.xxx  # will trigger mypy's attr-defined error

Utils

The package comes with few util functions to avoid building your own framework for simple use cases.

Single-line Configuration

from fiicha import parse_feature_flags_string

flags_string = "release_x !use_new_algorithm"  # stored in config
ff = MyProjectFeatureFlags(parse_feature_flags_string(flags_string))

print(ff.release_x)  # True
print(ff.use_new_algorithm)  # False

Load Flags From Environment Variables

import os
from fiicha import feature_flags_from_environ

os.environ["MYPROJ_FEATURE_RELEASE_X"] = "True"  # can also be 1, t, yes, on
os.environ["MYPROJ_FEATURE_USE_NEW_ALGORITHM"] = "False"  # can also be 0, f, no, off or empty string

ff = MyProjectFeatureFlags(feature_flags_from_environ("MYPROJ_FEATURE_"))

print(ff.release_x)  # True
print(ff.use_new_algorithm)  # False

Automatically Document Your Feature Flags

from fiicha import make_napoleon_doc, make_sphinx_doc

class GoogleStyleDocFeatureFlags(FeatureFlags, make_doc=make_napoleon_doc):
    a = FeatureFlag("Enable feature A")
    b = FeatureFlag("Enable feature B")

class SphinxStyleDocFeatureFlags(FeatureFlags, make_doc=make_sphinx_doc):
    x = FeatureFlag("Enable feature X")
    y = FeatureFlag("Enable feature Y")

print(GoogleStyleDocFeatureFlags.__doc__)
print(SphinxStyleDocFeatureFlags.__doc__)

Context Variable Support

You might want to do A/B testing or otherwise toggle feature flags for individual users without affecting the rest of the system. For such cases, there is FeatureFlagsContext - a wrapper around ContextVar. It copies current feature flags and sets them as new context variable on enter and resets them back on exit. This way you will be able to achieve global feature flags protection from changes made within context of a request or a task.

from contextvars import ContextVar
from fiicha import FeatureFlag, FeatureFlags, FeatureFlagsContext

class MyFeatureFlags(FeatureFlags):
    a = FeatureFlag("Enable feature A")
    b = FeatureFlag("Enable feature B")

root = MyFeatureFlags()
var: ContextVar[MyFeatureFlags] = ContextVar("test", default=root)
ff_ctx = FeatureFlagsContext(var)

with ff_ctx:
    ff = var.get()
    ff.a = True

    assert ff is not root  # is a copy

assert not root.a  # not changed

Advanced

See examples subfolder within the repo.

Metadata

Release files for fiicha 0.2.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 fiicha 0.2.0
File Size Uploaded
fiicha-0.2.0.tar.gz 9.0 kB Details

Built distribution (wheel)

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

Total release size: 17.6 kB

Release files / fiicha-0.2.0.tar.gz

Download URL fiicha-0.2.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a1ddad744fdbf4ee8b003136964381b4722a8c072ef41781da10bd1a6728ae8b
BLAKE2b-256 checksum
How to use checksums
783b17d02248d9e53fd37a4efb151af17e413fdc44b682fd52d9006abaf72e14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

Release files / fiicha-0.2.0-py3-none-any.whl

Download URL fiicha-0.2.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1781ec9170a0e84df3cf5a3526ed273396db29cbf3a19c2b6794c93a08b82e3
BLAKE2b-256 checksum
How to use checksums
97c6a0408aeda414110faafd970224a34decf06ac38fcf86db849fb9df321971
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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