Skip to main content

NextAuth-inspired pluggable authentication for FastAPI

Project description

FastAuth

PyPI License: MIT CI codecov Python 3.11+

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sreekarnv_fastauth-0.4.0.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sreekarnv_fastauth-0.4.0-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

File details

Details for the file sreekarnv_fastauth-0.4.0.tar.gz.

File metadata

  • Download URL: sreekarnv_fastauth-0.4.0.tar.gz
  • Upload date:
  • Size: 34.9 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

Hashes for sreekarnv_fastauth-0.4.0.tar.gz
Algorithm Hash digest
SHA256 147dd5686f5879a0cde0c069bed44d406811634380075fd0fceb36199b02735b
MD5 fae3e5caca2f6b7669016a7f6349d35b
BLAKE2b-256 a3d69d70b214f88e243eb0949e691dccf3c974f64e00a9fa32672361151a791f

See more details on using hashes here.

File details

Details for the file sreekarnv_fastauth-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: sreekarnv_fastauth-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 54.7 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

Hashes for sreekarnv_fastauth-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b103725d32f01b5753161853102600f97449626b223886f4a28be872befe6df3
MD5 d5b421362793e28af0cb778865e1ef1a
BLAKE2b-256 ffcc174168e5c3e80d2b1d168762eff673166747930b1ccc77af79919255297c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page