Skip to main content

Redis-based rate-limiting for FastAPI

Project description

FastAPI Ratelimiter

[PyPI version]


Quick start:

import asyncio

import aioredis
import uvicorn
from fastapi import FastAPI, Depends
from starlette.responses import JSONResponse

from fastapi_ratelimiter import RateLimited, RedisDependencyMarker
from fastapi_ratelimiter.strategies import BucketingRateLimitStrategy

app = FastAPI()
redis = aioredis.from_url("redis://localhost")

    "/some_expensive_call", response_class=JSONResponse,
async def handle_test_endpoint():
    await asyncio.sleep(5)
    return {"hello": "world"}

app.dependency_overrides[RedisDependencyMarker] = lambda: redis

if __name__ == '__main__':

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-ratelimiter-0.0.2.tar.gz (17.1 kB view hashes)

Uploaded source

Built Distribution

fastapi_ratelimiter-0.0.2-py3-none-any.whl (18.7 kB view hashes)

Uploaded py3

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