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.4.tar.gz
(2.7 kB
view details)
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 simplelimiter-0.1.4.tar.gz.
File metadata
- Download URL: simplelimiter-0.1.4.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.5 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12844fc3eebb5b1cded48ce4a30beb891c6ab049eac0d2b3af82ed6a4e401266
|
|
| MD5 |
4e7d056e98f6c4c96f280195376563e8
|
|
| BLAKE2b-256 |
8bcd41ac320c632e3352a9b3f51413a090f6e2f7adbcb84189999c0147b92080
|
File details
Details for the file simplelimiter-0.1.4-py3-none-any.whl.
File metadata
- Download URL: simplelimiter-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.5 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca09bfd044fd70173b0d7e930e393c3d260330110cae24a771226e50cce6f562
|
|
| MD5 |
02389b916bf5dbdeda6a3be7a377a962
|
|
| BLAKE2b-256 |
c40a025e882d1442a80d3dbce030681f219f189fa13b2fcdaaf0b76e094ce399
|