Skip to main content

Simple feature-flag module with per-tenant overrides and a consumer API for simple_module

Project description

simple_module_feature_flags

Feature flags for simple_module apps. Global flags with per-tenant overrides, a tiny consumer API, and no external service to run.

Install

pip install simple_module_feature_flags

What it provides

  • Flags are declared via the framework register_feature_flags hook (FeatureFlagDefinition(name, default_enabled=...)); the module persists only overrides in the feature_flags_override SQLModel table (scoped by scope / scope_id).
  • FeatureFlagRegistry.is_enabled("flag.name", tenant_id=...) consumer API (resolution order: tenant override > system override > declared default).
  • Admin UI at /feature_flags — toggle flags, add per-scope overrides.
  • The registry is an in-memory cache hydrated from the DB so checking a flag on every request is cheap.

Usage

Declare a flag in your module:

from simple_module_core.feature_flags import FeatureFlagDefinition, FeatureFlagRegistry


class OrdersModule(ModuleBase):
    def register_feature_flags(self, registry: FeatureFlagRegistry) -> None:
        registry.add(FeatureFlagDefinition(name="orders.new_pricing_engine", default_enabled=False))

Gate a route using the registry dependency:

from fastapi import APIRouter, HTTPException

from feature_flags.deps import FeatureFlagRegistryDep   # type: ignore[import-not-found]

router = APIRouter()


@router.get("/new-feature")
async def new_feature(flags: FeatureFlagRegistryDep):
    if not flags.is_enabled("orders.new_pricing_engine"):
        raise HTTPException(404)
    return {"rolled_out": True}

Overrides (system or per-tenant) are managed through the admin UI at /feature_flags.

Depends on

  • simple_module_core, simple_module_db, simple_module_hosting

License

MIT — see 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

simple_module_feature_flags-0.0.19.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_module_feature_flags-0.0.19-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file simple_module_feature_flags-0.0.19.tar.gz.

File metadata

File hashes

Hashes for simple_module_feature_flags-0.0.19.tar.gz
Algorithm Hash digest
SHA256 8d269bed8da316bdca17506c9e4a569b4852e74a9d773fedcf402fd0f9966d9c
MD5 1c6d9e05e044665c2fb1037ee20f8951
BLAKE2b-256 221acadae85a301e271b228de18e7206911980fa05a0a4803c3caf0965d9993f

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_module_feature_flags-0.0.19.tar.gz:

Publisher: release.yml on antosubash/simple_module_python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file simple_module_feature_flags-0.0.19-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_module_feature_flags-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 5421eba7652335d70ee48e8ab632fcfee080a982bf7bc652a4dbf835d7aceb22
MD5 779203654697ba9f7b5a04771490a603
BLAKE2b-256 7f04fbbb8942b5ad280f3de6a14205e801a52e107270a93a4c02e60d8ce5a752

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_module_feature_flags-0.0.19-py3-none-any.whl:

Publisher: release.yml on antosubash/simple_module_python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page