Closed hp0404 closed 3 years ago
With ratelimit
it should be as easy as:
import requests
from ratelimit import limits
@limits(calls=40, period=60)
def make_request(url, endpoint, params={}, headers={}):
r = requests.get(f"{url}/{endpoint}", params=params, headers=headers)
return r.json()
As noted in the docs, some ratelimits are applied:
While I think it's possible (and probably a more straightforward approach) to implement with just
time.sleep()
method, it might be worth looking at ratelimit package.A good example of how to
ratelimit
's decorators I think could be found in crossref's source code