Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

FastAPI Accounts ⚡

Modern, zero-boilerplate authentication and complete account management for FastAPI.

PyPI License FastAPI Pydantic v2 Python 3.10+ Discussions


💡 The Vision

Django developers have django-allauth.
TypeScript developers have Better-Auth and Lucia.
FastAPI developers deserve a modern, batteries-included authentication and account management engine.

Today, building authentication in FastAPI usually means either:

  1. Writing 1,000+ lines of custom boilerplate (Argon2 hashing, JWT/token issuance, password reset tokens, email verification, OAuth state handling) for every new project.
  2. Wrestling with complex generic typing and multi-file wiring in older libraries that are now in maintenance mode.
  3. Paying steep monthly fees to vendor-locked cloud auth providers (Clerk, Auth0).

FastAPI Accounts solves this: an async-first, zero-boilerplate authentication and account management engine built natively for FastAPI, Pydantic v2, and Async SQLAlchemy 2.0.

📖 Read our full story: The Journey of FastAPI Accounts (JOURNEY.md).


✨ Key Features

  • ⚡ 15-Line Setup: Complete authentication system mounted with a single router and sensible defaults.
  • 🍪 Native Dual-Transport:
    • For Web & SPAs (React, Next.js, Vue, Svelte): Secure HttpOnly SameSite=Lax cookies with built-in CSRF protection.
    • For Mobile & CLI (iOS, Flutter, React Native, Postman): Authorization: Bearer <token> with refresh token rotation.
  • 📬 Real-World Account Management:
    • Multiple email addresses per account (Primary + Verified state machine, just like GitHub).
    • Secure, stateless cryptographic email verification workflows (/verify-email & /request-verify-email).
  • 🛡️ Modern Security Primitives:
    • Modern Argon2id password hashing via pwdlib.
    • Active session tracking (view devices/IPs, "Logout everywhere").
  • 🚀 Modern Python Native:
    • Built exclusively for Python 3.10+, Pydantic v2, and Async SQLAlchemy 2.0.
    • Ready-to-use model mixins that plug directly into your existing Alembic migrations.

🚀 Quickstart (15 Lines of Code)

1. Installation

pip install fastapi-accounts --pre
# or with uv:
uv add fastapi-accounts --prerelease=allow

2. Basic Application (app.py)

from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI
from fastapi_accounts import FastAPIAccounts, SQLAlchemyAdapter

# 1. Initialize the adapter and account engine
adapter = SQLAlchemyAdapter(database_url="sqlite+aiosqlite:///./accounts.db")
accounts = FastAPIAccounts(adapter=adapter, secret_key="super-secret-key-change-me")

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Automatically create database tables on startup (for quickstarts/dev)
    await adapter.create_all()
    yield

# 2. Mount all auth & account endpoints in one line
app = FastAPI(title="My API", lifespan=lifespan)
app.include_router(accounts.router, prefix="/api/v1/auth", tags=["Auth"])

# 3. Protect any endpoint with clean dependency injection
@app.get("/api/v1/profile")
async def get_profile(user = Depends(accounts.current_active_user)):
    return {"message": f"Welcome back, {user.primary_email}!", "user_id": user.id}

Run your app:

uvicorn app:app --reload

Visit http://localhost:8000/docs to see your fully documented authentication endpoints:

  • POST /api/v1/auth/register
  • POST /api/v1/auth/verify-email
  • POST /api/v1/auth/request-verify-email
  • POST /api/v1/auth/login
  • POST /api/v1/auth/logout
  • GET /api/v1/auth/me

🗺️ Roadmap & Milestones

Milestone Target Capabilities Status
v0.1.0-alpha (Shipped) Email/Password (Argon2id), Email verification, Resend verification, Multi-email models, Async SQLAlchemy 2.0 adapter, Dual-transport (Cookies + Bearer) ✅ Completed
v0.1.x (Core Hardening) Password reset/recovery workflows, Multi-email addition/removal, Primary email changes, PostgreSQL integration tests 🏗️ In Progress
v0.2.0 (Social Accounts) Google OAuth2/OIDC integration, Safe social account linking with anti-takeover checks 📋 Planned
Future Horizons Additional OAuth providers (GitHub, Apple), Active session device management, TOTP / MFA 💡 Under RFC

🧪 Running Tests

FastAPI Accounts comes with an automated test suite:

# Clone the repository
git clone https://github.com/fastapi-accounts/fastapi-accounts.git
cd fastapi-accounts

# Run tests with uv
uv run --all-extras pytest

💬 Join the Community & RFC

We are actively designing the OAuth linking and Passkey architecture:

  • 💡 Have feedback or ideas? Join our GitHub Discussions.
  • 🐛 Found a bug or missing feature? Open an Issue.
  • ⭐ Support the project: Star this repository on GitHub!

📄 License

FastAPI Accounts is open-source software licensed under the Apache License 2.0.

Metadata

Release files for fastapi-accounts 0.1.0a1

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

Source distribution (sdist)

Source distribution for fastapi-accounts 0.1.0a1
File Size Uploaded
fastapi_accounts-0.1.0a1.tar.gz 952.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-accounts 0.1.0a1
File Interpreter ABI Platform
fastapi_accounts-0.1.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 974.0 kB

Release files / fastapi_accounts-0.1.0a1.tar.gz

Download URL fastapi_accounts-0.1.0a1.tar.gz
Size 952.4 kB
Tags Source
SHA-256 checksum
How to use checksums
de2cba6cec7fe56709b86fcc71484beb3b628a0133aa3e4702e829e2fd97c3f9
BLAKE2b-256 checksum
How to use checksums
7db26b315367fd556b2cfd810ba82f898775cd84b6fad9f60fb80a74b2a8e3f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fastapi_accounts-0.1.0a1-py3-none-any.whl

Download URL fastapi_accounts-0.1.0a1-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6b5e39c0ffe4f68daf07eff07d069fc4d01fbedff5c1b547a4ebb155d9e07e1
BLAKE2b-256 checksum
How to use checksums
2ee4153b5c1d4b02d3a3334d857ce14d88a1bd2ba170554c7d85732d8e26ed3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
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