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.4.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_throttling-0.1.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_throttling-0.1.4.tar.gz.

File metadata

  • Download URL: fastapi_throttling-0.1.4.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.1 Linux/5.15.0-1038-azure

File hashes

Hashes for fastapi_throttling-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1a1f8d567d08d14e86f0f92530f3dfac296ecde032ffc929d8daed5daa3ecbed
MD5 c248f22eb62108f52f15c2624380f0f5
BLAKE2b-256 1542ad35a8c79b49b320d0025564a30be87c3e72ed2da69740c70fc277d4d64c

See more details on using hashes here.

File details

Details for the file fastapi_throttling-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: fastapi_throttling-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.1 Linux/5.15.0-1038-azure

File hashes

Hashes for fastapi_throttling-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 258854c5c1765c6696aaa5190f51aaaf36992a25313354b82281bdb3b4729a8e
MD5 35e1ee3d4bc035d80e1f2c2415b07d15
BLAKE2b-256 45b356b27c90289fd1b0fb87a361466628a5928968ddd74f663a74f250cdfed2

See more details on using hashes here.

Supported by

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