Yet Another Rate Limiter (for Python)
Project description
pyyarl
pyyarl
(Yet Another Rate Limiter for Python) is a Python package for rate
limiting function calls.
A lot of Python rate limiting packages seem to exist, but many of them do not have the desired behavior in many use cases. For example, many clear tasks only when the period has elapsed, rather than using a sliding window, or they may mark a task as done prior to running the function rather than after.
pyyarl
uses a sliding window of completion times to enforce the rate limit, and
is simple to use. pyyarl
currently supports single and multithreaded execution.
Table of Contents
Quickstart
For example, the default Google Docs read request quota might be 300 requests per minute:
from pyyarl import rated_limited
@rate_limited(max_calls=300, period_s=60)
def make_read_request(file_id):
... # some request to the Google Docs API
for file_id in file_ids:
res = make_read_request(file_id)
Having multiple functions limited together
Sometimes, you want to limit multiple functions together such that their calls count towards the same rate.
from pyyarl import RateLimiter
rate_limiter = RateLimiter(max_calls=300, period_s=60)
@rate_limiter
def make_read_request_one(file_id) -> bool:
... # some request to the Google Docs API
@rate_limiter
def make_read_request_two(file_id):
... # some other request to the Google Docs API
for file_id in file_ids:
if make_read_request_one(file_id):
make_read_request_two(file_id)
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
Built Distribution
File details
Details for the file pyyarl-1.0.0.tar.gz
.
File metadata
- Download URL: pyyarl-1.0.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a82b56b0eb4728d0ff2ed90bbe77fae83d8a643ff5325f5cce40a46209f3018 |
|
MD5 | 53f64ccd74718f2a4241997d1bb5af81 |
|
BLAKE2b-256 | 7ef1e54de90295316dbfb4fc9b9eb4ea113e9bf81a782f11cfaf9eb572762f63 |
File details
Details for the file pyyarl-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyyarl-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a4f35c0c3951b6f4fca21529b1e60d5656277e891f70df34614e41e703b9a34 |
|
MD5 | 1a13e73fd1585575db11c3775f6c5936 |
|
BLAKE2b-256 | 6de422af32a9bf9f13812207f7b6281784d760cf54d759e96fd458566eb9467c |