{ "info": { "author": "sukobuto", "author_email": "sukobuto@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "[![PyPI pyversions](https://img.shields.io/pypi/pyversions/redis-gt.svg)](https://pypi.python.org/pypi/redis-gt/)\n[![CircleCI](https://circleci.com/gh/sukobuto/python-redis-gt.svg?style=svg)](https://circleci.com/gh/sukobuto/python-redis-gt)\n\n# Redis GT\nGlobal throttling with Redis.\n\n## installation\n\n```\npip install redis-gt\n```\n\n## usage\n\nex) request with throttle\n\n```python\nimport redis_gt\nimport requests\n\nredis_gt.Defaults.redis_url = 'redis://127.0.0.1:6379'\n\ndef get_members(**kwargs):\n throttle = redis_gt.Throttle('backend_api_call', 20)\n return throttle.run(requests.get, '/api/members/', **kwargs)\n```\n\nex) same with asyncio\n\n```python\nimport asyncio\nimport redis_gt\nimport requests\n\nredis_gt.Defaults.redis_url = 'redis://127.0.0.1:6379'\n\nasync def get_members(**kwargs):\n def _get():\n return requests.get('/api/members/', **kwargs)\n loop = asyncio.get_event_loop()\n throttle = redis_gt.AsyncThrottle('backend_api_call', 20)\n return await throttle.run(loop.run_in_executer(_get))\n```\n\n### throttling\n\n```python\nimport redis_gt\nimport time\nfrom threading import Thread\n\nredis_gt.Defaults.redis_url = 'redis://127.0.0.1:6379'\n\ndef do_something():\n time.sleep(1.0)\n\ndef do_something_with_throttle():\n # max 10 parallels\n throttle = Throttle(r, 'something', 10)\n throttle.run(do_something)\n\n# 100 tasks of each 1sec.\nthreads = [Thread(target=do_something_with_throttle) for _ in range(100)]\nfor t in threads:\n t.start()\n\n# takes about 10secs (100tasks/10para).\nfor t in threads:\n t.join()\n```\n\n### throttling with asyncio\n\n```python\nimport asyncio\nfrom redis_gt import AsyncThrottle\nimport redis\n\nasync def do_something():\n await asyncio.sleep(1.0)\n\nr = redis.StrictRedis.from_url('redis://127.0.0.1:6379')\n\n# max 10 parallels\nthrottle = AsyncThrottle(r, 'something', 10)\n\n# 100 tasks of each 1sec.\ntasks = [throttle.run(do_something()) for _ in range(100)]\nloop = asyncio.get_event_loop()\n\n# takes about 10secs (100tasks/10para).\nloop.run_until_complete(asyncio.wait(tasks))\n```\n\n### decorator\n\n```python\nfrom redis_gt import Throttle\nfrom redis_gt.decorators import throttle\nimport redis\n\nr = redis.StrictRedis.from_url('redis://127.0.0.1:6379')\n\n# for sync function\n\n@throttle('something', 10, redis=r)\ndef do_something():\n time.sleep(1.0)\n\n# 100 tasks of each 1sec.\nthreads = [Thread(target=do_something) for _ in range(100)]\nfor t in threads:\n t.start()\n\n# takes about 10secs (100tasks/10para).\nfor t in threads:\n t.join()\n\n# for async function\n@throttle('something', 10, redis=r)\nasync def do_something_async():\n await asyncio.sleep(1.0)\n\n# 100 tasks of each 1sec.\ntasks = [do_something_async() for _ in range(100)]\nloop = asyncio.get_event_loop()\n\n# takes about 10secs (100tasks/10para).\nloop.run_until_complete(asyncio.wait(tasks))\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sukobuto/python-redis-gt", "keywords": "throttle redis async", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "redis-gt", "package_url": "https://pypi.org/project/redis-gt/", "platform": "", "project_url": "https://pypi.org/project/redis-gt/", "project_urls": { "Homepage": "https://github.com/sukobuto/python-redis-gt" }, "release_url": "https://pypi.org/project/redis-gt/1.2.0/", "requires_dist": [ "redis (==2.10.6)" ], "requires_python": "", "summary": "Global throttling with Redis.", "version": "1.2.0" }, "last_serial": 4506165, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "d8415f0c5a026d089998846654ce9589", "sha256": "52b3dc817ab3f228210e408e484584718613478ea649e59396d3105dcdd078c0" }, "downloads": -1, "filename": "redis_gt-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d8415f0c5a026d089998846654ce9589", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5309, "upload_time": "2018-11-13T05:54:01", "url": "https://files.pythonhosted.org/packages/81/20/5d869bb528aca41c387656bec11d5cab48518285a8925f44b8e778d91ee7/redis_gt-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "120e13a93e2187a52d06943581b02397", "sha256": "13d469af00c9fcfb4ff0b660d575906a8fe5d0e2f7c939c6d7aa83f5bd5627f1" }, "downloads": -1, "filename": "redis_gt-1.0.0.tar.gz", "has_sig": false, "md5_digest": "120e13a93e2187a52d06943581b02397", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3058, "upload_time": "2018-11-13T05:55:41", "url": "https://files.pythonhosted.org/packages/c2/59/035b10470a429f509ecd0e6403b0be39b8ea61b261f2e800948d4c896867/redis_gt-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "9ae1ba35857f4bbd11f29485e50f15b1", "sha256": "4539d0da1e383ed3421308b9a231a5c8d1abe7ffb51b5d64f114ed70cc3b8aba" }, "downloads": -1, "filename": "redis_gt-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "9ae1ba35857f4bbd11f29485e50f15b1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5879, "upload_time": "2018-11-13T07:21:55", "url": "https://files.pythonhosted.org/packages/f0/ea/1c54e98db4536afe582e7005723aae311d2f8f891d267a5907f2b38cbbc2/redis_gt-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ebd6c735f000ffb5ca3bcc51a5d301a3", "sha256": "f6d7ed0a030dd8629546b5d0e4875d787bc4903d3475520f291d65dbb8bdee0b" }, "downloads": -1, "filename": "redis_gt-1.1.0.tar.gz", "has_sig": false, "md5_digest": "ebd6c735f000ffb5ca3bcc51a5d301a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3475, "upload_time": "2018-11-13T07:21:57", "url": "https://files.pythonhosted.org/packages/a6/a4/5c0eaad8acc1c69841541b82a8416a24273bf3b27817ba2dcbee4017e040/redis_gt-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "8dfa6391ab64b65f81cf49bc92346069", "sha256": "cd10ffb922e48870c90c26b9c59057ff8110c4132d51eac7ecdd13224fbd9cae" }, "downloads": -1, "filename": "redis_gt-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8dfa6391ab64b65f81cf49bc92346069", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5881, "upload_time": "2018-11-20T07:31:59", "url": "https://files.pythonhosted.org/packages/1e/41/7d9175d88ac021793b9d2b5dd819299464d78f540f3fd74277b23186fe4d/redis_gt-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fb5c104c81271ea226a827da104da902", "sha256": "15a05af278fcf110ca09a865b6679be966be6952f9f12e4fafed30883406f759" }, "downloads": -1, "filename": "redis_gt-1.2.0.tar.gz", "has_sig": false, "md5_digest": "fb5c104c81271ea226a827da104da902", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3468, "upload_time": "2018-11-20T07:32:01", "url": "https://files.pythonhosted.org/packages/63/c0/a8c3277e57c6cb4592f70879195dd047ec9b6f7e664d7401ad65b1bc8a73/redis_gt-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8dfa6391ab64b65f81cf49bc92346069", "sha256": "cd10ffb922e48870c90c26b9c59057ff8110c4132d51eac7ecdd13224fbd9cae" }, "downloads": -1, "filename": "redis_gt-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8dfa6391ab64b65f81cf49bc92346069", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5881, "upload_time": "2018-11-20T07:31:59", "url": "https://files.pythonhosted.org/packages/1e/41/7d9175d88ac021793b9d2b5dd819299464d78f540f3fd74277b23186fe4d/redis_gt-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fb5c104c81271ea226a827da104da902", "sha256": "15a05af278fcf110ca09a865b6679be966be6952f9f12e4fafed30883406f759" }, "downloads": -1, "filename": "redis_gt-1.2.0.tar.gz", "has_sig": false, "md5_digest": "fb5c104c81271ea226a827da104da902", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3468, "upload_time": "2018-11-20T07:32:01", "url": "https://files.pythonhosted.org/packages/63/c0/a8c3277e57c6cb4592f70879195dd047ec9b6f7e664d7401ad65b1bc8a73/redis_gt-1.2.0.tar.gz" } ] }