Skip to main content

Limit amount of requests to your FastAPI.

Project description

Upload Python Package

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


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.9.tar.gz (12.6 kB view hashes)

Uploaded Source

Built Distribution

fastapi_throttling-0.1.9-py3-none-any.whl (13.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page