Catalog PyPI
Back to packageRELEASE DETAILS

0.2.0

PyPI

aioburst

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

Published20 Oct 2022
Direct dependencies2
Transitive dependenciesNot calculated

README

Version 0.2.0 documentation

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:
    ...

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
pydantic
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.8,<4.0",
  "evaluation": "NOT_EVALUATED"
}
pydantic (>=1.10.2,<2.0.0)runtime
pendulum
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.8,<4.0",
  "evaluation": "NOT_EVALUATED"
}
pendulum (>=2.1.2,<3.0.0)runtime

Distribution files

2 collected
aioburst-0.2.0-py3-none-any.whl

bdist_wheel · 3.94 KB · Python py3

Source file
aioburst-0.2.0.tar.gz

sdist · 3.78 KB · Python source

Source file

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:42 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:b39641b7d74635309e0d8dc3ff0a09f8a8e43437dca92fe988b42184327320e8

Other collected versions

View all collected versions →