A decorator used to throttle calls of regular functions and asyncio coroutines.
Project description
call-throttle
This package provides decorators which can be used to throttle calls of regular Python functions and asyncio coroutines.
Install
Use pip package installer for Python:
python -m pip install --upgrade call-throttle
Make sure you have Python 3.7 or later installed.
Usage
Here is a basic example for how to use the throttle
decorator with functions and coroutines:
import time
import asyncio
from datetime import timedelta
from call_throttle import throttle
@throttle(calls=1, period=timedelta(seconds=1))
def func():
time.sleep(1)
@throttle(calls=1, period=timedelta(seconds=2))
async def coro():
await asyncio.sleep(1)
If passing raise_on_throttle=True
to @throttle(...)
, then a call_throttle.ThrottleException
is raised when a decorated function or coroutine is called more times than the defined calls
limit within the specified time period
.
License
This is a free software licensed under the terms of the MIT License.
Project details
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 call-throttle-0.4.0.tar.gz
.
File metadata
- Download URL: call-throttle-0.4.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9e216f9832340e7a7b7efd75bb30135fa17ea743763884462eda53b09c189db |
|
MD5 | be8041c0de043faacb0c981f752f1887 |
|
BLAKE2b-256 | bdd3a5e8f908aa79c15f4194d0539a3eac500ee2a78d2a211dbd788590892f2a |
File details
Details for the file call_throttle-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: call_throttle-0.4.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78492d7c08340c5c5f39a6bd51b8f324928eda5927956a2796ce1b98bfeccf5a |
|
MD5 | 4312ceaa4754f3c73965339d1add6bd2 |
|
BLAKE2b-256 | 56491eae9f207f2e8f4bd35b1543708d277eacae2235ca7c09ab1570ec3ee5ca |