-
-
Save pcustic/540f5ea3634bd77d107f283e65513ff8 to your computer and use it in GitHub Desktop.
PyrateLimiter example basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyrate_limiter import Duration, Rate, Limiter, BucketFullException | |
max_requests = 5 | |
time_period = Duration.SECOND * 2 | |
rate = Rate(max_requests, time_period) | |
limiter = Limiter(rate) | |
# Or you can pass multiple rates | |
# rates = [Rate(5, Duration.SECOND * 2), Rate(10, Duration.MINUTE)] | |
# limiter = Limiter(rates) | |
for request in range(max_requests + 1): | |
try: | |
limiter.try_acquire(request) | |
except BucketFullException as err: | |
print(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment