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

Add a “Usage note”? #55

Open
samwyse opened this issue Jul 24, 2021 · 0 comments
Open

Add a “Usage note”? #55

samwyse opened this issue Jul 24, 2021 · 0 comments

Comments

@samwyse
Copy link

samwyse commented Jul 24, 2021

Sometimes you need to limit API calls from another package that you do not control. In this case, monkey patching the API may be the best option. But where? In the requests package, calls to .get, .head, and other methods of a Request() object are funneled to self.request(), so that is one possibility.  However, that method creates a temporary Session object and sends all invocations through it. As a result, the best way to limit all API calls is:

throttled = limits(calls=15, period=FIFTEEN_MINUTES)
Session.request = throttled(Session.request)
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

No branches or pull requests

1 participant