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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 2Python 3

File details

Details for the file request_limiter-0.1.1.tar.gz.

File metadata

  • Download URL: request_limiter-0.1.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for request_limiter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0d239739026fb7ee0b606d7f9d8b9638eda54bef5dde29781cd81c43a51afb74
MD5 d1cc14ae601e3736027f2d7ebb46ed14
BLAKE2b-256 f1e64b29aaf41ad8e2ded39a3caaac3ad370c1b4f3567f6feefc182b8d220ea8

See more details on using hashes here.

File details

Details for the file request_limiter-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for request_limiter-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6aba04280d0695ac66e1020afc52226dda7e53a61d9abc08db0fb631a51c59cb
MD5 287a8c6ac6bfb454d3c60171e2c5e5fc
BLAKE2b-256 48d86361e53f2cb7159b1a2c2506cc6805a2a3244724b58165804b7880535ce5

See more details on using hashes here.

Supported by

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