Skip to main content

FAuth

An ergonomic, plug-and-play authentication library for FastAPI.

fauth eliminates boilerplate around JWT, password hashing, user fetching, and Role-Based Access Control (RBAC) by leveraging FastAPI's Dependency Injection (Depends), Pydantic models, and Python Protocols.

Dependabot Updates PyPI version Python versions License: MIT

Features

  • Protocol-Based User Fetching — Complete inversion of control via UserLoader and IdentityLoader protocols.
  • Plug-and-Play Configuration — Centralized settings via Pydantic (AuthConfig). Configure once, inject everywhere.
  • Pluggable Transports — Extensible Transport protocol with a built-in BearerTransport.
  • Automatic OpenAPI/Swagger UI Support — Integrated security schemes with "Authorize" button in Swagger UI.
  • Built-in Password Hashing & JWT Crypto — Argon2 via pwdlib and utilities for creating/decoding access and refresh tokens.
  • RBAC — require_roles and require_permissions dependencies with customizable user model field names.
  • Secure Router — SecureAPIRouter secures all its routes automatically.
  • Structured Logging — Built-in structlog-based logging.
  • Type Safe — Fully annotated for MyPy and IDE integration.

Installation

pip install fauth

Or with uv:

uv add fauth

Quick Start

from pydantic import BaseModel
from fastapi import FastAPI, Depends
from fauth import AuthConfig, AuthProvider, TokenPayload, hash_password


class User(BaseModel):
    id: str
    username: str
    hashed_password: str
    is_active: bool = True
    roles: list[str] = []
    permissions: list[str] = []


DB: dict[str, User] = {
    "user-123": User(
        id="user-123",
        username="alice",
        hashed_password=hash_password("s3cret"),
        roles=["admin"],
    ),
}


async def load_user(payload: TokenPayload) -> User | None:
    return DB.get(payload.sub)


async def load_identity(identifier: str) -> User | None:
    return next((u for u in DB.values() if u.username == identifier), None)


config = AuthConfig(secret_key="my-super-secret-key")
auth: AuthProvider[User] = AuthProvider(
    config=config, user_loader=load_user, identity_loader=load_identity
)

app = FastAPI()


@app.post("/login")
async def login(username: str, password: str):
    user = await auth.authenticate(username, password)
    return await auth.login(sub=user.id)


@app.get("/me")
async def get_me(user: User = Depends(auth.require_user)):
    return {"message": f"Hello {user.username}"}

📖 Full documentation at fauth.readthedocs.io

License

MIT

Metadata

Release files for fauth 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fauth 3.0.0
File Size Uploaded Provenance Actions
fauth-3.0.0.tar.gz 100.9 kB With provenance Details for fauth-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fauth 3.0.0
File Interpreter ABI Platform Actions
fauth-3.0.0-py3-none-any.whl Python 3 none any Details for fauth-3.0.0-py3-none-any.whl

Total release size: 116.3 kB

Release files / fauth-3.0.0.tar.gz

Download URL fauth-3.0.0.tar.gz
Size 100.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4163866d25b5485e99ccc96ff1b5967f470fcbd0039cb1aa12f2393ff31744a4
BLAKE2b-256 checksum
How to use checksums
92c41f955ee81e5918e5a9ab9bc562bb5f746afbbf15b77bf7d9d31ee36b2dc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release files / fauth-3.0.0-py3-none-any.whl

Download URL fauth-3.0.0-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36505dee1fc07d5cf87b2d0b86a759b6e8e73b2a7959082de1e2028fd9950bbc
BLAKE2b-256 checksum
How to use checksums
89e2eec400831c65c2602e2c74edf2e6942733715f90ae50e0533cfeee96c7d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Security for fauth 3.0.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fauth-3.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page