This package provides a few extra utilities for Python, like a "RateLimiter" class.
Project description
ExtraUtils
will provide a bunch of small functionalities to speedup developement.
(In active developement, so if you have any suggestions, to make other developers life easier, feel free to submit them.)
Currently ExtraUtils only has one feature.
RateLimiter()
# A very simplified example
from ExtraUtils import RateLimiter
rate_limit = RateLimiter(10,15,5,1,True)
# threshold (10) -> increments before rate_limit.hit is set to True
# upperCap (15) -> the highest value the trigger counter will go
# decay_rate (5) -> the amount in triggers to be decremented each decay cycle
# decay_time (1) -> the time in seconds between each decay cycle
# extreme_case (True) -> if a exeption should be raised (if True) or just rate_limit.hit set to True (if False)
def rate_limit_test(i:int):
rate_limit.increment()
print(i,rate_limit.hit)
for i in range(20):
rate_limit_test(i)
# Output:
#0 False
#(1 to 8) False
#9 False
#Traceback (most recent call last):
# File "E:\Developement\RTS-Modules\ExtraUtils\showcase.py", line 14, in <module>
# rate_limit_test(i)
# File "E:\Developement\RTS-Modules\ExtraUtils\showcase.py", line 5, in rate_limit_test
# rate_limiter.increment()
# File "E:\Developement\RTS-Modules\ExtraUtils\ExtraUtils\RateLimit.py", line 30, in increment
# raise RateLimited()
#ExtraUtils.RateLimit.RateLimited: Rate limit reached
Aditional methods are:
RateLimiter().pause_decay()
RateLimiter().resume_decay()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
extrautilities-0.1.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for extrautilities-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 326e8740815c68c8755ac6779770ce9b2bc6de73117cd0b97d736c2dceca12be |
|
MD5 | 8a3fde5734d8a7453952a55a8845688b |
|
BLAKE2b-256 | 22370ca0fcc629a5dd990e0cdb68d562203bff407d2a6c9c5ae8437c71548aa7 |