pyrate_limiter.abstracts package¶
- class pyrate_limiter.abstracts.AbstractBucket¶
Bases:
ABCBase bucket interface Assumption: len(rates) always > 0 TODO: allow empty rates
- close()¶
Release any resources held by the bucket.
Subclasses may override this method to perform any necessary cleanup (e.g., closing files, network connections, or releasing locks) when the bucket is no longer needed.
- Return type:
- failing_rate = None¶
- abstract flush()¶
Flush the whole bucket - Must remove failing-rate after flushing
- is_async = None¶
- abstract leak(current_timestamp=None)¶
leaking bucket - removing items that are outdated
- limiter_lock()¶
An additional lock to be used by Limiter in-front of the thread lock. Intended for multiprocessing environments where a thread lock is insufficient.
- now()¶
Retrieve current timestamp from the clock backend.
- abstract peek(index)¶
Peek at the rate-item at a specific index in latest-to-earliest order NOTE: The reason we cannot peek from the start of the queue(earliest-to-latest) is we can’t really tell how many outdated items are still in the queue
- abstract put(item)¶
Put an item (typically the current time) in the bucket return true if successful, otherwise false
- property rates¶
- class pyrate_limiter.abstracts.BucketAsyncWrapper(bucket)¶
Bases:
AbstractBucketBucketAsyncWrapper is a wrapping over any bucket that turns a async/synchronous bucket into an async one
- async count()¶
Count number of items in the bucket
- property failing_rate¶
- is_async = True¶
- async leak(current_timestamp=None)¶
leaking bucket - removing items that are outdated
- Return type:
- async peek(index)¶
Peek at the rate-item at a specific index in latest-to-earliest order NOTE: The reason we cannot peek from the start of the queue(earliest-to-latest) is we can’t really tell how many outdated items are still in the queue
- async put(item)¶
Put an item (typically the current time) in the bucket return true if successful, otherwise false
- property rates¶
- class pyrate_limiter.abstracts.BucketFactory¶
Bases:
ABCAsbtract BucketFactory class. It is reserved for user to implement/override this class with his own bucket-routing/creating logic
- create(bucket_class, *args, **kwargs)¶
Creating a bucket dynamically
- Return type:
- abstract get(item)¶
Get the corresponding bucket to this item
- Return type:
Union[AbstractBucket,Awaitable[AbstractBucket]]
- get_buckets()¶
Iterator over all buckets in the factory
- Return type:
- property leak_interval¶
Retrieve leak-interval from inner Leaker task
- schedule_leak(new_bucket)¶
Schedule all the buckets’ leak, reset bucket’s failing rate
- Return type:
- class pyrate_limiter.abstracts.Duration(value)¶
Bases:
EnumInterval helper class
- DAY = 86400000¶
- HOUR = 3600000¶
- MINUTE = 60000¶
- SECOND = 1000¶
- WEEK = 604800000¶
- class pyrate_limiter.abstracts.Rate(limit, interval)¶
Bases:
objectRate definition.
- Parameters:
- interval¶
- limit¶
- class pyrate_limiter.abstracts.RateItem(name, timestamp, weight=1)¶
Bases:
objectRateItem is a wrapper for bucket to work with
- name¶
- timestamp¶
- weight¶