Skip to main content

Request limiter contains a decorator to limit the rate of http request

Project description

Request Limiter

https://img.shields.io/pypi/v/request_limiter.svg https://img.shields.io/travis/matibek/request_limiter.svg Documentation Status

Request limiter contains a decorator to limit the rate of http request

Features

  • A decorator to limit django http request

  • A strategy to limit request per interval using requester IP

Get started

Installation:

$ pip install request_limiter

Limit request to django view using a decorator:

from request_limiter import request_limiter, LimitedIntervalStrategy, django_request_limiter

@django_request_limiter
@request_limiter(strategy=LimitedIntervalStrategy(requests=10, interval=60))  # 10 request per minute
def myview(request):
    # ...

Limit the number of request to function or part of it:

from request_limiter import request_limiter, LimitedIntervalStrategy, LimitException

@request_limiter(strategy=LimitedIntervalStrategy(requests=1, interval=60))  # 1 request per minute
def awesome_work(param):
    # ...

awesome_work("test")
try:
    awesome_work("limited")  # raises LimitException
except LimitException:
    # .. handle limit exception

limiter = LimitedIntervalStrategy(requests=1, interval=60))  # 1 request per minute

def another_work(param):
    if not limiter.allow():
        return False
    # ...
    return True

another_work("job1")  # returns True
another_work("job2")  # returns False

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.1 (2020-01-14)

  • First release on PyPI.

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

request_limiter-0.1.1.tar.gz (17.3 kB view hashes)

Uploaded Source

Built Distribution

request_limiter-0.1.1-py2.py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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