This release is a pre-release and may not be stable for production use.
OutlabsAuth
Library-first authentication and authorization for FastAPI — RBAC, optional ABAC, API keys, and Postgres-backed permissions that live inside your app.
Alpha — packaged on PyPI; the public API is still settling before 1.0.
Why OutlabsAuth
Most auth products push you into a separate IdP or a black-box service. OutlabsAuth is the opposite: a Python library you mount into your FastAPI app, with your Postgres, your routes, and your deployment.
| You get | Details |
|---|---|
| Two presets | SimpleRBAC (flat roles) or EnterpriseRBAC (entity hierarchy + tree permissions) |
| Auth surface | JWT access/refresh, API keys, service tokens, invitations, optional OAuth / magic link / access codes |
| Admin console | Optional sister app OutlabsAuth UI — point it at any host that mounts this library |
| Ops | Packaged Alembic migrations, CLI bootstrap, Redis when needed, optional in-process permission cache (cache_backend="memory") |
Documentation
Implementers start in the OutlabsAuth Handbook
(docs-library/) — human-readable guides written for people integrating the
library. A Nuxt docs site lives beside this repo at
../outlabsAuth-docs (Nuxt UI docs template); re-port
with python3 scripts/port_handbook.py from that project.
| Guide | What it covers |
|---|---|
| Handbook home | Reading paths, full guide index |
| Introduction | Mental model in a few minutes |
| Getting Started | Install → migrate → mount → login → optional UI |
| Choosing a Preset | SimpleRBAC vs EnterpriseRBAC in plain language |
| Routers & Prefixes | Which get_*_router factories to mount |
| Configuration | Constructor flags, Redis, schema, production defaults |
| OAuth · Sessions & audit · Passwordless | Optional auth extensions |
| Examples | Runnable SimpleRBAC + EnterpriseRBAC apps |
| OutlabsAuth UI | Sister admin console (Vite/React) |
Maintainers (design decisions, audits, release process): docs/.
Deep host DX / feature matrix when you need them:
API design,
Comparison matrix.
Choose a Preset
Need departments / teams / org tree?
NO → SimpleRBAC
YES → EnterpriseRBAC
| Need | Preset |
|---|---|
| Flat users → roles → permissions | SimpleRBAC |
| Hierarchy, memberships, tree permissions | EnterpriseRBAC |
Install
pip install outlabs-auth
You need PostgreSQL. Provide at least:
- a
postgresql+asyncpg://...URL - a JWT
secret_key(≥ 32 characters for HS256)
Quickstart
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
from outlabs_auth import SimpleRBAC
from outlabs_auth.routers import get_auth_router
auth = SimpleRBAC(
database_url="postgresql+asyncpg://postgres:postgres@localhost:5432/app",
# Must be at least 32 characters when signing with HS256, or construction
# fails. Generate one with:
# python -c "import secrets; print(secrets.token_urlsafe(48))"
secret_key=os.environ["SECRET_KEY"],
)
# Builds the engine, services and dependencies synchronously. Required *before*
# any router factory runs: they dereference `auth.deps`, which otherwise only
# exists after `initialize()` — and that's async, so it cannot run at import.
auth.prime_fastapi_routing()
@asynccontextmanager
async def lifespan(app: FastAPI):
await auth.initialize() # async work: migrations, Redis, service wiring
yield
await auth.shutdown()
app = FastAPI(lifespan=lifespan)
# Installs the exception handlers *and* the UnitOfWork/RequestCache middleware.
# Prefer this over bare register_exception_handlers(): the middleware commits
# before the response is sent, which is what makes a create immediately readable.
auth.instrument_fastapi(app)
app.include_router(get_auth_router(auth, prefix="/auth"))
tests/unit/test_readme_quickstart.py executes this block, so it cannot rot.
Deliberate details:
prime_fastapi_routing()before mounting — otherwiseConfigurationError: Dependencies not initialized- Real
secret_key— placeholders under 32 characters fail at construction under HS256
You can also mount inside lifespan() after initialize() (no priming) — see examples/simple_rbac/main.py.
For production, run migrations with the CLI (auto_migrate=False). Continue with Getting Started and Configuration.
OutlabsAuth UI
Optional sister repository: a Vite/React admin console that plugs into any app hosting this library. It reads GET {authApiPrefix}/auth/config and adapts to Simple vs Enterprise.
# Terminal 1 — Enterprise example API
cd examples/enterprise_rbac
uv sync && uv run outlabs-auth migrate && uv run python reset_test_env.py
uv run uvicorn main:app --reload --port 8004
# Terminal 2 — from the outlabsAuth repo root
cd ../OutlabsAuthUI # https://github.com/outlabsio/OutlabsAuthUI
bun install
cp public/app-config.template.json public/app-config.json
# apiBaseUrl: http://localhost:8004 authApiPrefix: /v1
bun run dev
Sign in with a seeded admin (e.g. admin@acme.com / Testpass1!). Full wiring: docs/AUTH_UI.md.
CLI Bootstrap
export DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/app
# optional: export OUTLABS_AUTH_SCHEMA=outlabs_auth
outlabs-auth migrate
outlabs-auth seed-system
outlabs-auth bootstrap-admin --email admin@example.com --password 'ChangeMe_now1!'
Useful operators: outlabs-auth doctor (read-only preflight), outlabs-auth bootstrap (idempotent first-boot). See Configuration and docs/DEPLOYMENT_GUIDE.md.
Production Snapshot
from outlabs_auth import EnterpriseRBAC
auth = EnterpriseRBAC(
database_url="postgresql+asyncpg://user:password@db-host/app?ssl=require",
database_schema="outlabs_auth",
secret_key="replace-me-with-a-long-secret",
auto_migrate=False,
redis_url="redis://cache-host:6379/0",
)
- Prefer a direct Postgres URL over transaction-pooler endpoints for auth-heavy apps
- Migrate in a single-process prestart step; then start workers
- Mount under an app-owned prefix such as
/iam - Point OutlabsAuth UI
authApiPrefixat that same prefix
export DATABASE_URL='postgresql+asyncpg://user:password@db-host/app?ssl=require'
export OUTLABS_AUTH_SCHEMA='outlabs_auth'
outlabs-auth migrate
outlabs-auth seed-system
exec uvicorn myapp.main:app --host 0.0.0.0 --port 8000 --workers 2
Status
Current Library Version: 0.1.0a26
Publication Status: Approved immutable release source for PyPI publication.
Release Stage: Alpha
License
MIT, copyright 2026 OUTLABS LLC.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file outlabs_auth-0.1.0a26.tar.gz.
File metadata
- Download URL: outlabs_auth-0.1.0a26.tar.gz
- Upload date:
- Size: 368.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43528893b084e56e75dfe22b0a78d55166172c76e62683e404dfb9d5e95a0808
|
|
| MD5 |
3132dfebeee4ae0535c95859037cc30f
|
|
| BLAKE2b-256 |
f89a16040b17bf3b287839dccb7e8566c46cbc4beb180e2886d0fcc255c2a179
|
Provenance
The following attestation bundles were made for outlabs_auth-0.1.0a26.tar.gz:
Publisher:
publish-pypi.yml on outlabsio/outlabsAuth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
outlabs_auth-0.1.0a26.tar.gz -
Subject digest:
43528893b084e56e75dfe22b0a78d55166172c76e62683e404dfb9d5e95a0808 - Sigstore transparency entry: 2285436405
- Sigstore integration time:
-
Permalink:
outlabsio/outlabsAuth@0ba4065d50003e6723059dbedeb8f72980187f88 -
Branch / Tag:
refs/tags/v0.1.0a26 - Owner: https://github.com/outlabsio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@0ba4065d50003e6723059dbedeb8f72980187f88 -
Trigger Event:
push
-
Statement type:
File details
Details for the file outlabs_auth-0.1.0a26-py3-none-any.whl.
File metadata
- Download URL: outlabs_auth-0.1.0a26-py3-none-any.whl
- Upload date:
- Size: 487.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c47e1100fe0590d0ac4b5c9808740c69b3045841ddb5e8c260030fadac63dd8f
|
|
| MD5 |
6d3b5ff2cd5ae4b6bf7497a4900607cc
|
|
| BLAKE2b-256 |
b092f6322c4b393d64e43411bff728849a66637caf41263a50479d2fb14f386e
|
Provenance
The following attestation bundles were made for outlabs_auth-0.1.0a26-py3-none-any.whl:
Publisher:
publish-pypi.yml on outlabsio/outlabsAuth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
outlabs_auth-0.1.0a26-py3-none-any.whl -
Subject digest:
c47e1100fe0590d0ac4b5c9808740c69b3045841ddb5e8c260030fadac63dd8f - Sigstore transparency entry: 2285436457
- Sigstore integration time:
-
Permalink:
outlabsio/outlabsAuth@0ba4065d50003e6723059dbedeb8f72980187f88 -
Branch / Tag:
refs/tags/v0.1.0a26 - Owner: https://github.com/outlabsio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@0ba4065d50003e6723059dbedeb8f72980187f88 -
Trigger Event:
push
-
Statement type: