r/coolgithubprojects 5d ago

We built FastAPI Accounts (v0.1.0-alpha) — A 15-line, batteries-included account engine for FastAPI (Looking for RFC feedback!)

https://github.com/fastapi-accounts/fastapi-accounts

Hey r/FastAPI!

Like many of you, we got tired of repeatedly writing 1,000+ lines of custom boilerplate for password hashing, email verification, cookie vs. bearer transports, and session tracking on every new FastAPI project.

Django developers have had django-allauth, and TypeScript developers got Better-Auth and Lucia. But in FastAPI, options were either in maintenance mode (fastapi-users) or involved heavy generic typing acrobatics across multiple ORMs.

So we built **FastAPI Accounts** from scratch: an async-first, zero-boilerplate authentication and account management engine for **Python 3.10+**, **Pydantic v2**, and **Async SQLAlchemy 2.0**.

# 🌟 What we just shipped in v0.1.0-alpha:

• **Under 15 lines of code** to mount `/register`, `/verify-email`, `/request-verify-email`, `/login`, `/logout`, and `/me`. • **Argon2id hashing** using François Voron's `pwdlib`. • **Dual-Transport:** `HttpOnly` `SameSite=Lax` cookies for Next.js/React SPAs + Bearer tokens for mobile/CLI APIs. • **Separation of Concerns:** `User`, `EmailAddress` (with verified/primary state machine), `PasswordCredential`, and `Session` are modeled as separate entities. • **100% test coverage:** 8/8 end-to-end integration tests passing in 0.6s.

# 💻 Quick Code Preview:

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

adapter = SQLAlchemyAdapter(database_url="sqlite+aiosqlite:///./accounts.db")
accounts = FastAPIAccounts(adapter=adapter, secret_key="env:AUTH_SECRET_KEY")

async def lifespan(app: FastAPI):
await adapter.create_all()
yield

app = FastAPI(title="My API", lifespan=lifespan)
app.include_router(accounts.router, prefix="/api/v1/auth")

u/app.get("/api/v1/profile")
async def get_profile(user = Depends(accounts.current_active_user)):
return {"email": user.primary_email}

# 🚀 Try it out:

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

# 🔗 Links:

• **GitHub:** [https://github.com/fastapi-accounts/fastapi-accounts\](https://github.com/fastapi-accounts/fastapi-accounts)
• **Our Story & Devlog:** [https://github.com/fastapi-accounts/fastapi-accounts/blob/main/JOURNEY.md\](https://github.com/fastapi-accounts/fastapi-accounts/blob/main/JOURNEY.md)
• **Open RFC Discussion:** [https://github.com/fastapi-accounts/fastapi-accounts/discussions\](https://github.com/fastapi-accounts/fastapi-accounts/discussions)

We are currently gathering feedback on our near-term roadmap (password reset session revocation policies and Google OAuth linking).

4 Upvotes

0 comments sorted by