Skip to content

Number of remaining API calls? #286

Discussion options

You must be logged in to vote

Hello. I prepared simple example of override method that gives you access to response headers (which contains rate limits).

class RateLimitedClient(Client):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        self._limit = self._remaining = self._reset = None

    def get_rate_limit(self):
        return self._limit, self._remaining, self._reset

    def _invoke(self, *args, **kwargs):
        response = super()._invoke(*args, **kwargs)

        self._limit = response.headers.get('RateLimit-Limit')
        self._remaining = response.headers.get('RateLimit-Remaining')
        self._reset = response.headers.get('RateLimit-Reset')

        return 

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@andreafailla
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by andreafailla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants