Ready to use and customizable Authentications and Oauth2 management for FastAPI
Project description
AuthX
Ready-to-use and customizable Authentications and Oauth2 management for FastAPI ⚡
| Project | Status |
|---|---|
| CI | |
| Meta |
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
- 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
Thanks goes to these wonderful people (emoji key):
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file authx-1.5.0.tar.gz.
File metadata
- Download URL: authx-1.5.0.tar.gz
- Upload date:
- Size: 67.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f41e410881af83319cd248784a1a79bea363c6ca17aa3070dd1654b99f43d16
|
|
| MD5 |
7ea40167e7d5aa87069beece47448e6a
|
|
| BLAKE2b-256 |
83a78387de7e4d86808c2e2a57a1c9cd27b19e372b78daa70309a10f3645d82c
|
Provenance
The following attestation bundles were made for authx-1.5.0.tar.gz:
Publisher:
release.yml on yezz123/authx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
authx-1.5.0.tar.gz -
Subject digest:
9f41e410881af83319cd248784a1a79bea363c6ca17aa3070dd1654b99f43d16 - Sigstore transparency entry: 790703562
- Sigstore integration time:
-
Permalink:
yezz123/authx@d3dcf450482ddac1b0741b06671e53e1d87a53be -
Branch / Tag:
refs/tags/1.5.0 - Owner: https://github.com/yezz123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d3dcf450482ddac1b0741b06671e53e1d87a53be -
Trigger Event:
release
-
Statement type:
File details
Details for the file authx-1.5.0-py3-none-any.whl.
File metadata
- Download URL: authx-1.5.0-py3-none-any.whl
- Upload date:
- Size: 31.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e8237c32e594c7cbdfa03e1d548c00668d2fe7526ff9a56d99f6b51c9accf0f
|
|
| MD5 |
076116e686135201ac8316ae920b036a
|
|
| BLAKE2b-256 |
2c73688fcce86edc13f055103594f783a2c41473be648236635ec8de71f37625
|
Provenance
The following attestation bundles were made for authx-1.5.0-py3-none-any.whl:
Publisher:
release.yml on yezz123/authx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
authx-1.5.0-py3-none-any.whl -
Subject digest:
2e8237c32e594c7cbdfa03e1d548c00668d2fe7526ff9a56d99f6b51c9accf0f - Sigstore transparency entry: 790703565
- Sigstore integration time:
-
Permalink:
yezz123/authx@d3dcf450482ddac1b0741b06671e53e1d87a53be -
Branch / Tag:
refs/tags/1.5.0 - Owner: https://github.com/yezz123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d3dcf450482ddac1b0741b06671e53e1d87a53be -
Trigger Event:
release
-
Statement type: