tomasbasham / ratelimit

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

User Defined Ratelimit Time Period at Class level #56

Closed johnbumgarner closed 3 years ago

johnbumgarner commented 3 years ago

I have a use case where I would like to preset a base level time period as a Class argument.

Some far I haven't been able to figure out the correct methods to allow this argument to be passed within the Class.

class MyClass(object):

    timeout_period = 0

    def __init__(self, search_string='', rate_limit_timeout_period=60):
        """
        self._word = search_string
        timeout_period = rate_limit_timeout_period

    @on_exception(expo, RateLimitException, max_tries=10)
    @limits(calls=5, period=timeout_period)
    def function_to_ratelimit(self):
      # more code here

In the code above the timeout period is always ZERO. How can I pass the Class argument rate_limit_timeout_period to @limits(calls=5, period=timeout_period)?

Thanks in advance for any assistance.