Rate¶
- class uprate.rate.Rate(uses: int, period: float)[source]¶
A rate consisting of uses and time period
Used to define rates for ratelimits with syntatical expressions.
You should refrain from creating your own Rate objects and instead use the objects provided in the library.
- uprate.rate.Seconds = <uprate.rate.Rate object>¶
A Rate of 1 use / 1 Second Used in syntatical expression to define rate
Example
assert 2 / Seconds(3) == 2 / (3 * Seconds) ... # 30 uses per 2 min 30 sec but also 2 uses per 2 seconds api_rate: uprate.rate.RateGroup = 2/Seconds(2) | 30/(2 * Minutes + 30 * Seconds)
- uprate.rate.Minutes = <uprate.rate.Rate object>¶
Rate of 1 use / 1 Minute
- uprate.rate.Hours = <uprate.rate.Rate object>¶
Rate of 1 use / 1 Hour
- uprate.rate.Days = <uprate.rate.Rate object>¶
Rate of 1 use / 1 Day
- uprate.rate.Weeks = <uprate.rate.Rate object>¶
Rate of 1 use / 1 Week
- uprate.rate.Months = <uprate.rate.Rate object>¶
Rate of 1 use / 1 Month
Note
If you need larger time periods you can create them by
Year = Rate(1, 60 * 60 * 24 * 365) # Proceed to use like other unitary use rates rate = 5 / Year(2) # 5 uses per 2 years
Rate Group¶
This is an internal component but has been documented for sake of typing.
uprate.rate.RateGroup
objects are created when uprate.rate.Rate
objects are operated togather
with operator.__or__()
that is the bitwise or operator a | b
ApiRateGroup: uprate.rate.RateGroup = (2 / Seconds(3)) | (3 / Minutes(2) + Seconds(5))