Skip to content

Better Auth for PythonAuthentication for Python, at parity.

A server-side port of Better Auth. Same routes, same JSON shapes, same error codes, same database โ€” so a Python service and a TypeScript one are interchangeable on one schema.

Twenty lines is a working auth server โ€‹

Sign-up, sign-in, sessions, sign-out, password reset, email verification and social login, mounted under /api/auth.

python
from better_auth import BetterAuth, EmailAndPassword
from better_auth.integrations.fastapi import BetterAuthFastAPI
from fastapi import Depends, FastAPI

auth = BetterAuth(
    secret="...",  # openssl rand -base64 32
    base_url="http://localhost:8000",
    email_and_password=EmailAndPassword(enabled=True),
)

app = FastAPI()
ba = BetterAuthFastAPI(auth)
app.include_router(ba.router)  # mounts /api/auth/*

@app.get("/me")
async def me(result: dict = Depends(ba.require_session)):
    return result["user"]
bash
uv add better-auth-server[fastapi,sqlalchemy]

The core is framework-agnostic, and FastAPI, Litestar, Flask and Django integrations ship in the box โ€” each a thin layer over plain request/response dataclasses. There is a client too: better-auth-client talks to any Better Auth server from Python, sync or async. Start here.

MIT licensed ยท API-compatible with better-auth