Why fastapi-rls
Enforced by PostgreSQL
Policies compile to native ROW LEVEL SECURITY. Isolation is enforced by the database on every SELECT/INSERT/UPDATE/DELETE — not by application code you have to remember to write.
ORM-agnostic core
Policies, context, and DDL have zero framework dependencies. SQLAlchemy, FastAPI, and Alembic are optional adapters. The security-critical code is small, auditable, and testable without a database.
Leak-proof by construction
Identity is applied with SET LOCAL inside a per-request transaction and scrubbed on pool checkout. A request with no context sees no rows — never everyone’s.
Sync and async
First-class support for both Session and AsyncSession. Copy-on-write context vars keep concurrent requests isolated across asyncio tasks and threadpool threads.
Immutable identity
user_id and tenant_id cannot be silently overridden mid-request. Elevating requires an explicit, auditable system context.
Migrate your way
Alembic operation directives (op.create_policy) for migration users, and a standalone fastapi-rls CLI (sync/plan/audit) for everyone else.