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.3.1.tar.gz (31.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.3.1-py3-none-any.whl (49.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sreekarnv_fastauth-0.3.1.tar.gz
  • Upload date:
  • Size: 31.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.3.1.tar.gz
Algorithm Hash digest
SHA256 7f5a2c717ebb4ad84e51cc157f5c0aba9c8a0e8a01847e1250a32aa97de21933
MD5 78809a8267c576f5d2e4331fd8581b52
BLAKE2b-256 c9e322ecbffd19565a876ca78adf138fd348ca99c1d2fe6bad12656ef5e16cb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sreekarnv_fastauth-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 49.8 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1293f53497b38e5c185554945f53ff73af35a9af67b10a209d452f39dc2475da
MD5 3ebe14b9c023e734f29002c90f0b1fe5
BLAKE2b-256 9dfddc1e60d8521d43cc5cfea1f9438d324aa0298a79f7d80af72e5b78ad7685

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