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.
💡 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:
- Writing 1,000+ lines of custom boilerplate (Argon2 hashing, JWT/token issuance, password reset tokens, email verification, OAuth state handling) for every new project.
- Wrestling with complex generic typing and multi-file wiring in older libraries that are now in maintenance mode.
- 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
HttpOnlySameSite=Laxcookies with built-in CSRF protection. - For Mobile & CLI (iOS, Flutter, React Native, Postman):
Authorization: Bearer <token>with refresh token rotation.
- For Web & SPAs (React, Next.js, Vue, Svelte): Secure
- 📬 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 Argon2id password hashing via
- 🚀 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/registerPOST /api/v1/auth/verify-emailPOST /api/v1/auth/request-verify-emailPOST /api/v1/auth/request-password-resetPOST /api/v1/auth/reset-passwordPOST /api/v1/auth/change-passwordPOST /api/v1/auth/loginPOST /api/v1/auth/logoutGET /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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_accounts-0.1.0a3.tar.gz | 960.2 kB | Without provenance | Details for fastapi_accounts-0.1.0a3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_accounts-0.1.0a3-py3-none-any.whl | Python 3 | none | any | Details for fastapi_accounts-0.1.0a3-py3-none-any.whl |
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
|
Security for fastapi-accounts 0.1.0a3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.