A pluggable API Gateway toolkit for FastAPI with authentication and rate limiting.
Project description
SentryGate
A pluggable API Gateway toolkit for FastAPI with authentication and rate limiting.
This project provides middleware and routing components to easily add gateway functionality to your FastAPI applications.
Installation
pip install SentryGate-ydnd
To include the uvicorn server for running examples, install with the [dev] extra:
pip install "SentryGate-ydnd[dev]"
Quickstart
Here's how to set up a basic API gateway in just a few lines of code.
# main.py
import os
from fastapi import FastAPI
from contextlib import asynccontextmanager
from sentrygate import AuthMiddleware, RateLimitingMiddleware, create_gateway_router
# The RateLimitingMiddleware needs to connect to Redis on startup.
# We use the 'lifespan' context manager to handle this.
@asynccontextmanager
async def lifespan(app: FastAPI):
# Initialize the middleware to get a reference
rate_limiter = app.user_middleware[1].instance
await rate_limiter.connect_to_redis()
yield
await rate_limiter.close_redis_client()
# Create the FastAPI app with the lifespan handler
app = FastAPI(lifespan=lifespan)
# Add authentication and rate limiting middleware
app.add_middleware(
AuthMiddleware,
supabase_url=os.getenv("SUPABASE_URL"),
supabase_jwt_secret=os.getenv("SUPABASE_JWT_SECRET")
)
app.add_middleware(
RateLimitingMiddleware,
redis_url=os.getenv("REDIS_URL", "redis://localhost")
)
# Define routes to proxy to other services
gateway_routes = [
{"path_prefix": "/api/users", "target_service": "http://localhost:8001"},
{"path_prefix": "/api/products", "target_service": "http://localhost:8002"},
]
app.include_router(create_gateway_router(routes=gateway_routes))
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 sentrygate_ydnd-0.1.1.tar.gz.
File metadata
- Download URL: sentrygate_ydnd-0.1.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
223fe3ed7a410b7c17b606cf915f80b46ecd7a689174a165c405e90672c06c09
|
|
| MD5 |
ec1e321f1c29063e84d858f9a53820b0
|
|
| BLAKE2b-256 |
1e08ba0cbdeb3b80cb3383ba357d13ca9b49323fb9060c6e36ac048ea56ee5e0
|
File details
Details for the file sentrygate_ydnd-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sentrygate_ydnd-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f917d8647b450e929f03f0dd6ca6c838ebf7b129985a8c2a34d05f3a0936c4ab
|
|
| MD5 |
8bfa528d9f9656aacf320da4037b1ac4
|
|
| BLAKE2b-256 |
d3419d0ff1aa02c3a867435ff31dfca849c5e7282917eef50ae4b05d74e95b97
|