Fast ratelimit implementation with django caches
Project description
django-fast-ratelimit
Django-fast-ratelimit provides a secure and fast ratelimit facility based on the django caching framework.
Installation
pip install django-fast-ratelimit
Note: pip >= 19 is required, I use the novel pyproject.toml method
usage
Decorator:
import ratelimit
@ratelimit.decorate(key="ip", rate="1/s")
def expensive_func(request):
# how many ratelimits request limiting
if request.ratelimit["request_limit"] > 0:
# reschedule with end of rate epoch
return request_waiting(request.ratelimit["end"])
blocking Decorator (raises RatelimitError):
import ratelimit
@ratelimit.decorate(key="ip", rate="1/s", block=True, methods=ratelimit.UNSAFE)
def expensive_func(request):
# how many ratelimits request limiting
if request.ratelimit["end"] > 0:
decorate View (requires group):
import ratelimit
from django.views.generic import View
from django.utils.decorators import method_decorator
@method_decorator(ratelimit.decorate(
key="ip", rate="1/s", block=True, methods=ratelimit.SAFE, group="required"
), name="dispatch")
class FooView(View):
...
manual
import ratelimit
def func(request):
ratelimit.get_ratelimit(key="ip", rate="1/s", request=request, group="123")
# or only for GET
ratelimit.get_ratelimit(
key="ip", rate="1/s", request=request, group="123", methods="GET"
)
# also simple calls possible (note: key in bytes format)
ratelimit.get_ratelimit(
key=b"abc", rate="1/s", group="123"
)
TODO
- more documentation
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
Built Distribution
Close
Hashes for django-fast-ratelimit-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 301cc8c8501351b1fb2f78e8f72b13d2d28fb0edea0662fad8f15f4c3b6c479f |
|
MD5 | 766e886ef834d785b91b692d974dc4dd |
|
BLAKE2b-256 | 78e0471a33a99264937687d86eb93a8649b442f33b59bcdf1f4a8e21cd7fced5 |
Close
Hashes for django_fast_ratelimit-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c372c6158b6b96c6bff88ba3becc145ba3bb3a18a65677e70deb283228dfb89 |
|
MD5 | e0b89b5228010b612acd716aaaac3678 |
|
BLAKE2b-256 | 097eacd42651898dfe3c10d1626023aa00b7adb666227dd8686a860d0a5c62d2 |