AuthFast
A tiny authentication toolkit for FastAPI.
AuthFast gives FastAPI apps a simple way to add authentication without building the same routes, sessions, and database setup from scratch.
Install
pip install authfast
Default install supports SQLite. For production databases, install the matching driver extra:
pip install "authfast[postgres]"
pip install "authfast[mysql]"
pip install "authfast[all]"
Supported database targets:
- SQLite:
sqlite:///./app.dborsqlite+aiosqlite:///./app.db - PostgreSQL, Neon, Supabase Postgres:
postgresql://...orpostgresql+asyncpg://... - MySQL/MariaDB:
mysql://...ormysql+asyncmy://...
Create auth.py
Create .env next to auth.py:
AUTHFAST_SECRET_KEY=change-this-secret-for-local-development
from authfast import AuthFast
auth = AuthFast(
database="sqlite:///./app.db",
email_and_password={
"enabled": True,
},
)
Set Up The Database
authfast setup
The CLI looks for auth.py in ./, ./app, ./lib, ./src, ./src/app, and ./src/lib.
For SQLite, the relative database path is resolved from the directory where you run the command or server. Run authfast setup and uvicorn from the same project root.
Use a custom path:
authfast setup --config examples/basic/auth.py
Drop and recreate AuthFast tables:
authfast setup --force
Mount Routes
from fastapi import FastAPI
from auth import auth
app = FastAPI()
app.include_router(auth.router)
@app.get("/protected")
async def protected(user=auth.user()):
return {"id": user.id, "name": user.name, "email": user.email}
Use The API
Sign up:
curl -X POST http://127.0.0.1:8000/auth/sign-up/email \
-H "Content-Type: application/json" \
-d '{"name":"Dev","email":"dev@example.com","password":"secret123"}'
Log in:
curl -X POST http://127.0.0.1:8000/auth/sign-in/email \
-H "Content-Type: application/json" \
-d '{"email":"dev@example.com","password":"secret123"}'
Use the session cookie or returned bearer token:
curl http://127.0.0.1:8000/auth/me \
-H "Authorization: Bearer <access_token>"
Routes
POST /auth/sign-up/emailPOST /auth/sign-in/emailPOST /auth/sign-outPOST /auth/signupPOST /auth/loginPOST /auth/logoutGET /auth/meGET /auth/session
Example
From the project root:
authfast setup --config examples/basic/auth.py
uvicorn examples.basic.main:app --reload
Or from inside examples/basic:
authfast setup --config auth.py
uvicorn main:app --reload
Keep setup and uvicorn in the same working directory when using the example SQLite URL, because ./app.db is resolved from the current directory.
Reference
Metadata
Release files for authfast 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| authfast-0.1.0.tar.gz | 49.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| authfast-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 64.1 kB
Release files / authfast-0.1.0.tar.gz
| Download URL | authfast-0.1.0.tar.gz |
|---|---|
| Size | 49.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6fffcc64ea30db54af77f781c9b25c3d86138445d2ad39b33e9ab60f2f26409
|
|
BLAKE2b-256 checksum How to use checksums |
ae0cf176fba8b4005198efa97c9e61e762b9fe638d625db8f176829f6290c249
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|
Release files / authfast-0.1.0-py3-none-any.whl
| Download URL | authfast-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79dd402a98c0777847a3cf4534c091b596f4078abd998ede8518e11bc4cadf3f
|
|
BLAKE2b-256 checksum How to use checksums |
7a4962f069241e87ba37c3c9d7520d7abf24b6b0a933d089553acced8f4d9ae3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.14
|