This package provides decorators which can be used to throttle calls of regular Python functions and asyncio coroutines.
Use pip package installer for Python:
python -m pip install --upgrade call-throttleMake sure you have Python 3.9 or later installed.
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=2))
def func():
time.sleep(1)
@throttle(calls=2, period=0.2)
async def coro():
await asyncio.sleep(0.05)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.
This is a free software licensed under the terms of the MIT License.