Metadata-Version: 2.1
Name: simplelimiter
Version: 0.1.3
Summary: Simple FastAPI rate limiter
License: MIT
Author: Fabrizio Liotta
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: fastapi (>=0.103.1,<0.104.0)
Requires-Dist: redis (>=5.0.0,<6.0.0)
Description-Content-Type: text/markdown

# simplelimiter

A simple FastAPI rate limiter

## Requirements

[Redis](https://redis.io/)

## How to use

Install the package
```
pip install simplelimiter
```

Example

```py
import redis

from fastapi import FastAPI, APIRouter, Request
from fastapi.params import Depends
from simplelimiter import Limiter


app = FastAPI()
router = APIRouter()

# We initialize the Limiter on the app startup event
@app.on_event("startup")
async def startup():
    r = redis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
    Limiter.init(redis_instance=r, debug=True)

    return app


# We pass the Limiter as a dependencie
@router.get("/", dependencies=[Depends(Limiter("5/minute"))])
def base_route(request: Request):
    return {"response": "ok"}


app.include_router(router)
```


