yezz123
authx
Python

Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ✨

Last updated Aug 8, 2026
1.2k
Stars
62
Forks
3
Issues
0
Stars/day
Attention Score
73
Language breakdown
Python 99.6%
Shell 0.4%
Files click to expand
README

AuthX

AuthX

Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ⚡


| Project | Status | |---------|--------| | CI | CI pre-commit.ci status Codecov | | Meta | Package version Downloads Pydantic Version 2 Ruff Quality Gate Status |


Source Code:

Documentation:


Add a fully featured authentication and authorization system to your FastAPI project. AuthX is designed to be simple, customizable, and secure.

Installation

pip install authx

Quick Start

from fastapi import FastAPI, Depends, HTTPException
from authx import AuthX, AuthXConfig

app = FastAPI()

config = AuthXConfig( JWTSECRETKEY="your-secret-key", # Change this! JWTTOKENLOCATION=["headers"], )

auth = AuthX(config=config) auth.handle_errors(app)

@app.post("/login") def login(username: str, password: str): if username == "test" and password == "test": token = auth.createaccesstoken(uid=username) return {"access_token": token} raise HTTPException(401, detail="Invalid credentials")

@app.get("/protected", dependencies=[Depends(auth.accesstokenrequired)]) def protected(): return {"message": "Hello World"}

Test it:

# Get a token
curl -X POST "http://localhost:8000/login?username=test&password=test"

Access protected route

curl -H "Authorization: Bearer <your-token>" http://localhost:8000/protected

Features

  • Support for Python 3.9+ and Pydantic 2
  • JWT authentication with multiple token locations:
- Headers (Bearer token) - Cookies (with CSRF protection) - Query parameters - JSON body
  • Access and refresh token support
  • Token freshness for sensitive operations
  • Token blocklist/revocation
  • Built-in AuthManager for isolated multi-login-type applications
  • Pluggable policy engine for scopes, attributes, environment checks, and custom evaluators
  • Extensible error handling

Extra Features

Install authx-extra for additional features:

pip install authx-extra
  • Redis session store and cache
  • HTTP caching
  • Performance profiling with pyinstrument
  • Prometheus metrics
Note: Check Release Notes.

Contributors and Sponsors

All Contributors

Thanks goes to these wonderful people (emoji key):

Yasser Tahiri
Yasser Tahiri

💻 📖 🚧 🚇
Abderrahim SOUBAI-ELIDRISI
Abderrahim SOUBAI-ELIDRISI

👀 📖
Ismail Ghallou
Ismail Ghallou

💻 🛡️
MojixCoder
MojixCoder

💻 🐛
Stéphane Raimbault
Stéphane Raimbault

💻 🔌
theoohoho
theoohoho

📖
Yogesh Upadhyay
Yogesh Upadhyay

🐛
Roman
Roman

🐛
Alvaro Lopez Ortega
Alvaro Lopez Ortega

📖
Devy Santo
Devy Santo

🚇
pg365
pg365

🚇
Jorrit
Jorrit

📦
Callam
Callam

💻
Maxim
Maxim

💻
Suyog Shimpi
Suyog Shimpi

💻
NeViNez
NeViNez

🐛
Antareske
Antareske

💻
YuexiaW
YuexiaW

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is licensed under the terms of the MIT License.

© 2026 GitRepoTrend · yezz123/authx · Updated daily from GitHub