Skip to main content

Rate limiting middleware for FastAPI applications

Project description

FastAPI Rate Limit

A flexible rate limiting middleware for FastAPI applications.

Features

  • Simple and intuitive API
  • Multiple storage backends (in-memory, Redis)
  • Customizable rate limit rules
  • Response headers with rate limit information
  • Exception handling with customizable responses

Installation

pip install fastapi-rate-limit

Quick Start

from fastapi import FastAPI
from fastapi_rate_limit import RateLimitMiddleware, Rule

app = FastAPI()

# Add rate limiting middleware
app.add_middleware(
    RateLimitMiddleware,
    rules=[
        Rule(path="/api/*", limit=10, period=60),  # 10 requests per minute for /api/* paths
    ]
)

@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.get("/api/items")
async def get_items():
    return {"items": ["item1", "item2"]}

Documentation

For more detailed documentation, please visit our documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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_ratelimit_middleware-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

fastapi_ratelimit_middleware-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_ratelimit_middleware-0.1.0.tar.gz.

File metadata

File hashes

Hashes for fastapi_ratelimit_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b60bd8980a78d8b48a1601cab1c644f48433bf10fe81ced9429218666361e905
MD5 51e200791dc1e563351ae8347efaf940
BLAKE2b-256 d96e16cbc4c1711bd5c5ffc519d4d386b81cd30765bde58df7c660a87db890f8

See more details on using hashes here.

File details

Details for the file fastapi_ratelimit_middleware-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_ratelimit_middleware-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a4be4dc6356b62e92e238dbd70e9d117eb19abe488b1bc84fd8f05b35f9ec5f
MD5 2f54b3cade56e3a0679880382a3e9ccc
BLAKE2b-256 e2d77105770147732ee1d0445a54b88215d4537441f7a2f673d6d5b8f953a812

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