{ "info": { "author": "hallazzang", "author_email": "hallazzang@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "================\nasyncio-throttle\n================\n\n|travis-ci| |pypi-version| |pypi-license|\n\nSimple, easy-to-use throttler for asyncio.\n\nExample\n-------\n\n.. code:: python\n\n import time\n import random\n import asyncio\n\n from asyncio_throttle import Throttler\n\n async def worker(no, throttler, n):\n for _ in range(n):\n await asyncio.sleep(random.random() * 2)\n\n async with throttler:\n print(time.time(), 'Worker #%d: Bang!' % no)\n\n async def main():\n throttler = Throttler(rate_limit=5)\n\n tasks = [\n loop.create_task(worker(no, throttler, 10))\n for no in range(5)\n ]\n await asyncio.wait(tasks)\n\n loop = asyncio.get_event_loop()\n loop.run_until_complete(main())\n loop.close()\n\nHere I limited work rate to 5/sec while there are 5 workers.\n\nInstallation\n------------\n\n.. code:: bash\n\n $ pip install asyncio-throttle\n\nUsage\n-----\n\n``asyncio_throttle.Throttler`` introduces simple APIs:\n``flush()`` and ``acquire()``. But you will not be interested in those\nbecause you can just use it within ``with`` statement and it looks nicer.\n\nFirst, create a throttler given desired rate limit.\nFor example if you want to limit rate to 500/min, you can make it as:\n\n.. code:: python\n\n from asyncio_throttle import Throttler\n\n throttler = Throttler(rate_limit=500, period=60)\n\nThen whenever you want to do some jobs which should have limited\nrate(e.g. sending request to server), Put it in ``async with`` statement:\n\n.. code:: python\n\n async with throttler:\n send_a_request()\n\nIt's that easy. ``asyncio_throttler`` can be easily integrated\nwith ``aiohttp`` too:\n\n.. code:: python\n\n async def worker(throttler, session):\n while True:\n async with throttler:\n async with session.get('http://example.com') as resp:\n do_some_job_with(await resp.text())\n\n await asyncio.sleep(0.05)\n\n.. |pypi-version| image:: https://img.shields.io/pypi/v/asyncio-throttle.svg?style=flat-square\n :target: https://pypi.python.org/pypi/asyncio-throttle/\n\n.. |pypi-license| image:: https://img.shields.io/pypi/l/asyncio-throttle.svg?style=flat-square\n :target: https://pypi.python.org/pypi/asyncio-throttle/\n\n.. |travis-ci| image:: https://travis-ci.org/hallazzang/asyncio-throttle.svg?branch=master\n :target: https://travis-ci.org/hallazzang/asyncio-throttle\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hallazzang/asyncio-throttle", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "asyncio-throttle", "package_url": "https://pypi.org/project/asyncio-throttle/", "platform": "any", "project_url": "https://pypi.org/project/asyncio-throttle/", "project_urls": { "Homepage": "https://github.com/hallazzang/asyncio-throttle" }, "release_url": "https://pypi.org/project/asyncio-throttle/0.1.1/", "requires_dist": null, "requires_python": ">=3.5", "summary": "Simple, easy-to-use throttler for asyncio", "version": "0.1.1" }, "last_serial": 3252919, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "8061c9de537150ace1022a079a4c0c6a", "sha256": "e4f38ad72275c3518b4692f777cc5e7a3285d1623f937118818955fb04d309e4" }, "downloads": -1, "filename": "asyncio_throttle-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8061c9de537150ace1022a079a4c0c6a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3547, "upload_time": "2017-10-16T03:49:36", "url": "https://files.pythonhosted.org/packages/ff/bf/c23c926ce0e01fc05723bea8ca48d233488a489634a4c4fb0b0766927420/asyncio_throttle-0.0.1-py2.py3-none-any.whl" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "70ec3a630f78c753b2271aae519ef71e", "sha256": "7678e6192a34dda2e3fba78b55520556473ae709f7867e602a9ab17358a0d582" }, "downloads": -1, "filename": "asyncio_throttle-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "70ec3a630f78c753b2271aae519ef71e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3549, "upload_time": "2017-10-16T05:08:43", "url": "https://files.pythonhosted.org/packages/ec/2c/9cdebeb636531f14274ac6853bb6cba2dd85bbbb70ca18035cf67d3c408f/asyncio_throttle-0.0.2-py2.py3-none-any.whl" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "57d03a89147ec088591a6ae9ab0d2250", "sha256": "e639d07b4f0431c3090ca7c582a6e12e695a00889eefee3206cd5b96f8910b88" }, "downloads": -1, "filename": "asyncio_throttle-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "57d03a89147ec088591a6ae9ab0d2250", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5369, "upload_time": "2017-10-16T05:21:32", "url": "https://files.pythonhosted.org/packages/3d/ef/88e1a2fd571a551d50ec20158e78e481ec050227e0ef9e23b1c8632e488e/asyncio_throttle-0.1.0-py2.py3-none-any.whl" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "d96a71bb5bcaab9ce9e9110d857d49c5", "sha256": "a01a56f3671e961253cf262918f3e0741e222fc50d57d981ba5c801f284eccfe" }, "downloads": -1, "filename": "asyncio_throttle-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d96a71bb5bcaab9ce9e9110d857d49c5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5409, "upload_time": "2017-10-16T08:13:07", "url": "https://files.pythonhosted.org/packages/c2/b4/0b6bd59151d979c3d9902d9b35c992aa1e55ab0f60d8b0b7fbbf61dd3138/asyncio_throttle-0.1.1-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d96a71bb5bcaab9ce9e9110d857d49c5", "sha256": "a01a56f3671e961253cf262918f3e0741e222fc50d57d981ba5c801f284eccfe" }, "downloads": -1, "filename": "asyncio_throttle-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d96a71bb5bcaab9ce9e9110d857d49c5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 5409, "upload_time": "2017-10-16T08:13:07", "url": "https://files.pythonhosted.org/packages/c2/b4/0b6bd59151d979c3d9902d9b35c992aa1e55ab0f60d8b0b7fbbf61dd3138/asyncio_throttle-0.1.1-py3-none-any.whl" } ] }