https://github.com/pgjones/quart-rate-limiter
Quart-Rate-Limiter is an extension for Quart to allow for rate limits to be defined and enforced on a per route basis.
https://github.com/pgjones/quart-rate-limiter
quart
Last synced: 6 months ago
JSON representation
Quart-Rate-Limiter is an extension for Quart to allow for rate limits to be defined and enforced on a per route basis.
- Host: GitHub
- URL: https://github.com/pgjones/quart-rate-limiter
- Owner: pgjones
- License: mit
- Created: 2022-04-04T14:39:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-24T11:34:35.000Z (9 months ago)
- Last Synced: 2025-04-02T11:04:43.477Z (6 months ago)
- Topics: quart
- Language: Python
- Homepage:
- Size: 71.3 KB
- Stars: 26
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
Quart-Rate-Limiter
==================|Build Status| |docs| |pypi| |python| |license|
Quart-Rate-Limiter is an extension for `Quart
`_ to allow for rate limits to be
defined and enforced on a per route basis. The 429 error response
includes a `RFC7231
`_ compliant
``Retry-After`` header and the successful responses contain headers
compliant with the `RateLimit Header Fields for HTTP
`_ 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.idRateLimiter(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
`_. You are very welcome to
open `issues `_ or
propose `merge requests
`_.Testing
~~~~~~~The best way to test Quart-Rate-Limiter is with Tox,
.. code-block:: console
$ pip install tox
$ toxthis will check the code style and run the tests.
Help
----The Quart-Rate-Limiter `documentation
`_ is the best
places to start, after that try searching `stack overflow
`_ or ask for help
`on gitter `_. If you still
can't find an answer please `open an issue
`_... |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