Limit amount of requests to your FastAPI.
Project description
FastAPI Throttling Middleware
FastAPI Throttling Middleware is a rate-limiting middleware for the FastAPI web framework. It uses a Redis server for request tracking and allows you to throttle incoming requests based on IP address and access token. Features
IP-based throttling: Limit requests based on client's IP address.
Token-based throttling: Limit requests based on user access token.
Redis integration: Uses Redis as a fast, in-memory data store to track request count.
Configurable rate limits: Set your own request limit and time window.
Installation
First, ensure you have a running Redis server.
Next, install the middleware library.
pip install fastapi-throttling
Usage
Here's a basic example of how to use the middleware:
from fastapi import FastAPI, Request, HTTPException
from fastapi_throttling import ThrottlingMiddleware
app = FastAPI()
app.add_middleware(ThrottlingMiddleware, limit=100, window=60)
In this example, the middleware will limit to 100 requests per 60 seconds, either by IP or by user token.
License
GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
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
File details
Details for the file fastapi_throttling-0.1.9.tar.gz
.
File metadata
- Download URL: fastapi_throttling-0.1.9.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1040-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82052c202109eb573e60a13abe37e9904d2976d6baf80775dfc19a0189a393aa |
|
MD5 | 92c5f3d4405be3cf0e7aff4c12b769bb |
|
BLAKE2b-256 | 194af47389f0aedc8f6f6e7c24c37aa6886164a73c850e139e127d17a11ddc60 |
File details
Details for the file fastapi_throttling-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: fastapi_throttling-0.1.9-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.15.0-1040-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d4214775b6909537c79395c990e65a3fb6ae23984e86d4dbcc1a8f30fe903cb |
|
MD5 | 79f01c7635e3f46cda610ffda24b6e6b |
|
BLAKE2b-256 | 5fb57a3720093284a373b29480bb591db0bce2f9fc4265369b3dd6abb4b25571 |