Skip to main content

Ready to use and customizable Authentications and Oauth2 management for FastAPI

Project description

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: https://github.com/yezz123/authx

Documentation: https://authx.yezz.me/


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(
    JWT_SECRET_KEY="your-secret-key",  # Change this!
    JWT_TOKEN_LOCATION=["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.create_access_token(uid=username)
        return {"access_token": token}
    raise HTTPException(401, detail="Invalid credentials")

@app.get("/protected", dependencies=[Depends(auth.access_token_required)])
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.

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

authx-1.7.1.tar.gz (96.8 kB view details)

Uploaded Source

Built Distribution

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

authx-1.7.1-py3-none-any.whl (44.5 kB view details)

Uploaded Python 3

File details

Details for the file authx-1.7.1.tar.gz.

File metadata

  • Download URL: authx-1.7.1.tar.gz
  • Upload date:
  • Size: 96.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for authx-1.7.1.tar.gz
Algorithm Hash digest
SHA256 6b52c75096b9459be91058720833d09886a58b2b7d87f85624e1fef7ae358686
MD5 8f1aee6eb0250b1f850b9ac111d49fab
BLAKE2b-256 48def8dbcc5dae9c9be4f6145a3ff69250b2540c2c55e360cb48e28bf47cebc3

See more details on using hashes here.

Provenance

The following attestation bundles were made for authx-1.7.1.tar.gz:

Publisher: release.yml on yezz123/authx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file authx-1.7.1-py3-none-any.whl.

File metadata

  • Download URL: authx-1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 44.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for authx-1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d28896ff78865d724eef21a704b2cfa28da5beaf411c6e3893fac35f1df4a26b
MD5 321472b5c52586d11b0b0ab83c0604c9
BLAKE2b-256 7ee8bc92951b01e0ccf3e3c447bc274f19725a3bc4042fdd87ce515a8841d71f

See more details on using hashes here.

Provenance

The following attestation bundles were made for authx-1.7.1-py3-none-any.whl:

Publisher: release.yml on yezz123/authx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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