High level API for limiting callbacks with static rates.
- @uprate.decorators.ratelimit(rate: Rate | RateGroup, *, key: Callable[..., Key] | Callable[..., Coroutine[Any, Any, Key]] | None = None, on_retry: Callable[[RateLimitError], Any] | Callable[[RateLimitError], Coroutine] | None = None, store: BaseStore | SyncStore | None = None)¶
Limit a coroutine function or a callable to be called within provided rate. Example here
Key] | Callable[…, Coroutine[Any, Any,
None) – The callback for generating a bucket for ratelimit from the arguments provided to the decorated function, this can be a coroutine function only when the decorated is a coroutine function as well. If
None, a default callback returning a string based on the decorated function’s name is used, by default
RateLimitError], Any] | Callable[[
RateLimitError], Coroutine] |
None) – If provided then this function will be called when the function gets ratelimited and then the decorated function will be called again, if
Nonethen function call isn’t retried and
RateLimitErroris raised, by default
None) – The store to use for the rate limit, must be of type
BaseStoreif decorated function is a coroutine function else
Nonethen a suitable derived memory store is used, by default
on_retryparameter is not provided and the decorated function got ratelimited.
- async uprate.decorators.on_retry_sleep(error: uprate.errors.RateLimitError) None ¶
Make the current task yield to the event_loop till a usage token is available for the rate limit which raised
RateLimitError) – The rate limit error to sleep for.