quart-rate-limiter


Namequart-rate-limiter JSON
Version 0.12.1 PyPI version JSON
download
home_pageNone
SummaryA Quart extension to provide rate limiting support
upload_time2025-08-13 12:41:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Quart-Rate-Limiter
==================

|Build Status| |docs| |pypi| |python| |license|

Quart-Rate-Limiter is an extension for `Quart
<https://github.com/pgjones/quart>`_ to allow for rate limits to be
defined and enforced on a per route basis. The 429 error response
includes a `RFC7231
<https://tools.ietf.org/html/rfc7231#section-7.1.3>`_ compliant
``Retry-After`` header and the successful responses contain headers
compliant with the `RateLimit Header Fields for HTTP
<https://tools.ietf.org/html/draft-polli-ratelimit-headers-00>`_ RFC
draft.

Quickstart
----------

To add a rate limit first initialise the RateLimiting extension with
the application, and then rate limit the route,

.. code-block:: python

    app = Quart(__name__)
    rate_limiter = RateLimiter(app)

    @app.get('/')
    @rate_limit(1, timedelta(seconds=10))
    async def handler():
        ...

Simple examples
~~~~~~~~~~~~~~~

To limit a route to 1 request per second and a maximum of 20 per minute,

.. code-block:: python

    @app.route('/')
    @rate_limit(1, timedelta(seconds=1))
    @rate_limit(20, timedelta(minutes=1))
    async def handler():
        ...

Alternatively the ``limits`` argument can be used for multiple limits,

.. code-block:: python

    @app.route('/')
    @rate_limit(
        limits=[
            RateLimit(1, timedelta(seconds=1)),
            RateLimit(20, timedelta(minutes=1)),
        ],
    )
    async def handler():
        ...

To identify remote users based on their authentication ID, rather than
their IP,

.. code-block:: python

    async def key_function():
        return current_user.id

    RateLimiter(app, key_function=key_function)

The ``key_function`` is a coroutine function to allow session lookups
if appropriate.

Contributing
------------

Quart-Rate-Limiter is developed on `GitHub
<https://github.com/pgjones/quart-rate-limiter>`_. You are very welcome to
open `issues <https://github.com/pgjones/quart-rate-limiter/issues>`_ or
propose `merge requests
<https://github.com/pgjones/quart-rate-limiter/pulls>`_.

Testing
~~~~~~~

The best way to test Quart-Rate-Limiter is with Tox,

.. code-block:: console

    $ pip install tox
    $ tox

this will check the code style and run the tests.

Help
----

The Quart-Rate-Limiter `documentation
<https://quart-rate-limiter.readthedocs.io/en/latest/>`_ is the best
places to start, after that try searching `stack overflow
<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help
`on gitter <https://gitter.im/python-quart/lobby>`_. If you still
can't find an answer please `open an issue
<https://github.com/pgjones/quart-rate-limiter/issues>`_.


.. |Build Status| image:: https://github.com/pgjones/quart-rate-limiter/actions/workflows/ci.yml/badge.svg
   :target: https://github.com/pgjones/quart-rate-limiter/commits/main

.. |docs| image:: https://readthedocs.org/projects/quart-rate-limiter/badge/?version=latest&style=flat
   :target: https://quart-rate-limiter.readthedocs.io/en/latest/

.. |pypi| image:: https://img.shields.io/pypi/v/quart-rate-limiter.svg
   :target: https://pypi.python.org/pypi/Quart-Rate-Limiter/

.. |python| image:: https://img.shields.io/pypi/pyversions/quart-rate-limiter.svg
   :target: https://pypi.python.org/pypi/Quart-Rate-Limiter/

