{"id":7015,"library":"asynciolimiter","title":"asynciolimiter","description":"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.","status":"active","version":"1.2.0","language":"en","source_language":"en","source_url":"https://github.com/bharel/asynciolimiter","tags":["asyncio","rate limiter","throttling","concurrency"],"install":[{"cmd":"pip install asynciolimiter","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Limiter","correct":"from asynciolimiter import Limiter"},{"symbol":"LeakyBucketLimiter","correct":"from asynciolimiter import LeakyBucketLimiter"},{"symbol":"StrictLimiter","correct":"from asynciolimiter import StrictLimiter"}],"quickstart":{"code":"import asyncio\nfrom asynciolimiter import Limiter\n\n# Limit to 2 requests per second (10 requests per 5 seconds)\nrate_limiter = Limiter(10/5)\n\nasync def request_task(task_id):\n    await rate_limiter.wait() # Wait for a slot to be available\n    print(f\"Task {task_id}: Request sent at {asyncio.get_event_loop().time():.2f}\")\n\nasync def main():\n    print(\"Starting rate-limited tasks...\")\n    tasks = [request_task(i) for i in range(10)]\n    await asyncio.gather(*tasks)\n    print(\"All tasks completed.\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to `asynciolimiter>=1.1.2` to ensure correct behavior of `LeakyBucketLimiter`.","message":"`LeakyBucketLimiter` in versions prior to 1.1.2 had a bug where it would not schedule tasks correctly after the bucket fully emptied.","severity":"breaking","affected_versions":"<1.1.2"},{"fix":"Upgrade to `asynciolimiter>=1.1.1` to avoid assertions and instead receive a warning for fast event loop scenarios.","message":"In 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.","severity":"gotcha","affected_versions":"<1.1.1"},{"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)`.","message":"The `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).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"If you intend to use `asynciolimiter`, import its specific limiter classes, such as `Limiter`, `LeakyBucketLimiter`, or `StrictLimiter`. For example: `from asynciolimiter import Limiter`.","cause":"Attempting to import `AsyncLimiter`, which belongs to a different library (`aiolimiter`), instead of `asynciolimiter`'s own limiter classes.","error":"ModuleNotFoundError: No module named 'asynciolimiter.AsyncLimiter'"},{"fix":"Ensure you are using `asynciolimiter` version `1.1.2` or higher. Upgrade using `pip install --upgrade asynciolimiter`.","cause":"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.","error":"LeakyBucketLimiter does not release tasks after periods of inactivity, or tasks are stuck waiting indefinitely."},{"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)`.","cause":"The `rate` parameter was likely set incorrectly. It expects the number of calls per second, not total calls over a period.","error":"My asynchronous tasks are being executed too slowly (or too quickly) despite setting a rate limit."}]}