Rate-limiting asynchronous and thread-safe decorators and context managers that implement the token-bucket algorithm.
Project description
limiter
Rate-limiting thread-safe and asynchronous decorators and context managers that implement the token-bucket algorithm.
- Thread-safe, with no need for a timer thread
- Control burst requests
- Control average request rate
- Easy to use
Installation
Requirements
- Python 3.7+
Installing from PyPI
pip3 install limiter
Usage
from asyncio import sleep
from requests import get, Response
from limiter import get_limiter, limit
REFRESH_RATE = 2
BURST_RATE = 3
limiter = get_limiter(rate=REFRESH_RATE, capacity=BURST_RATE)
@limit(limiter)
def get_page(url: str) -> Response:
return get(url)
@limit(limiter, consume=2)
async def do_stuff():
await sleep(0.1)
def do_stuff():
# do stuff
with limit(limiter, consume=1.5):
# do expensive stuff
pass
async def do_stuff():
# do stuff
async with limit(limiter):
# do expensive stuff
pass
@limit(limiter, bucket=b'other stuff')
def do_other_stuff():
pass
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 Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file limiter-0.1.1.tar.gz.
File metadata
- Download URL: limiter-0.1.1.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.0b3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54bc4e23ab1c0b75b28b2608936a614022b08c4fbf4ff87fa45461ece29058be
|
|
| MD5 |
2537d196e46ffaafbd6d9d7491380098
|
|
| BLAKE2b-256 |
bf31d745003d378d968b6ae6a52791684220b4aa0e4ce20093660d8ca45da4e6
|
File details
Details for the file limiter-0.1.1-py3.8.egg.
File metadata
- Download URL: limiter-0.1.1-py3.8.egg
- Upload date:
- Size: 5.3 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.0b3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53391dbe0dccec6efa61698f461b198cf818d69c4e5db9851d72424bfc4fa518
|
|
| MD5 |
47eb490cc58c13d4d21c3e28cdd8e2f9
|
|
| BLAKE2b-256 |
a64aca8951770b4c406312d89ad86b435dea729475545105c1fbceb8aec7e52d
|
File details
Details for the file limiter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: limiter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.0b3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cf9d7c7c472f262b452af4b6351f7a4166a66d3d3655f1c744cc0625b3eae2d
|
|
| MD5 |
10dacbbc8faf925521c0e61a19d85f71
|
|
| BLAKE2b-256 |
bb717e65d2ac539272bf1f06f04f5802b280f31566ac044fa9fea6683c21a799
|
File details
Details for the file limiter-0.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: limiter-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51405869f3fba51913232be9eb83d6025181141ee38cfbf91ac72a629044c279
|
|
| MD5 |
247ee3916d9b99c4a63cd6c4ebadb15d
|
|
| BLAKE2b-256 |
23a6045eb90d57066348e9296709ac25e8c9343e69e126145ac943ab5b6f5e6a
|