https://github.com/byunjuneseok/fastapi-frl
⚡️⏲ Rate limiter library for FastAPI. (Work in progress..)
https://github.com/byunjuneseok/fastapi-frl
aioredis fastapi python3 rate-limiter rate-limiting redis
Last synced: about 1 year ago
JSON representation
⚡️⏲ Rate limiter library for FastAPI. (Work in progress..)
- Host: GitHub
- URL: https://github.com/byunjuneseok/fastapi-frl
- Owner: byunjuneseok
- License: apache-2.0
- Created: 2022-02-10T02:40:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-30T13:49:36.000Z (about 4 years ago)
- Last Synced: 2025-04-15T03:54:59.920Z (about 1 year ago)
- Topics: aioredis, fastapi, python3, rate-limiter, rate-limiting, redis
- Language: Python
- Homepage: https://byunjuneseok.github.io/fastapi-frl/
- Size: 561 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastapi-frl
[](https://pypi.python.org/pypi/fastapi-frl)
[](https://pypi.org/project/fastapi-frl/)
Rate limiter library for FastAPI.

## Prerequisite
- Redis server
## Installation
```shell
pip install fastapi-frl
```
## Getting Started
```python3
from fastapi import APIRouter, Depends, FastAPI
from fastapi_frl import LimiterBackend, Limiter
from fastapi_frl.algorithms import SimpleAlgorithm, SlidingWindowCounter
from fastapi_frl.key import KeyByIP, KeyByPath
app = FastAPI()
# You only need to initialize backend of limiter once.
limiter_backend = LimiterBackend('redis://localhost')
# Define the limiter.
limiter = Limiter(
name='hello_world_limiter',
algorithm=SimpleAlgorithm(threshold=10),
key_generator=KeyByIP()
)
# Apply it to a single api endpoint.
@app.get('/', status_code=200, dependencies=[Depends(limiter)])
async def hello_world():
return {'message': 'Hello World'}
# You can define multiple limiter with different rules.
api_book_limiter = Limiter(
name='api_book_limiter',
algorithm=SlidingWindowCounter(10, 10),
key_generator=KeyByPath(),
)
# Also, you can apply it to the api router.
api_book_router = APIRouter(prefix='/books', tags=['Book'], dependencies=[Depends(api_book_limiter)])
...
app.include_router(api_book_router)
```
## Documentation
The API documentation is in progress.