Skip to main content

Python decorators for asyncio

Project description


Python decorators for asyncio, including

  • throttle


$ pip install aiodecorator


import time
import asyncio

from aiodecorator import (

now = time.time()

# The throttled function is only called twice a second
@throttle(2, 1)
async def throttled(index: int):
    diff = format(time.time - now, '.0f')
    print(index, f'{diff}s')

async def main():
    loop = asyncio.get_running_loop()
    tasks = [
        for index in range(5)

    await asyncio.wait(tasks)

# Output
# 0 0s
# 1 0s
# 2 1s
# 3 1s
# 4 2s


throttle(limit: int, interval: Union[float, int])

  • limit int Maximum number of calls within an interval.
  • interval Union[int, float] Timespan for limit in seconds.

Returns a decorator function



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aiodecorator, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size aiodecorator-1.0.0-py3-none-any.whl (3.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiodecorator-1.0.0.tar.gz (3.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page