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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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

Hashes for fastapi_throttling-0.1.9.tar.gz
Algorithm Hash digest
SHA256 82052c202109eb573e60a13abe37e9904d2976d6baf80775dfc19a0189a393aa
MD5 92c5f3d4405be3cf0e7aff4c12b769bb
BLAKE2b-256 194af47389f0aedc8f6f6e7c24c37aa6886164a73c850e139e127d17a11ddc60

See more details on using hashes here.

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

Hashes for fastapi_throttling-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8d4214775b6909537c79395c990e65a3fb6ae23984e86d4dbcc1a8f30fe903cb
MD5 79f01c7635e3f46cda610ffda24b6e6b
BLAKE2b-256 5fb57a3720093284a373b29480bb591db0bce2f9fc4265369b3dd6abb4b25571

See more details on using hashes here.

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