Rate limiting middleware for FastAPI applications
Project description
FastAPI Rate Limit
A flexible rate limiting middleware for FastAPI applications.
Features
- Simple and intuitive API
- Multiple storage backends (in-memory, Redis)
- Customizable rate limit rules
- Response headers with rate limit information
- Exception handling with customizable responses
Installation
pip install fastapi-rate-limit
Quick Start
from fastapi import FastAPI
from fastapi_rate_limit import RateLimitMiddleware, Rule
app = FastAPI()
# Add rate limiting middleware
app.add_middleware(
RateLimitMiddleware,
rules=[
Rule(path="/api/*", limit=10, period=60), # 10 requests per minute for /api/* paths
]
)
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/api/items")
async def get_items():
return {"items": ["item1", "item2"]}
Documentation
For more detailed documentation, please visit our documentation.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
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 fastapi_ratelimit_middleware-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_ratelimit_middleware-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b60bd8980a78d8b48a1601cab1c644f48433bf10fe81ced9429218666361e905
|
|
| MD5 |
51e200791dc1e563351ae8347efaf940
|
|
| BLAKE2b-256 |
d96e16cbc4c1711bd5c5ffc519d4d386b81cd30765bde58df7c660a87db890f8
|
File details
Details for the file fastapi_ratelimit_middleware-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_ratelimit_middleware-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a4be4dc6356b62e92e238dbd70e9d117eb19abe488b1bc84fd8f05b35f9ec5f
|
|
| MD5 |
2f54b3cade56e3a0679880382a3e9ccc
|
|
| BLAKE2b-256 |
e2d77105770147732ee1d0445a54b88215d4537441f7a2f673d6d5b8f953a812
|