Skip to main content

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
  • /health endpoint

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_xkit-2.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

fastapi_xkit-2.0.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for fastapi_xkit-2.0.2.tar.gz
Algorithm Hash digest
SHA256 b66a6b1e423080c0bb78d562fa6ae26c9f0abb73f7f5c197a2d72bf3f67735cd
MD5 8b6c5e3afaab9e4cf2a4643bfc5aed1d
BLAKE2b-256 1b12ae7751533294c65603a33e5fe2db081dd98b594885a50f0c09026aab33e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_xkit-2.0.2.tar.gz:

Publisher: publish.yml on Kubenew/FastAPI-XKit

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

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

Hashes for fastapi_xkit-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3201cd1dcf20c16e7851d7aaf967a6995a9690aad48ae0709670b02f28060e4
MD5 bee0a5a9d455285ededf4ad11b3eff61
BLAKE2b-256 7f7dd343f8a4135e74c518fdda0e83f8eb2c9081c772ca088bedb42d3ae62056

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_xkit-2.0.2-py3-none-any.whl:

Publisher: publish.yml on Kubenew/FastAPI-XKit

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