tomasbasham / ratelimit

API Rate Limit Decorator
MIT License
768 stars 159 forks source link

How to use set up calls/period with class attributes #25

Open sirhc78 opened 6 years ago

sirhc78 commented 6 years ago

Hi,

I am trying to use Ratelimit in a class.

class test : 
 def __init__(self,maxcalls,period)
    self.maxcalls =maxcalls
    self.period=period

 @limits(calls=self.maxcalls, period=self.period)
 def todo:
    pass

But I can't. What can be my solutions ?

Thanks

jonespm commented 6 years ago

You can probably do it in the class constructor. I don't know how or if it's possible to do it on the class function. This is the only place you're defining these values anyway.

from ratelimit import limits

class test: 
    def __init__ (self, maxcalls, period):
        self.todo = limits(calls=maxcalls, period=period)(self._todo)

    def _todo(self):
        pass