Why AuthX?
AuthX takes the complexity out of implementing authentication in your FastAPI projects:- Ready to use - Get started with just a few lines of code
- Customizable - Configure every aspect of JWT handling to fit your needs
- Secure by default - Built-in CSRF protection, token freshness, and best practices
- Type safe - Full type hints and Pydantic 2 support
- FastAPI native - Designed specifically for FastAPI’s dependency injection system
Features
Core authentication
- JWT tokens - Industry-standard JSON Web Tokens for stateless authentication
- Access and refresh tokens - Keep users logged in with automatic token rotation
- Token freshness - Require re-authentication for sensitive operations
- Token blocklist - Revoke tokens when needed (logout, security incidents)
- Multiple token locations - Headers, cookies, query parameters, or JSON body
Security features
- CSRF protection - Automatic CSRF token generation for cookie-based auth
- Scope-based authorization - Fine-grained permissions with hierarchical scopes
- Configurable algorithms - Support for HS256, RS256, and other JWT algorithms
- Token verification - Comprehensive validation of claims, expiry, and signatures
Developer experience
- FastAPI dependencies - Protect routes with simple
Depends()decorators - Error handling - Automatic conversion of auth errors to proper HTTP responses
- Type hints - Full IDE autocomplete and type checking
- Extensible - Callbacks for custom user loading and token validation
Quick example
Here’s a complete authentication system in under 30 lines:Extra features
Installauthx-extra for additional production features:
- Redis session store - Distributed session management and caching
- HTTP caching - Response caching with cache control headers
- Performance profiling - Built-in profiler using pyinstrument
- Prometheus metrics - Track authentication events and performance
Requirements
- Python 3.9+
- FastAPI 0.68+
- Pydantic 2.0+
Next steps
Installation
Install AuthX and verify your setup
Quickstart
Build your first authenticated API in 5 minutes