.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
   :target: https://github.com/pgjones/quart-rate-limiter/blob/main/LICENSE

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "quart-rate-limiter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "pgjones <philip.graham.jones@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/db/c4/84c073f15612ad6971e95cd541e75534de0fdeab9e59d6ff968f17622a18/quart_rate_limiter-0.12.1.tar.gz",
    "platform": null,
    "description": "Quart-Rate-Limiter\n==================\n\n|Build Status| |docs| |pypi| |python| |license|\n\nQuart-Rate-Limiter is an extension for `Quart\n<https://github.com/pgjones/quart>`_ to allow for rate limits to be\ndefined and enforced on a per route basis. The 429 error response\nincludes a `RFC7231\n<https://tools.ietf.org/html/rfc7231#section-7.1.3>`_ compliant\n``Retry-After`` header and the successful responses contain headers\ncompliant with the `RateLimit Header Fields for HTTP\n<https://tools.ietf.org/html/draft-polli-ratelimit-headers-00>`_ RFC\ndraft.\n\nQuickstart\n----------\n\nTo add a rate limit first initialise the RateLimiting extension with\nthe application, and then rate limit the route,\n\n.. code-block:: python\n\n    app = Quart(__name__)\n    rate_limiter = RateLimiter(app)\n\n    @app.get('/')\n    @rate_limit(1, timedelta(seconds=10))\n    async def handler():\n        ...\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\nAlternatively the ``limits`` argument can be used for multiple limits,\n\n.. code-block:: python\n\n    @app.route('/')\n    @rate_limit(\n        limits=[\n            RateLimit(1, timedelta(seconds=1)),\n            RateLimit(20, timedelta(minutes=1)),\n        ],\n    )\n    async def handler():\n        ...\n\nTo identify remote users based on their authentication ID, rather than\ntheir IP,\n\n.. code-block:: python\n\n    async def key_function():\n        return current_user.id\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 `GitHub\n<https://github.com/pgjones/quart-rate-limiter>`_. You are very welcome to\nopen `issues <https://github.com/pgjones/quart-rate-limiter/issues>`_ or\npropose `merge requests\n<https://github.com/pgjones/quart-rate-limiter/pulls>`_.\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\nThe Quart-Rate-Limiter `documentation\n<https://quart-rate-limiter.readthedocs.io/en/latest/>`_ is the best\nplaces to start, after that try searching `stack overflow\n<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help\n`on gitter <https://gitter.im/python-quart/lobby>`_. If you still\ncan't find an answer please `open an issue\n<https://github.com/pgjones/quart-rate-limiter/issues>`_.\n\n\n.. |Build Status| image:: https://github.com/pgjones/quart-rate-limiter/actions/workflows/ci.yml/badge.svg\n   :target: https://github.com/pgjones/quart-rate-limiter/commits/main\n\n.. |docs| image:: https://readthedocs.org/projects/quart-rate-limiter/badge/?version=latest&style=flat\n   :target: https://quart-rate-limiter.readthedocs.io/en/latest/\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://github.com/pgjones/quart-rate-limiter/blob/main/LICENSE\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Quart extension to provide rate limiting support",
    "version": "0.12.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "17c2ed5b657287b9cf5b7ef59e243f5c95265a26f78bf3f96a06b3b44d30ea5d",
                "md5": "fd0ba69f8ee50562f27332150ab96dc9",
                "sha256": "c910aa603b1eaaedb02d9475c9df1626e32b2bd936647228609d00269521f656"
            },
            "downloads": -1,
            "filename": "quart_rate_limiter-0.12.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fd0ba69f8ee50562f27332150ab96dc9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8960,
            "upload_time": "2025-08-13T12:41:25",
            "upload_time_iso_8601": "2025-08-13T12:41:25.207882Z",
            "url": "https://files.pythonhosted.org/packages/17/c2/ed5b657287b9cf5b7ef59e243f5c95265a26f78bf3f96a06b3b44d30ea5d/quart_rate_limiter-0.12.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dbc484c073f15612ad6971e95cd541e75534de0fdeab9e59d6ff968f17622a18",
                "md5": "6a650c5544aae8b8c90e1b0483b44076",
                "sha256": "9bd44b35372d0255ae716bff9aedeb041188cc3480a51a37e1f9e00b178941f3"
            },
            "downloads": -1,
            "filename": "quart_rate_limiter-0.12.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6a650c5544aae8b8c90e1b0483b44076",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9647,
            "upload_time": "2025-08-13T12:41:26",
            "upload_time_iso_8601": "2025-08-13T12:41:26.594085Z",
            "url": "https://files.pythonhosted.org/packages/db/c4/84c073f15612ad6971e95cd541e75534de0fdeab9e59d6ff968f17622a18/quart_rate_limiter-0.12.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-13 12:41:26",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "quart-rate-limiter"
}
        
Elapsed time: 2.33104s