Skip to main content

Redis-based rate-limiting for FastAPI

Project description

FastAPI Ratelimiter

[PyPI version]

Documentation: https://fastapi-ratelimit.readthedocs.io/en/latest/

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


@app.get(
    "/some_expensive_call", response_class=JSONResponse,
    dependencies=[
        Depends(RateLimited(BucketingRateLimitStrategy(rate="10/60s")))
    ]
)
async def handle_test_endpoint():
    await asyncio.sleep(5)
    return {"hello": "world"}


app.dependency_overrides[RedisDependencyMarker] = lambda: redis

if __name__ == '__main__':
    uvicorn.run(app)

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file fastapi-ratelimiter-0.0.2.tar.gz.

File metadata

  • Download URL: fastapi-ratelimiter-0.0.2.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.8.0-59-generic

File hashes

Hashes for fastapi-ratelimiter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f43b498d9de10c53d3612bede8619271143b2160d88421ac67c56770e84f4a94
MD5 1aa3bb133b4334b6299e3942f6a4c213
BLAKE2b-256 03c8ab0f2bcc4f6734688f560cb9cf4b72e3a83f6567944fa9b5fe9fb4d7d4fe

See more details on using hashes here.

File details

Details for the file fastapi_ratelimiter-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_ratelimiter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4101dcb1604303a862aa2fd7b1717d490569f51478d6a531f101bb76efb5c5e8
MD5 0dfe401ed3c12f1d35e977ccfa1c1b94
BLAKE2b-256 027c1403f844243a51f2e7c4295f997724f8c11ded3ec4db30f2e5e8ff25de04

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