long2ice / fastapi-limiter

A request rate limiter for fastapi

Home Page:https://github.com/long2ice/fastapi-limiter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User customized rate limit ?

harshraj22 opened this issue · comments

I want to have a subscription based api service. there are 3 types of subscription:
Free: 10 api calls per 24hour
Basic: 30 api calls per 24hour
Advanced: 80 api calls per 24hour.

Along with the request body, suppose the detaiils about the subscription is also available. Can such scenario be handled by your library ?
I am using fastapi, and I would prefer using a library than writing my own rate limiter using reddis.

No, which need your own customization

I opted for something like this

async def dynamic_rate_limiter(request: Request, response: Response):
    # logic here, if free, else if premium ...
    await RateLimiter(times=1, seconds=60)(request, response)


@router.get(
    "/v1/dummy",
    dependencies=[Depends(dynamic_rate_limiter)],
)
def get_dummy():
    return {"dummy": "dummy"}