A lightning-fast cooldown/ratelimit implementation.
from pycooldown import FixedCooldown
cooldown = FixedCooldown(period=10, capacity=5)
def handle_event(sender):
retry_after = cooldown.update_ratelimit(sender)
if retry_after is None:
print("Event succeeded!")
else:
print(f"Too many events from {sender}. Retry in {retry_after} seconds.")