{ "info": { "author": "P G Jones", "author_email": "philip.graham.jones@googlemail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Quart-Rate-Limiter\n==================\n\n|Build Status| |pypi| |python| |license|\n\nQuart-Rate-Limiter is an extension for `Quart\n`_ to allow for rate limits to be\ndefined and enforced on a per route basis. The 429 error response\nincludes a `RFC7231\n`_ compliant\n``Retry-After`` header and the successful responses contain headers\ncompliant with the `RateLimit Header Fields for HTTP\n`_ RFC\ndraft.\n\nUsage\n-----\n\nTo add a rate limit first initialise the RateLimiting extension with\nthe application,\n\n.. code-block:: python\n\n app = Quart(__name__)\n rate_limiter = RateLimiter(app)\n\nor via the factory pattern,\n\n.. code-block:: python\n\n rate_limiter = RateLimiter()\n\n def create_app():\n app = Quart(__name__)\n rate_limiter.init_app(app)\n return app\n\nNow this is done you can apply rate limits to any route by using the\n``rate_limit`` decorator,\n\n.. code-block:: python\n\n @app.route('/')\n @rate_limit(1, timedelta(seconds=10))\n async def handler():\n ...\n\nTo alter the identification of remote users you can either supply a\nglobal key function when initialising the extension, or on a per route\nbasis.\n\nBy default rate limiting information (TATs) will be stored in memory,\nwhich will result in unexpected behaviour if multiple workers are\nused. To solve this a redis store can be used by installing the\n``redis`` extra (``pip install quart-rate-limiter[redis]``) and then\nusing as so,\n\n.. code-block:: python\n\n from quart_rate_limiter.redis_store import RedisStore\n\n redis_store = RedisStore(address)\n RateLimiter(app, store=redis_store)\n\nThis store uses `aioredis `_,\nand any extra keyword arguments passed to the ``RedisStore``\nconstructor will be passed to the aioredis ``create_redis`` function.\n\nA custom store is possible, see the ``RateLimiterStoreABC`` for the\nrequired interface.\n\nSimple examples\n~~~~~~~~~~~~~~~\n\nTo limit a route to 1 request per second and a maximum of 20 per minute,\n\n.. code-block:: python\n\n @app.route('/')\n @rate_limit(1, timedelta(seconds=1))\n @rate_limit(20, timedelta(minutes=1))\n async def handler():\n ...\n\nTo identify remote users based on the forwarded IP, rather than the\ndirect IP (if behind a load balancer),\n\n.. code-block:: python\n\n async def key_function():\n # Return the X-Forwarded-For as the user-agent identifier,\n # unless it isn't present (direct connection).\n return request.headers.get(\"X-Forwarded-For\", request.remote_addr)\n\n RateLimiter(app, key_function=key_function)\n\nThe ``key_function`` is a coroutine function to allow session lookups\nif appropriate.\n\nContributing\n------------\n\nQuart-Rate-Limiter is developed on `GitLab\n`_. You are very welcome to\nopen `issues `_ or\npropose `merge requests\n`_.\n\nTesting\n~~~~~~~\n\nThe best way to test Quart-Rate-Limiter is with Tox,\n\n.. code-block:: console\n\n $ pip install tox\n $ tox\n\nthis will check the code style and run the tests.\n\nHelp\n----\n\nThis README is the best place to start, after that try opening an\n`issue `_.\n\n\n.. |Build Status| image:: https://gitlab.com/pgjones/quart-rate-limiter/badges/master/build.svg\n :target: https://gitlab.com/pgjones/quart-rate-limiter/commits/master\n\n.. |pypi| image:: https://img.shields.io/pypi/v/quart-rate-limiter.svg\n :target: https://pypi.python.org/pypi/Quart-Rate-Limiter/\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/quart-rate-limiter.svg\n :target: https://pypi.python.org/pypi/Quart-Rate-Limiter/\n\n.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg\n :target: https://gitlab.com/pgjones/quart-rate-limiter/blob/master/LICENSE\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/pgjones/quart-rate-limiter/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Quart-Rate-Limiter", "package_url": "https://pypi.org/project/Quart-Rate-Limiter/", "platform": "", "project_url": "https://pypi.org/project/Quart-Rate-Limiter/", "project_urls": { "Homepage": "https://gitlab.com/pgjones/quart-rate-limiter/" }, "release_url": "https://pypi.org/project/Quart-Rate-Limiter/0.1.0/", "requires_dist": [ "Quart (>=0.7)", "aioredis ; extra == 'redis'" ], "requires_python": ">=3.7.0", "summary": "A Quart extension to provide rate limiting support.", "version": "0.1.0" }, "last_serial": 5832813, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "8936aea94b54fd291a9aaa97deb6d599", "sha256": "1c9ace5e0f54421285ee8fe0e6d8ad2b6327b453679d7cebe8cc0822b048336c" }, "downloads": -1, "filename": "Quart_Rate_Limiter-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8936aea94b54fd291a9aaa97deb6d599", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 7431, "upload_time": "2019-09-15T19:08:01", "url": "https://files.pythonhosted.org/packages/bf/42/d07662449eaaf1967fa3760df43b9c84ffeb275822db51e5ffd6704643a1/Quart_Rate_Limiter-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "14a9c59c4365f6024c1cbc441bc69614", "sha256": "2443331ce1612c76ae8fb96d1997e11dbdb3cf52f69e76478d0e32e7789ef94b" }, "downloads": -1, "filename": "Quart-Rate-Limiter-0.1.0.tar.gz", "has_sig": false, "md5_digest": "14a9c59c4365f6024c1cbc441bc69614", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 7596, "upload_time": "2019-09-15T19:08:04", "url": "https://files.pythonhosted.org/packages/95/06/f045392f1c3f32dbf4576f12cdbf3283548197dc48d2f78d3bf11b4a8712/Quart-Rate-Limiter-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8936aea94b54fd291a9aaa97deb6d599", "sha256": "1c9ace5e0f54421285ee8fe0e6d8ad2b6327b453679d7cebe8cc0822b048336c" }, "downloads": -1, "filename": "Quart_Rate_Limiter-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8936aea94b54fd291a9aaa97deb6d599", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7.0", "size": 7431, "upload_time": "2019-09-15T19:08:01", "url": "https://files.pythonhosted.org/packages/bf/42/d07662449eaaf1967fa3760df43b9c84ffeb275822db51e5ffd6704643a1/Quart_Rate_Limiter-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "14a9c59c4365f6024c1cbc441bc69614", "sha256": "2443331ce1612c76ae8fb96d1997e11dbdb3cf52f69e76478d0e32e7789ef94b" }, "downloads": -1, "filename": "Quart-Rate-Limiter-0.1.0.tar.gz", "has_sig": false, "md5_digest": "14a9c59c4365f6024c1cbc441bc69614", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7.0", "size": 7596, "upload_time": "2019-09-15T19:08:04", "url": "https://files.pythonhosted.org/packages/95/06/f045392f1c3f32dbf4576f12cdbf3283548197dc48d2f78d3bf11b4a8712/Quart-Rate-Limiter-0.1.0.tar.gz" } ] }