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/request-password-reset
  • POST /api/v1/auth/reset-password
  • POST /api/v1/auth/change-password
  • 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 Email/Password (Argon2id), Email verification, Timed HMAC tokens, Async SQLAlchemy 2.0, Dual-transport (Cookies + Bearer), Password reset & recovery, Authenticated password change ✅ Completed
v0.2.0 (Multi-Email & DB Matrix) Secondary email addition/verification/removal, Primary email promotion, PostgreSQL & MySQL integration tests 🎯 Next Sprint
v0.3.0 (Social Accounts) Google OAuth2/OIDC integration, Safe social account linking with anti-takeover verification 📋 Planned
Future Horizons Additional OAuth providers (GitHub, Apple), Active session device management, TOTP / MFA, WebAuthn Passkeys 💡 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.0a3

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.0a3
File Size Uploaded
fastapi_accounts-0.1.0a3.tar.gz 960.2 kB Details

Built distribution (wheel)

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

Total release size: 983.6 kB

Release files / fastapi_accounts-0.1.0a3.tar.gz

Download URL fastapi_accounts-0.1.0a3.tar.gz
Size 960.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ad42d3c9ca38dc7d1b19ff07201a43883224c6580cfe22da032a3df6031e528b
BLAKE2b-256 checksum
How to use checksums
d0964f74a0a8f3877cb99482b3dbf6522da10ca40a5040d4496297115f9fca82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

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

Download URL fastapi_accounts-0.1.0a3-py3-none-any.whl
Size 23.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91911466d13370ed6fc2e3caba327bc515ff3a957f3a1866ff5b324a6e264387
BLAKE2b-256 checksum
How to use checksums
a8475191677fa724b9be43edd706267c42d395fea84e786c47319253b774b211
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5
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