pyrate_limiter.limit_context_decorator module#

class pyrate_limiter.limit_context_decorator.LimitContextDecorator(limiter, *identities, delay=False, max_delay=None)#

Bases: object

A class that can be used as a:

  • decorator

  • async decorator

  • contextmanager

  • async contextmanager

Intended to be used via Limiter.ratelimit(). Depending on arguments, calls that exceed the rate limit will either raise an exception, or sleep until space is available in the bucket.

Parameters
  • limiter (Limiter) – Limiter object

  • identities (str) – Bucket identities

  • delay (bool) – Delay until the next request instead of raising an exception

  • max_delay (Union[int, float, None]) – The maximum allowed delay time (in seconds); anything over this will raise an exception

async async_delayed_acquire()#

Delay and retry until we can successfully acquire an available bucket item

delay_or_reraise(err)#

Determine if we should delay after exceeding a rate limit. If so, return the delay time, otherwise re-raise the exception.

Return type

float

delayed_acquire()#

Delay and retry until we can successfully acquire an available bucket item