Metadata-Version: 2.4
Name: SentryGate-ydnd
Version: 0.1.1
Summary: A pluggable API Gateway toolkit for FastAPI with authentication and rate limiting.
Author-email: Navneet Dhar Dubey <navneetdhardubey.india@gmail.com>
License-Expression: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: fastapi
Requires-Dist: httpx
Requires-Dist: redis
Requires-Dist: python-jose[cryptography]
Provides-Extra: dev
Requires-Dist: uvicorn; extra == "dev"

# 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

```bash
pip install SentryGate-ydnd
```

To include the `uvicorn` server for running examples, install with the `[dev]` extra:

```bash
pip install "SentryGate-ydnd[dev]"
```

## Quickstart

Here's how to set up a basic API gateway in just a few lines of code.

```python
# 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))
```
