How to use the ratelimitingfilter.ratelimitingfilter.RateLimitingFilter function in ratelimitingfilter

To help you get started, we’ve selected a few ratelimitingfilter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wkeeling / ratelimitingfilter / ratelimitingfilter / ratelimitingfilter.py View on Github external
def __init__(self, rate=1, per=30, burst=1, **kwargs):
        """Initialise an instance of the RateLimitingFilter allowing a default rate of 1 record
        every 30 seconds when no arguments are supplied.

        :param rate:
            The number of records to restrict to, per the specified time interval. Default 1.
        :param per:
            The number of seconds during which 'rate' records may be sent. Default 30.
        :param burst:
            The maximum number of records that can be sent before rate limiting kicks in.
        :param kwargs:
            Additional config options that can be passed to the filter.
        """
        super(RateLimitingFilter, self).__init__()

        self.rate = rate
        self.per = per
        self.burst = burst

        self._default_bucket = TokenBucket(rate, per, burst)
        self._substr_buckets = None
        self._auto_buckets = None

        if 'match' in kwargs:
            if kwargs['match'] == 'auto':
                self._auto_buckets = defaultdict(partial(TokenBucket, rate, per, burst))
            else:
                self._substr_buckets = {}
                for s in kwargs['match']:
                    # Create a new token bucket for each substring

ratelimitingfilter

A rate limiting filter for the Python logging system

MIT
Latest version published 3 years ago

Package Health Score

49 / 100
Full package analysis

Similar packages