Production-ready authentication for FastAPI applications
FastAuth is a flexible, database-agnostic authentication library for FastAPI that provides secure user authentication, session management, and authorization out of the box.
- Complete Authentication - Registration, login, logout, token refresh
- Role-Based Access Control - Fine-grained permissions and roles
- Session Management - Multi-device session tracking
- OAuth Support - Social login (Google, GitHub, etc.)
- Email Verification - Secure email verification with tokens
- Password Reset - Self-service password reset
- Database Agnostic - Works with any database via adapters
- Type Safe - Full type hints and validation
pip install sreekarnv-fastauthNote: FastAPI is a peer dependency - your project must have FastAPI installed.
For OAuth providers (Google, GitHub, etc.):
pip install sreekarnv-fastauth[oauth]from fastapi import Depends, FastAPI
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from fastauth.api.auth import router as auth_router
from fastauth.security.jwt import decode_access_token
app = FastAPI()
app.include_router(auth_router)
security = HTTPBearer()
@app.get("/protected")
def protected(credentials: HTTPAuthorizationCredentials = Depends(security)):
payload = decode_access_token(credentials.credentials)
return {"user_id": payload["sub"]}uvicorn main:app --reloadVisit http://localhost:8000/docs to see the auto-generated API documentation.
- Getting Started - Install and setup in 5 minutes
- Guides - Authentication, RBAC, sessions, OAuth
- API Reference - Complete API documentation
- Examples - Working example applications
Check out complete working examples:
- OAuth with Google - Social login with PKCE
- RBAC Blog - Role-based access control
- Session Management - Multi-device tracking
- Basic App - Simple authentication
FastAuth follows security best practices:
- ✅ Argon2 password hashing (OWASP recommended)
- ✅ JWT tokens with configurable expiration
- ✅ Rate limiting for authentication endpoints
- ✅ Refresh token rotation
- ✅ Session tracking and revocation
┌─────────────────────────────────────┐
│ Your FastAPI App │
├─────────────────────────────────────┤
│ FastAuth API Layer │
├─────────────────────────────────────┤
│ Core Business Logic │ ← Database-agnostic
├─────────────────────────────────────┤
│ Adapter Interface │
├─────────────────────────────────────┤
│ Database Implementation │ ← SQLAlchemy, MongoDB, etc.
└─────────────────────────────────────┘
Key Principles:
- Database-agnostic core
- Adapter pattern for flexibility
- Dependency injection
- Full type safety
Contributions are welcome! See CONTRIBUTING.md for guidelines.
# Setup development environment
git clone https://github.com/sreekarnv/fastauth.git
cd fastauth
poetry install
poetry run pytestMIT License - see LICENSE for details.
Built with FastAPI, SQLModel, Argon2, and python-jose.
⭐ Star this repo if you find it useful!
Made with ❤️ by Sreekar Nutulapati