Makes it easy to respect rate limits.
Project description
Ratelim is a simple Python library that limits the number of times a function can be called in during a time interval. It is particularly useful when using online APIs, which commonly enforce rate limits.
Installation
$ pip install ratelim
Usage
Say you want to call a function at most for n_calls during a n_seconds time interval.
# 10 times in 5 seconds
@ratelim.greedy(10, 5)
def hello(lines):
print("hello")
The greedy rate limiter calls does not delay any function call until it’s really necessary.
In some scenarios, for example when crawling data from an API, you want to maximize the number of calls you make and you want to avoid sending them in short sequence. For this goal, we can use the patient rate limiter. It distributes calls evenly between each other.
# 10 times in 5 seconds
# Gets called at most every 0.5 seconds
@ratelim.patient(10, 5)
def hello(lines):
print("hello")
LICENSE
MIT.
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
File details
Details for the file ratelim-0.1.4.tar.gz
.
File metadata
- Download URL: ratelim-0.1.4.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 423cfb2421abffddb53ca2f4359d320c4e4f21996898600450cb6dc8e6fa1818 |
|
MD5 | 1657e31d301f4a3b08fc574ff2c41d6f |
|
BLAKE2b-256 | e9e8e638adfdfb64df3936d9f3c2b8f6d690d5078cf21d9ea68f275e124f780b |