FastAuth
Simple and flexible authentication library for FastAPI — FastAPI-only by design.
Session, JWT, OIDC, and plain OAuth2 strategies. One class per strategy, one config object, your own SQLAlchemy or any ORM models. Asynchronous end to end.
What it is
FastAuth is a FastAPI-native authentication library: secure defaults out of the box, pluggable underneath. One class per strategy, one FastAuthConfig for tuning, your own SQLAlchemy models for storage. Async-only core.
Why it exists
Better Auth-style developer experience didn't exist for FastAPI specifically. FastAuth is FastAPI-only on purpose — not framework-agnostic — so it can lean on FastAPI dependencies, Pydantic validation, and async end to end instead of abstracting over them.
Current state
Working now:
- Session strategy — cookie transport, server-side rows (
SessionAuth) - JWT strategy — short-lived bearer tokens + rotating refresh cookies (
JWTAuth) - OIDC login — Google-style providers with discovery doc + verified
id_token(OIDCAuth) - Plain OAuth2 login — GitHub-style providers with no discovery doc (
OAuth2Auth) - Rate limiting — in-memory (default), database, or Redis backends
- Event hooks — before/observer hooks on signup, login, logout, refresh, password reset, and OAuth logins
- Config validation — bad values fail at startup, not in production
Installation
Requires Python 3.14+ and uv.
uv add builtbyelly-fastauth
SQLAlchemy and the redis client ship in the default install — no extras. Optional dependencies for other ORMs will arrive over time as more backends land. Add an async DB driver for your database:
uv add aiosqlite # SQLite, as used in examples/
Quickstart
Define models with the mixins, build the auth instance, mount the router, protect routes with auth.current_user (from examples/basic/main.py):
from fastapi import Depends, FastAPI
from sqlalchemy import ForeignKey
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from fastauth import SessionAuth
from fastauth.adapters.sqlalchemy import SQLAlchemySessionAdapter
from fastauth.adapters.sqlalchemy.models import (
FastAuthSessionMixin,
FastAuthUserMixin,
)
class Base(DeclarativeBase): ...
class User(Base, FastAuthUserMixin):
__tablename__ = "users"
class Session(Base, FastAuthSessionMixin):
__tablename__ = "sessions"
user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("users.id"))
auth = SessionAuth(
adapter=SQLAlchemySessionAdapter,
user_model=User,
session_model=Session,
db_session_dependency=get_db, # your FastAPI dep yielding an AsyncSession
)
app = FastAPI()
app.include_router(auth.router)
@app.get("/protected")
async def protected(user=Depends(auth.current_user)):
return {"email": user.email}
That mounts POST /auth/signup, POST /auth/login, POST /auth/logout, POST /auth/forgot-password, POST /auth/reset-password, and GET /auth/me. See examples/ for full apps: basic (sessions), jwt_example (JWT + DB rate limiting), oidc (Google), oauth2 (GitHub).
Features
- Sessions —
HttpOnly/Secure/SameSitecookies, server-side expiry, rotation on login - JWT — 10-minute access tokens, single-use rotating refresh tokens, reuse detection
- OIDC — per-provider config,
stateCSRF protection, signature +iss/aud/expverification - Plain OAuth2 — explicit URLs, dev-supplied
map_profile_to_user, provider tokens handed to your hook, never persisted - Adapters — SQLAlchemy included; bring your own ORM by subclassing
Adapter - Hooks —
on_before_signup,on_after_login,on_after_oidc_login,on_after_oauth2_login, and more; before-hooks can mutate orHookAbort, observers never break the response - Rate limiting — fixed-window, per-IP + path; memory, database (row-locked), or Redis (Lua-atomic) storage
- Config — one frozen
FastAuthConfig; placeholder secrets rejected, lifetimes bounded
Docs
Full docs live in docs/ (zensical): uvx zensical serve. Start at docs/getting-started/quickstart.md. ARCHITECTURE.md covers the internals. Agents: see llms.txt (library use) and AGENTS.md (contributing).
License
MIT.
Metadata
Release files for builtbyelly-fastauth 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| builtbyelly_fastauth-0.1.0.tar.gz | 37.3 kB | Without provenance | Details for builtbyelly_fastauth-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| builtbyelly_fastauth-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for builtbyelly_fastauth-0.1.0-py3-none-any.whl |
Total release size: 97.5 kB
Release files / builtbyelly_fastauth-0.1.0.tar.gz
| Download URL | builtbyelly_fastauth-0.1.0.tar.gz |
|---|---|
| Size | 37.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
456ce68ed074de783d20fc9341622333b47d634a558f8aa1327c2a5833d2bffb
|
|
BLAKE2b-256 checksum How to use checksums |
108e7ea21cd0d3075db2de5dcc0bad54abb6a658a4263b284cd51a7e3f8da868
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / builtbyelly_fastauth-0.1.0-py3-none-any.whl
| Download URL | builtbyelly_fastauth-0.1.0-py3-none-any.whl |
|---|---|
| Size | 60.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce3ddb8e0a2ff546607d8e839e52da34f0ab8870c19fceb6ca1418accf19ac22
|
|
BLAKE2b-256 checksum How to use checksums |
0837d89226a3f162c5509cbbc3f78fae8ecc9631332358cac96e3319938323f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for builtbyelly-fastauth 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.