Registry / http-networking / asynciolimiter

asynciolimiter

JSON →
library1.2.0pypypi✓ verified 85d ago

asynciolimiter is a simple yet efficient Python library providing various rate limiting algorithms for AsyncIO applications. It offers different limiter flavors like `Limiter`, `LeakyBucketLimiter`, and `StrictLimiter` to control the rate of asynchronous operations. The current version is 1.2.0, actively maintained with regular releases addressing features and bug fixes.

pip install asynciolimiter
INSTALL
IMPORT
SIG · ASYNCIOLIMITER
A
asynciolimiter
http-networkingpythonv1.2.0
Install
1.5s avg
Import
195ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.208s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.182s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Limiter
from asynciolimiter import Limiter
LeakyBucketLimiter
from asynciolimiter import LeakyBucketLimiter
StrictLimiter
from asynciolimiter import StrictLimiter

This quickstart demonstrates how to use the basic `Limiter` to constrain the execution rate of asynchronous tasks. It creates a limiter allowing 2 requests per second (10 requests over 5 seconds) and then schedules 10 tasks, each waiting for the limiter before proceeding.

import asyncio from asynciolimiter import Limiter # Limit to 2 requests per second (10 requests per 5 seconds) rate_limiter = Limiter(10/5) async def request_task(task_id): await rate_limiter.wait() # Wait for a slot to be available print(f"Task {task_id}: Request sent at {asyncio.get_event_loop().time():.2f}") async def main(): print("Starting rate-limited tasks...") tasks = [request_task(i) for i in range(10)] await asyncio.gather(*tasks) print("All tasks completed.") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breaking`LeakyBucketLimiter` in versions prior to 1.1.2 had a bug where it would not schedule tasks correctly after the bucket fully emptied.
fix
Upgrade to `asynciolimiter>=1.1.2` to ensure correct behavior of `LeakyBucketLimiter`.
affects: <1.1.2
gotchaIn versions prior to 1.1.1, the library might raise an assertion error if the event loop was too fast, which has since been downgraded to a warning.
fix
Upgrade to `asynciolimiter>=1.1.1` to avoid assertions and instead receive a warning for fast event loop scenarios.
affects: <1.1.1
gotchaThe `rate` parameter for all limiters (e.g., `Limiter`, `LeakyBucketLimiter`, `StrictLimiter`) expects calls *per second*. Misinterpreting this can lead to unexpected rate limiting behavior (e.g., too slow or too fast).
fix
Always pass the desired rate as a floating-point number representing calls per second. For example, to allow 10 requests in 5 seconds, use `Limiter(10/5)`, which evaluates to `Limiter(2.0)`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'asynciolimiter.AsyncLimiter'
Attempting to import `AsyncLimiter`, which belongs to a different library (`aiolimiter`), instead of `asynciolimiter`'s own limiter classes.
fix
If you intend to use `asynciolimiter`, import its specific limiter classes, such as `Limiter`, `LeakyBucketLimiter`, or `StrictLimiter`. For example: `from asynciolimiter import Limiter`.
LeakyBucketLimiter does not release tasks after periods of inactivity, or tasks are stuck waiting indefinitely.
This behavior was caused by a bug in older versions of `LeakyBucketLimiter` where it failed to schedule tasks correctly after its bucket had fully emptied.
fix
Ensure you are using `asynciolimiter` version `1.1.2` or higher. Upgrade using `pip install --upgrade asynciolimiter`.
My asynchronous tasks are being executed too slowly (or too quickly) despite setting a rate limit.
The `rate` parameter was likely set incorrectly. It expects the number of calls per second, not total calls over a period.
fix
Recalculate your desired rate as `total_calls / total_seconds`. For example, if you want 30 calls in 60 seconds, your rate should be `30/60 = 0.5`. Initialize the limiter as `Limiter(0.5)`.
Upgrade
Version history
1.2.0latest on PyPI · released Mar 18, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
28 hits · last 30 days
node
24
Perplexity
1
OpenAI (training)
1
Resources
asynciolimiter — pip install asynciolimiter · libregistry