Simple FastAPI rate limiter
Project description
simplelimiter
A simple FastAPI rate limiter
Requirements
How to use
Install the package
pip install simplelimiter
Example
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)
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
simplelimiter-0.1.3.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for simplelimiter-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed523d92585bb7ee65d55256db5564b9478dfc7a7d8b1d23b370b63138602785 |
|
MD5 | f96c68d24f05712e1c513356775d2dcc |
|
BLAKE2b-256 | 5ea9fe431a560c19f09a193fd1d7dcd7bb045e0a9e8792a0db61eebe240fff0f |