Internal Ratelimiter
Warning
While this is documented, you are not encouraged to modify how the library handles ratelimits. The defaults are curated to the active top.gg ratelimits, and modifying things (incorrectly) will break every function in toppy.
Ratelimiter class
- class toppy.ratelimiter.bucket.Ratelimit(*, route: str, hits: int, cooldown: float)
Internalised ratelimit class to prevent 429s from top.gg
- Parameters
route – str - Not actually used.
hits – int - The maximum number of times the API can be hit before a 429 is expected.
cooldown – float - The cooldown time when hitting a 429. For top.gg, this is always 3600.0 (1 hour)
- property ratelimited: bool
Boolean indicating if the current route is ratelimited. :return: True if a request would become ratelimited, otherwise False.
- property retry_after: float
Floating point number indicating how long, in seconds, until the current ratelimit has expired.
Note
This function ALWAYS returns a float. This means
0.0will be returned if there’s no ratelimit active.- Returns
How long (in seconds) until the current ratelimit is over.
- sync_from_ratelimit(retry_after: float)
Syncs the internal ratelimit clock to that of a 429 response.
- Parameters
retry_after – float - The retry_after value
- add_hit()
Handles adding a hit to the route and dealing with the datetime-y stuff