{"id":6472,"library":"throttler","title":"Throttler","description":"Throttler is a zero-dependency Python package designed for easy rate limiting and concurrency control, with robust support for asyncio. It provides flexible context managers and decorators to manage the frequency and simultaneity of operations. The library is actively maintained, with version 1.2.3 being the latest, and receives updates to support newer Python versions and improve performance.","status":"active","version":"1.2.3","language":"en","source_language":"en","source_url":"https://github.com/uburuntu/throttler","tags":["asyncio","throttling","rate-limiting","concurrency","async"],"install":[{"cmd":"pip install throttler","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Throttler","correct":"from throttler import Throttler"},{"symbol":"throttle","correct":"from throttler import throttle"},{"symbol":"ThrottlerSimultaneous","correct":"from throttler import ThrottlerSimultaneous"},{"symbol":"throttle_simultaneous","correct":"from throttler import throttle_simultaneous"},{"symbol":"ExecutionTimer","correct":"from throttler import ExecutionTimer"},{"symbol":"execution_timer","correct":"from throttler import execution_timer"}],"quickstart":{"code":"import asyncio\nfrom throttler import Throttler\nimport time\n\nasync def limited_task(task_id, throttler):\n    async with throttler:\n        print(f\"{time.time():.2f}: Task {task_id} executing...\")\n\nasync def main():\n    # Limit to 3 calls per second\n    rate_limiter = Throttler(rate_limit=3, period=1.0)\n    tasks = [limited_task(i, rate_limiter) for i in range(10)]\n    await asyncio.gather(*tasks)\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates using the `Throttler` context manager to rate-limit asynchronous tasks to 3 executions per second. The `asyncio.run()` function is used to execute the main asynchronous function."},"warnings":[{"fix":"Upgrade to Python 3.8+ or pin `throttler` to a version prior to 1.2.3.","message":"Version 1.2.3 dropped official support for Python 3.6 and 3.7. Users on these Python versions should remain on `throttler<1.2.3` to avoid compatibility issues.","severity":"breaking","affected_versions":">=1.2.3"},{"fix":"Ensure usage is within an `async` function and an `asyncio` event loop (e.g., using `asyncio.run()`, `await`).","message":"Both `Throttler` and `ThrottlerSimultaneous` are asynchronous context managers or decorators. They must be used within an `async` function and typically require an `asyncio` event loop to run correctly. Attempting to use them synchronously will result in runtime errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Understand the sliding window behavior; if a strict fixed window is required, consider implementing custom logic or exploring other libraries.","message":"The `Throttler` (for rate limiting) implements a sliding window mechanism. This means it tracks the exact timestamps of previous executions within the `period`. If you expect a fixed window behavior, this might lead to different throttling patterns than anticipated.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to `throttler>=1.2.1` to benefit from improved argument validation and more graceful error handling.","message":"Prior to version 1.2.1, argument validation for `Throttler` and related classes might have been less robust, potentially leading to unexpected behavior with invalid input values or types. Version 1.2.1 introduced explicit checks for these.","severity":"gotcha","affected_versions":"<1.2.1"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}