Metadata-Version: 2.4
Name: simple_module_feature_flags
Version: 0.0.7
Summary: Simple feature-flag module with per-tenant overrides and a consumer API for simple_module
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
Project-URL: Repository, https://github.com/antosubash/simple_module_python
Project-URL: Issues, https://github.com/antosubash/simple_module_python/issues
Project-URL: Changelog, https://github.com/antosubash/simple_module_python/blob/main/CHANGELOG.md
Author-email: Anto Subash <antosubash@live.com>
License-Expression: MIT
License-File: LICENSE
Keywords: feature-flags,multi-tenant,simple-module,toggles
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: simple-module-core==0.0.7
Requires-Dist: simple-module-db==0.0.7
Requires-Dist: simple-module-hosting==0.0.7
Description-Content-Type: text/markdown

# simple_module_feature_flags

Feature flags for [simple_module](https://github.com/antosubash/simple_module_python) apps. Global flags with per-tenant overrides, a tiny consumer API, and no external service to run.

## Install

```bash
pip install simple_module_feature_flags
```

## What it provides

- `Flag` and `TenantFlagOverride` SQLModel tables.
- `is_enabled("flag.name", tenant_id=...)` consumer API.
- Admin UI at `/feature-flags/admin` — toggle flags, add tenant overrides.
- Cache layer so checking a flag on every request is cheap.

## Usage

Gate a route:

```python
from feature_flags import is_enabled   # type: ignore[import-not-found]
from fastapi import APIRouter, Depends, HTTPException

router = APIRouter()


@router.get("/new-feature")
async def new_feature(tenant_id: int = Depends(current_tenant_id)):
    if not await is_enabled("orders.new_pricing_engine", tenant_id=tenant_id):
        raise HTTPException(404)
    return {"rolled_out": True}
```

Seed a flag in a migration or admin UI:

```python
# via migration
Flag(name="orders.new_pricing_engine", enabled=False)
```

Tenant override:

```python
TenantFlagOverride(tenant_id=7, flag_name="orders.new_pricing_engine", enabled=True)
```

## Depends on

- `simple_module_core`, `simple_module_db`, `simple_module_hosting`

## License

MIT — see [LICENSE](https://github.com/antosubash/simple_module_python/blob/main/LICENSE).
