Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change rate limit after the app has started #64

Open
sandeepkumar-one opened this issue Sep 13, 2021 · 7 comments · May be fixed by #66
Open

Change rate limit after the app has started #64

sandeepkumar-one opened this issue Sep 13, 2021 · 7 comments · May be fixed by #66

Comments

@sandeepkumar-one
Copy link
Collaborator

Is it possible to change the rate limit of app or particular route after the app has started?

@laurentS
Copy link
Owner

You should be able to pass a callable that returns a limit string, something like 1/minute, as the limit definition in your decorator, instead of the hardcoded limit string. That function can then return whatever you need on any call. Something like:

def dynamic_limit():
    # do anything you want here
    return "1/minute"

@limiter.limit(dynamic_limit)
async def homepage(request: Request):
    return PlainTextResponse("test")

Let me know if this works for your use case.

@sandeepkumar-one
Copy link
Collaborator Author

Thank you Laurent for explanation. I suggest we add this example in the test case (tests/test_fastapi_extension.py). It will be helpful for others as well.

@laurentS
Copy link
Owner

Sounds good! Feel free to send a PR for this, or to add an example in the docs.

@sandeepkumar-one
Copy link
Collaborator Author

Thanks, I will raise a PR. Could you please give me access to push a branch.

@laurentS
Copy link
Owner

Thanks, I will raise a PR. Could you please give me access to push a branch.

I don't have access to the repo settings from mobile, but you can fork the repo and open a PR from there.

@sandeepkumar-one
Copy link
Collaborator Author

Hi Laurent, I raised a PR : #66 as per above discussion.

I have a doubt, as seen in my PR I am using exempt in this format : @limiter.limit('exempt') rather than @limiter.exempt. If I use the latter I am getting runtime error. Could you please check it once.

@sandeepkumar-one
Copy link
Collaborator Author

Hi @laurentS, could you please review above mentioned PR.

@laurentS laurentS linked a pull request Oct 10, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants