FastAPIRateLimit

Contributing is F&E (free&easy) Y

Usage

pip install farlimit

NOTE you have to define starlette.requests.Request as first argument

from farlimit import Limiter
from fastapi import APIRouter
from starlette.requests import Request

router = APIRouter(...)

@router.<any-method>(path)
@Limiter(times=3, per=5 * Limiter.SECONDS)
def test_ratelimit(request: Request):
    return 'no limit'
  • Limiter Schema and options

  • if need to extend Limiter Memory (like on redis to distributed services)

CNEEDS

  • RedisMemory
  • custom identifier
  • custom execption handler or callbacks
  • some api for reports
  • could we handle race condition?

GitHub

View Github