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 middleware_lib 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
fastapi_throttling-0.1.1.tar.gz
(12.3 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_throttling-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 553e1a5fc2d73f233731e3ef48429fce53fd46d4e8e7f44d9668bcc386322a57 |
|
MD5 | 8b9ec0ba63a4cbf2d99995536ffa64ad |
|
BLAKE2b-256 | 31abd154f414027543e5a3fcf6774ddf01e30f57a01fae47009c7d13ecd2c23e |