NextAuth-inspired pluggable authentication for FastAPI
Project description
FastAuth
NextAuth-inspired pluggable authentication for FastAPI.
FastAuth gives you a complete auth system — credentials, OAuth, email verification, password reset, RBAC, and JWT — without locking you into any particular database or ORM.
Features
- Multiple providers — email/password, Google OAuth, GitHub OAuth
- Pluggable adapters — SQLAlchemy (SQLite, PostgreSQL, MySQL) or bring your own
- JWT & database sessions — stateless tokens or server-side sessions
- Cookie delivery — HttpOnly, Secure, SameSite out of the box
- Email flows — verification and password reset with customizable transports
- RBAC — roles and fine-grained permissions on any route
- Event hooks — intercept sign-in/sign-up and modify JWT payloads
- RS256 / JWKS — rotate keys and expose a JWKS endpoint for microservices
- CLI — scaffold a project, check dependencies, generate secrets
Install
pip install "sreekarnv-fastauth[standard]"
| Extra | Includes |
|---|---|
standard |
FastAPI, JWT (joserfc), SQLAlchemy, Argon2 |
oauth |
httpx (Google, GitHub OAuth) |
email |
aiosmtplib, Jinja2 |
redis |
redis-py async |
postgresql |
asyncpg |
cli |
typer, rich |
all |
everything |
Quick start
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI
from fastauth import FastAuth, FastAuthConfig
from fastauth.adapters.sqlalchemy import SQLAlchemyAdapter
from fastauth.api.deps import require_auth
from fastauth.providers.credentials import CredentialsProvider
adapter = SQLAlchemyAdapter(engine_url="sqlite+aiosqlite:///./auth.db")
auth = FastAuth(FastAuthConfig(
secret="change-me", # fastauth generate-secret
providers=[CredentialsProvider()],
adapter=adapter.user,
token_adapter=adapter.token,
))
@asynccontextmanager
async def lifespan(app: FastAPI):
await adapter.create_tables()
yield
app = FastAPI(lifespan=lifespan)
auth.mount(app) # registers /auth/signup, /auth/signin, /auth/signout, …
@app.get("/dashboard")
async def dashboard(user=Depends(require_auth)):
return {"hello": user["email"]}
uvicorn main:app --reload
Documentation
Full documentation at sreekarnv.github.io/fastauth
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
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 sreekarnv_fastauth-0.3.0.tar.gz.
File metadata
- Download URL: sreekarnv_fastauth-0.3.0.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a908e5c8c30a23cc2344f37db22003d647fbbbc8582f19ed77dfac856d3759ad
|
|
| MD5 |
e74d6ef2dd3b246a243e628d7e464f73
|
|
| BLAKE2b-256 |
c3a09a939496f70e5722eabfeaa513cec0ef4e75ddaaf74d0d9eaf05d79deb03
|
File details
Details for the file sreekarnv_fastauth-0.3.0-py3-none-any.whl.
File metadata
- Download URL: sreekarnv_fastauth-0.3.0-py3-none-any.whl
- Upload date:
- Size: 49.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e99bfbb734569cc3cd3ccc8bdf183284421b48bc80f11ac44efa0795d81fcf3
|
|
| MD5 |
711e6ef6723bdf4c2af2b713ae8c046a
|
|
| BLAKE2b-256 |
6f5f664b77cdca4f22f83835cef1b36a7b17cf2d71dcc1dc8a1b7d0f429d1168
|