FastAPI production toolkit: Redis rate limiting, JWT auth, RBAC, audit logs to DB, OpenTelemetry middleware.
Project description
fastapi-xkit
FastAPI-XKit is a production toolkit for FastAPI.
Features (v0.2.0)
- Redis rate limiter backend
- JWT authentication dependency
- RBAC (role-based access control) dependency
- Audit logs written to SQL database (SQLAlchemy)
- OpenTelemetry ASGI instrumentation + OTLP exporter
- Request-ID middleware
/healthendpoint
Install
pip install fastapi-xkit
Quick Example
from fastapi import FastAPI, Depends
from fastapixkit import FastAPIXKitConfig, setup_fastapixkit
from fastapixkit.security.jwt import require_jwt_user
from fastapixkit.security.rbac import require_role
app = FastAPI()
config = FastAPIXKitConfig(
jwt_secret="supersecret",
redis_url="redis://localhost:6379/0",
audit_db_url="sqlite:///./audit.db",
otel_enabled=False,
)
setup_fastapixkit(app, config)
@app.get("/secure")
def secure(user=Depends(require_jwt_user(config))):
return {"user": user}
@app.get("/admin")
def admin(user=Depends(require_role(config, "admin"))):
return {"ok": True, "admin": user}
JWT payload format
Expected fields:
sub(user id)roles(list of strings)
Example:
{"sub":"123","roles":["admin","user"]}
OpenTelemetry
If otel_enabled=True, the middleware exports traces to OTLP endpoint.
Default OTLP endpoint: http://localhost:4318
Rate limiting
Redis counter per IP per minute.
License
MIT
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 fastapi_xkit-2.0.2.tar.gz.
File metadata
- Download URL: fastapi_xkit-2.0.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b66a6b1e423080c0bb78d562fa6ae26c9f0abb73f7f5c197a2d72bf3f67735cd
|
|
| MD5 |
8b6c5e3afaab9e4cf2a4643bfc5aed1d
|
|
| BLAKE2b-256 |
1b12ae7751533294c65603a33e5fe2db081dd98b594885a50f0c09026aab33e2
|
Provenance
The following attestation bundles were made for fastapi_xkit-2.0.2.tar.gz:
Publisher:
publish.yml on Kubenew/FastAPI-XKit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_xkit-2.0.2.tar.gz -
Subject digest:
b66a6b1e423080c0bb78d562fa6ae26c9f0abb73f7f5c197a2d72bf3f67735cd - Sigstore transparency entry: 1347374695
- Sigstore integration time:
-
Permalink:
Kubenew/FastAPI-XKit@3c9f5dff927ef5aeb165bd33c420e746d96f0fb5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Kubenew
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3c9f5dff927ef5aeb165bd33c420e746d96f0fb5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastapi_xkit-2.0.2-py3-none-any.whl.
File metadata
- Download URL: fastapi_xkit-2.0.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3201cd1dcf20c16e7851d7aaf967a6995a9690aad48ae0709670b02f28060e4
|
|
| MD5 |
bee0a5a9d455285ededf4ad11b3eff61
|
|
| BLAKE2b-256 |
7f7dd343f8a4135e74c518fdda0e83f8eb2c9081c772ca088bedb42d3ae62056
|
Provenance
The following attestation bundles were made for fastapi_xkit-2.0.2-py3-none-any.whl:
Publisher:
publish.yml on Kubenew/FastAPI-XKit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_xkit-2.0.2-py3-none-any.whl -
Subject digest:
d3201cd1dcf20c16e7851d7aaf967a6995a9690aad48ae0709670b02f28060e4 - Sigstore transparency entry: 1347374787
- Sigstore integration time:
-
Permalink:
Kubenew/FastAPI-XKit@3c9f5dff927ef5aeb165bd33c420e746d96f0fb5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Kubenew
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3c9f5dff927ef5aeb165bd33c420e746d96f0fb5 -
Trigger Event:
workflow_dispatch
-
Statement type: