pyrate_limiter.abstracts.rate module

Unit classes that deals with rate, item & duration

class pyrate_limiter.abstracts.rate.Duration(*values)

Bases: Enum

Interval helper class

DAY = 86400000
HOUR = 3600000
MINUTE = 60000
SECOND = 1000
WEEK = 604800000
static readable(value)
Return type:

str

class pyrate_limiter.abstracts.rate.Rate(limit, interval, burst=None)

Bases: object

Rate definition.

Parameters:
  • limit (int) – Number of requests allowed within interval

  • interval (int | Duration) – Time interval, in miliseconds

  • burst (int | None) – How many units may be spent at once. Only the constant-state algorithms (GCRA, TokenBucket) read it; the window algorithms admit up to limit per window regardless. Defaults to limit, which is classic token-bucket behaviour - a full bucket at rest. burst=1 makes the output perfectly smooth.

burst
interval
limit
class pyrate_limiter.abstracts.rate.RateItem(name, timestamp, weight=1)

Bases: object

RateItem is a wrapper for bucket to work with

name
timestamp
weight