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.
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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2912110f2e4044484e402c6882472226bc9ead86efa43157dfb29fa96c23e69d |
|
MD5 | 3d212fbc9bacdfd771b4f98e9ec0ede6 |
|
BLAKE2b-256 | 342e4fe8fe9e5fa8c1033ce895ac5a1cc1f2eefb1410b7029af8e2d9abdcc2cd |
Close
Hashes for django_fast_ratelimit-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 507faa5010ac68564c795df6a51f14c0a26d58716a19b7b6b1d78d337f12de12 |
|
MD5 | 454b16d002d333ed786b3a878afdee5d |
|
BLAKE2b-256 | 4f161f91e9c9e5bba3809a5c85e7ec16ebbae3768de34d60a9fb622272d5b85e |