hcss-utils / scite

0 stars 0 forks source link

Ratelimits #2

Closed hp0404 closed 3 years ago

hp0404 commented 3 years ago

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

hp0404 commented 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()