{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "\n[![CircleCI](https://circleci.com/gh/closeio/limitlion.svg?style=svg)](https://circleci.com/gh/closeio/limitlion)\n[![Maintainability](https://api.codeclimate.com/v1/badges/defea1a895913b923112/maintainability)](https://codeclimate.com/github/closeio/limitlion/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/defea1a895913b923112/test_coverage)](https://codeclimate.com/github/closeio/limitlion/test_coverage)\n# LimitLion\n\nA token bucket rate limiting throttle using Redis as the backend. Inspired by\nStripe's [Scaling your API with rate limiters](https://stripe.com/blog/rate-limiters)\nblog post. Can be used to control processing rates from one to many processes.\nPotential implementations include protecting databases from high processing rates,\norchestrating queue consumer processes, or enforcing HTTP request rate limits.\n\nFollowing is a simple example of a throttle named `test` that allows `5` requests per second (RPS) with\na burst factor of `2` using a `8` second window and requesting `1` token (default)\nfor each unit of work. Look in the `examples` directory for more.\n\n```py\nredis = redis.Redis('localhost', 6379)\nthrottle_configure(redis)\nwhile True:\n allowed, tokens, sleep = throttle('test', 5, 2, 8)\n if allowed:\n print ('Do work here')\n else:\n print ('Sleeping {}'.format(sleep))\n time.sleep(sleep)\n```\n\n## Design\nThe rate limiting logic uses a classic token bucket algorithm but is implemented\nentirely as a Lua Redis script. It leverages the Redis [TIME](https://redis.io/commands/time)\ncommand which ensures fair microsecond resolution across all callers independent\nof the caller's clock. Note that buckets start and end on whole seconds.\n\nRedis 3.2+ is required because `replicate_commands()` is used to support using\nthe `TIME` command in a Lua script.\n\n## Configuring\nDefault values for RPS, burst factor and window size are supplied to the throttle\nLua script. The Lua script creates a `throttle:[throttle name]:knobs` hash with\nthese values if it does not yet exist in Redis. The script then uses the values\nin that `knobs` hash for the token bucket calculations. Each call also sets the\nTTL for the `knobs` key to 7 days so it will remain in Redis as long as the\nthrottle has been active in the last week.\n\nSince these settings are stored in Redis a separate process can be used to adjust\nthem on the fly. This could simply be manually issuing the Redis command to\nchange the RPS or a more sophisicated process that polls Prometheus metrics to\ndetermine the current load on your database and adjust the RPS accordingly.\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": "http://github.com/closeio/limitlion", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "limitlion", "package_url": "https://pypi.org/project/limitlion/", "platform": "any", "project_url": "https://pypi.org/project/limitlion/", "project_urls": { "Homepage": "http://github.com/closeio/limitlion" }, "release_url": "https://pypi.org/project/limitlion/0.9.2/", "requires_dist": [ "redis (==2.10.6)" ], "requires_python": "", "summary": "Close LimitLion", "version": "0.9.2" }, "last_serial": 5567601, "releases": { "0.9.1": [ { "comment_text": "", "digests": { "md5": "4f039b5bcf90992878348afa5ef9cb8c", "sha256": "06855eaf37b3a2a120759df21acde91256a2c960be19cb34fd1953c247ca41e3" }, "downloads": -1, "filename": "limitlion-0.9.1-py2-none-any.whl", "has_sig": false, "md5_digest": "4f039b5bcf90992878348afa5ef9cb8c", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6200, "upload_time": "2019-05-01T08:50:12", "url": "https://files.pythonhosted.org/packages/73/8a/43980b04cf99c5c712454d5a8f77af7ad9d225ca8a05b1a2158e7cb848e7/limitlion-0.9.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8847979a786489e7799f8cfcc356b321", "sha256": "3c81e3eef9e367a1de9a7995286bbdf6cd722c0b7486c4ca10919a8913742eb5" }, "downloads": -1, "filename": "limitlion-0.9.1.tar.gz", "has_sig": false, "md5_digest": "8847979a786489e7799f8cfcc356b321", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5928, "upload_time": "2019-05-01T08:50:09", "url": "https://files.pythonhosted.org/packages/72/8b/7b5741f08b744710c1efc6d64a579afd393768d64acfccb932f543ff8e9d/limitlion-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "7e2b8bfb12f8c5b572ed88c14c842774", "sha256": "ac33e681e06427b672bfe3776509b48587433cb78b7833c27e8b75f608b0f93a" }, "downloads": -1, "filename": "limitlion-0.9.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7e2b8bfb12f8c5b572ed88c14c842774", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9778, "upload_time": "2019-07-22T14:00:57", "url": "https://files.pythonhosted.org/packages/26/e9/a1e1319f262271ab946b053ba64ae0ccd484adc194646081e85b4a37f511/limitlion-0.9.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "77e3be7c6f851e6310959854750cadd7", "sha256": "b731e0bf5d09fb4b3fa2014a232bf1bac0f13a1fefb79847cedb4ed651a5a12a" }, "downloads": -1, "filename": "limitlion-0.9.2.tar.gz", "has_sig": false, "md5_digest": "77e3be7c6f851e6310959854750cadd7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7404, "upload_time": "2019-07-22T14:00:58", "url": "https://files.pythonhosted.org/packages/a0/85/4fa6c7feb5c25e686cbccfb43da07b4bef89837e45464954da24447b8e3a/limitlion-0.9.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7e2b8bfb12f8c5b572ed88c14c842774", "sha256": "ac33e681e06427b672bfe3776509b48587433cb78b7833c27e8b75f608b0f93a" }, "downloads": -1, "filename": "limitlion-0.9.2-py3-none-any.whl", "has_sig": false, "md5_digest": "7e2b8bfb12f8c5b572ed88c14c842774", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9778, "upload_time": "2019-07-22T14:00:57", "url": "https://files.pythonhosted.org/packages/26/e9/a1e1319f262271ab946b053ba64ae0ccd484adc194646081e85b4a37f511/limitlion-0.9.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "77e3be7c6f851e6310959854750cadd7", "sha256": "b731e0bf5d09fb4b3fa2014a232bf1bac0f13a1fefb79847cedb4ed651a5a12a" }, "downloads": -1, "filename": "limitlion-0.9.2.tar.gz", "has_sig": false, "md5_digest": "77e3be7c6f851e6310959854750cadd7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7404, "upload_time": "2019-07-22T14:00:58", "url": "https://files.pythonhosted.org/packages/a0/85/4fa6c7feb5c25e686cbccfb43da07b4bef89837e45464954da24447b8e3a/limitlion-0.9.2.tar.gz" } ] }