Skip to main content

Rate-limiter for FastAPI with the possibility of user-based rate limits

Project description

FastAPI rate limiter

This package adds a rate limiter to FastAPI using Redis.

Installation

First install Redis, then install the package using:

pip install fastapi-user-limiter

Usage

An example of how to use the rate limiter can be found in example.py:

from fastapi_user_limiter.limiter import RateLimiter, rate_limit
from fastapi import FastAPI, Request


app = FastAPI()
rate_limiter = RateLimiter()


@app.get("/")
@rate_limit(rate_limiter, 5, 60)
async def read_root(request: Request):
    return {"Hello": "World"}

Every endpoint handler with the rate limiter decorator needs to have request (of type fastapi.Request) as its first argument.

Future features

The package will soon have the additional feature of allowing each user account to have a different rate limit for each endpoint.

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_user_limiter-0.1.0.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

fastapi_user_limiter-0.1.0-py3-none-any.whl (2.9 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