ws.utils.rate module

RateLimited() is a rate limiting algorithm implemented as Python decorator.

The original algorithm comes from this StackOverflow answer and has been modified to apply longer timeout when the rate limit is exceeded.

Usage as Python decorator:

# allow at most 10 calls in 2 seconds
@RateLimited(10, 2)
def PrintNumber(num):
    print(num)

Or at runtime by wrapping the function call:

# allow at most 10 calls in 2 seconds
wrapped = RateLimited(10, 2)(PrintNumber)
ws.utils.rate.RateLimited(rate, per)