Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Rate Limiting

Rate Limiting Algorithm implemented using python and redis.

This can be used in two ways, as a function decorator and can be used using with keyword.

In your test.py:

from rest_framework import generics
from throttling import rate_limiter, Rat

class UserAPIView(generics.RetrieveAPIView):
    
    @rate_limiter(namespace="user", resource="post" , interval=1, max_requests=2000, unit=RateLimitUnit.HOUR)
    def create(self, request, *args, **kwargs):
        data = {}
        return Response(data, status=status.HTTP_200_OK)

So the above decorator of rate_limiter will limit the requests 2000/hour. Similarily using with keyword -

from rest_framework import generics
from throttling import rate_limiter, Rat

class UserAPIView(generics.RetrieveAPIView):
    
    def create(self, request, *args, **kwargs):
        with rate_limiter(namespace="user", resource="post" , interval=1, max_requests=2000, unit=RateLimitUnit.HOUR)
            data = {}
            return Response(data, status=status.HTTP_200_OK)

About

Rate Limiting Algorithm implemented using python and redis.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages