Request limiter contains a decorator to limit the rate of http request
Project description
Request Limiter
Request limiter contains a decorator to limit the rate of http request
Free software: MIT license
Documentation: https://request-limiter.readthedocs.io.
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
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
request_limiter-0.1.1.tar.gz
(17.3 kB
view hashes)
Built Distribution
Close
Hashes for request_limiter-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aba04280d0695ac66e1020afc52226dda7e53a61d9abc08db0fb631a51c59cb |
|
MD5 | 287a8c6ac6bfb454d3c60171e2c5e5fc |
|
BLAKE2b-256 | 48d86361e53f2cb7159b1a2c2506cc6805a2a3244724b58165804b7880535ce5 |