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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size limiter-0.1.1-py2.py3-none-any.whl (15.2 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
Filename, size limiter-0.1.1-py3.8.egg (5.3 kB) | File type Egg | Python version 3.8 | Upload date | Hashes View |
Filename, size limiter-0.1.1-py3-none-any.whl (3.7 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size limiter-0.1.1.tar.gz (3.5 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for limiter-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51405869f3fba51913232be9eb83d6025181141ee38cfbf91ac72a629044c279 |
|
MD5 | 247ee3916d9b99c4a63cd6c4ebadb15d |
|
BLAKE2-256 | 23a6045eb90d57066348e9296709ac25e8c9343e69e126145ac943ab5b6f5e6a |