A Quart extension to provide rate limiting support
Project description
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,
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,
@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,
@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,
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. You are very welcome to open issues or propose merge requests.
Testing
The best way to test Quart-Rate-Limiter is with Tox,
$ pip install tox
$ tox
this 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file quart_rate_limiter-0.10.0.tar.gz
.
File metadata
- Download URL: quart_rate_limiter-0.10.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87e538e50b4a0e8c3fc2d72e0c7bd4f0de193f041d70e9deb18128730e9a3e5b |
|
MD5 | efb5c7258515b5c7c9fede701e202b82 |
|
BLAKE2b-256 | 81d9c6e98db7fdf9ff31ecd8da889a58ece0d214cb12ee1b41751b751b3201e2 |
File details
Details for the file quart_rate_limiter-0.10.0-py3-none-any.whl
.
File metadata
- Download URL: quart_rate_limiter-0.10.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc9b429b856550744dd014f6f02f6d9e6b01b39b1a2092bec2fc4bbd408f902 |
|
MD5 | 10a11719e5ac045e8ef38303db76a1cc |
|
BLAKE2b-256 | f141310850a9e1940f8c014602647d929985eb88a09f15fffabef021f81a06b1 |