Skip to main content

Production-ready authentication for FastAPI applications

Project description

FastAuth

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.

CI codecov Python Version License: MIT

โœจ Features

  • 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

๐Ÿš€ Quick Start

Install

pip install sreekarnv-fastauth

Note: FastAPI is a peer dependency - your project must have FastAPI installed.

For OAuth providers (Google, GitHub, etc.):

pip install sreekarnv-fastauth[oauth]

Create Your App

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"]}

Run

uvicorn main:app --reload

Visit http://localhost:8000/docs to see the auto-generated API documentation.

๐Ÿ“š Documentation

๐Ÿ’ก Examples

Check out complete working examples:

๐Ÿ”’ Security

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

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         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

๐Ÿค Contributing

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 pytest

๐Ÿ“„ License

MIT License - see LICENSE for details.

๐Ÿ™ Acknowledgments

Built with FastAPI, SQLModel, Argon2, and python-jose.


โญ Star this repo if you find it useful!

Made with โค๏ธ by Sreekar Nutulapati

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sreekarnv_fastauth-0.2.5.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sreekarnv_fastauth-0.2.5-py3-none-any.whl (63.4 kB view details)

Uploaded Python 3

File details

Details for the file sreekarnv_fastauth-0.2.5.tar.gz.

File metadata

  • Download URL: sreekarnv_fastauth-0.2.5.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.2 Windows/11

File hashes

Hashes for sreekarnv_fastauth-0.2.5.tar.gz
Algorithm Hash digest
SHA256 ed201da0049de2b9ba8be5574a8c93219f3683e741fbdaaafb6477802bc8535a
MD5 a8b544a47eef1d45194045a83bdac3fd
BLAKE2b-256 caedf4869165422765b78edad47ca62c067d6326d9076611c72be4fb14f6c587

See more details on using hashes here.

File details

Details for the file sreekarnv_fastauth-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sreekarnv_fastauth-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b04abfd17c43c5e36c54c4652a7c160ac588cfc23d6e01ada0bc42fa4e90b3
MD5 001e888bdd8f0a29e790e70074d4e8c9
BLAKE2b-256 acc7ef62e5932262afaed7f6c2d1aab902cc2ff4e995204c5a65cb96140fc39f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page