py-auth-fastapi
FastAPI integration for py-auth-core.
Removes the boilerplate of wiring py-auth-core authentication into a FastAPI application down to a single line.
Features
- ✅ One-liner setup — Mounts as a standard FastAPI
APIRouterwithapp.include_router() - ✅ Automatic cookie handling — Sets and clears session and CSRF cookies automatically
- ✅ Dependency injection — Includes
get_current_session()dependency factory for protecting endpoints - ✅ Built-in error handling — Converts
py-auth-coreerrors into standard FastAPIHTTPExceptionresponses
Installation
pip install py-auth-fastapi
Quick Start
from fastapi import FastAPI, Depends
from py_auth import PyAuth
from py_auth_fastapi import PyAuthFastAPI
# Initialize your PyAuth instance
auth = PyAuth(...)
app = FastAPI()
# Mount auth router (prefix="/auth" and tags=["Authentication"] by default)
auth_router = PyAuthFastAPI(auth)
app.include_router(auth_router)
# Protect routes using the session dependency
@app.get("/protected")
async def protected_route(session=Depends(auth_router.get_current_session())):
return {"message": f"Hello user {session['user_id']}"}
Endpoints Registered
POST /auth/signin— Authenticates credentials and sets session & CSRF cookiesPOST /auth/signout— Revokes session and deletes cookiesGET /auth/session— Fetches current session and rotates CSRF token
License
Release files for py-auth-fastapi 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_auth_fastapi-0.0.1.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_auth_fastapi-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / py_auth_fastapi-0.0.1.tar.gz
| Download URL | py_auth_fastapi-0.0.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7da0d03b3c6b72e6416b8e370e840cf4190bcd780522dc30e7e694ad03b6765a
|
|
BLAKE2b-256 checksum How to use checksums |
1f7acb4947f094186fd5df978685d588fd4a1fff82025431e3017b640cf9c06c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / py_auth_fastapi-0.0.1-py3-none-any.whl
| Download URL | py_auth_fastapi-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf4c43e78faabd7ab54ab40b2820d72d5d556f3ff5e7427179eba1478572b875
|
|
BLAKE2b-256 checksum How to use checksums |
3afb7e957e86256a251f82be758c6a27c9c93954a2b3a0e2387741e1dc271378
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|