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.

Files for request_limiter, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size request_limiter-0.1.1-py2.py3-none-any.whl (6.4 kB) File type Wheel Python version 3.7 Upload date Hashes View
Filename, size request_limiter-0.1.1.tar.gz (17.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page