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
limiter-0.1.0.tar.gz
(3.5 kB
view details)
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.0.tar.gz.
File metadata
- Download URL: limiter-0.1.0.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.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.0b3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bc658e501cd43ee40a4f62f0670a0c94ecc7c3c0689aea7e119ef1cf4a6c4a9
|
|
| MD5 |
9754671bcd39376a8a48925bcbf97aaa
|
|
| BLAKE2b-256 |
d673a0f5d97dec62819cb5e56d2de1d2ea0f67dc6cf46be157a33821953b48cd
|
File details
Details for the file limiter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: limiter-0.1.0-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.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.8.0b3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a38b8858c7506bb3c4b6590f56b4d5549f5b1accf156eb6b9772f7fa9c98e75b
|
|
| MD5 |
f4e1be62ffc001ea872135afe9f0ae99
|
|
| BLAKE2b-256 |
ac4e2490be078452d21a946fce5a5e45d07a5794fb8c9944fd5a3a6774c271d5
|
File details
Details for the file limiter-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: limiter-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbcd5228d2870f552ae34369ba57600e08e75272657734cf86b86bc338ebb601
|
|
| MD5 |
38042165b6a43798f90f502a996b7daf
|
|
| BLAKE2b-256 |
4a39cd88c18a7a4ddc2c2797935530d4957508b5da44a64c16300f48d60759b7
|