Skip to main content

A Quart extension to provide rate limiting support

Project description

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,

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quart_rate_limiter-0.12.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

quart_rate_limiter-0.12.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file quart_rate_limiter-0.12.0.tar.gz.

File metadata

  • Download URL: quart_rate_limiter-0.12.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quart_rate_limiter-0.12.0.tar.gz
Algorithm Hash digest
SHA256 951dc3d6636fc0ce51859228d5cdcbd0db7a1287a1efe92480a0e53183a82612
MD5 ac3834b55bd27cb28017d7477550b710
BLAKE2b-256 ab50e45c5fd368bcd0f37465a98acab44a4f42243449f61e70a0a8cf0ef8648a

See more details on using hashes here.

Provenance

The following attestation bundles were made for quart_rate_limiter-0.12.0.tar.gz:

Publisher: publish.yml on pgjones/quart-rate-limiter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quart_rate_limiter-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quart_rate_limiter-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f538cac8fab734ec11e817ecb318e448ddb071e41d7254ef6ad288fc883871c4
MD5 ff8b3ee5aa27a362e71c5b94ca6d7f8b
BLAKE2b-256 01ea28628dc8445a3a820ee98c39e0c3c6e961db92bfa993e6e744f9e59fd216

See more details on using hashes here.

Provenance

The following attestation bundles were made for quart_rate_limiter-0.12.0-py3-none-any.whl:

Publisher: publish.yml on pgjones/quart-rate-limiter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page