Skip to main content

A library to optimize the speed of rate limited async calls.

Project description

aioburst

A library to optimize the speed of rate limited async calls, by alternating between bursts and sleeps.

Usage

Install the package using pip:

pip install aioburst

Import the limiter:

from aioburst import aioburst

Instantiate the limiter using the create method, setting the limit (number of calls) and period (period over which the number of calls are restricted):

limiter = AIOBurst.create(limit=10, period=1.0)

async with limiter:
    ...

The code above would allow 10 asynchronous entries (into the context manager) without any limit. Then it adds "sleepers" for the next calls. The sleeper tells the next entry when it can start. The 11th call gets the sleeper set by the 1st call that returned and waits until the period has elapsed. This approach ensures that there are never more than limit simultaneous calls but that the next call can start as soon as possible. The result is that in a sliding window of period you should see exactly limit calls as active, regardless of how fast or slow any individual call returns.

You can also stack limiters:

limiter1 = AIOBurst.create(limit=10, period=1.0)
limiter2 = AIOBurst.create(limit=100, period=60.0)

async with limiter1:
	async with limiter2:
    ...

Use this for cases where an API has a two-level rate limit like 10 calls per second or 100 calls per minute---both limits will be respected. The stack is also idempotent, meaning that whichever way you stack the limiters, both limits will be respected:

limiter1 = AIOBurst.create(limit=10, period=1.0)
limiter2 = AIOBurst.create(limit=100, period=60.0)


async with limiter1:
	async with limiter2:
    ...
    
# The limit above will do the exact same thing as the limit below
async with limiter2:
	async with limiter1:
    ...

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

aioburst-0.2.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

aioburst-0.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file aioburst-0.2.0.tar.gz.

File metadata

  • Download URL: aioburst-0.2.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.7 Linux/5.4.0-1090-azure

File hashes

Hashes for aioburst-0.2.0.tar.gz
Algorithm Hash digest
SHA256 29c7e3289d7e935e974009a846a8da55fefa45214780a15949517fabf0e4aad2
MD5 b6ea61b0bf208605b92c160ee875add1
BLAKE2b-256 95bdfe5671cddc5a72585f2f9dc101065d93d583367968a887f020fae0a54ffa

See more details on using hashes here.

File details

Details for the file aioburst-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aioburst-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.7 Linux/5.4.0-1090-azure

File hashes

Hashes for aioburst-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e036e68e504b8031ebfe260bb66ac8d8aaff4c39f5f4332cf52c814109da8b1
MD5 b6f7103edc8373275219db32c899a475
BLAKE2b-256 64568b44c64452352ede6e8da85ad604325c89e4d18b38a5a200b59ec75ecd12

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page