pyrate_limiter.bucket module#
Implement this class to create a workable bucket for Limiter to use
- class pyrate_limiter.bucket.AbstractBucket(maxsize=0, **_kwargs)#
Bases:
abc.ABC
Base bucket interface
- abstract get(number)#
Get items, remove them from the bucket in the FIFO order, and return the number of items that have been removed
- Return type
- inspect_expired_items(time)#
Find how many items in bucket that have slipped out of the time-window
- lock_acquire()#
Acquire a lock prior to beginning a new transaction, if needed
- lock_release()#
Release lock following a transaction, if needed
- maxsize()#
Return the maximum size of the bucket, ie the maximum number of item this bucket can hold
- Return type
- abstract put(item)#
Put an item (typically the current time) in the bucket Return 1 if successful, else 0
- Return type
- class pyrate_limiter.bucket.MemoryListBucket(maxsize=0, **_kwargs)#
Bases:
pyrate_limiter.bucket.AbstractBucket
A bucket that resides in memory using python’s List
- flush()#
Flush/reset bucket
- get(number)#
Get items, remove them from the bucket in the FIFO order, and return the number of items that have been removed
- Return type
- put(item)#
Put an item (typically the current time) in the bucket Return 1 if successful, else 0
- class pyrate_limiter.bucket.MemoryQueueBucket(maxsize=0, **_kwargs)#
Bases:
pyrate_limiter.bucket.AbstractBucket
A bucket that resides in memory using python’s built-in Queue class
- flush()#
Flush/reset bucket
- get(number)#
Get items, remove them from the bucket in the FIFO order, and return the number of items that have been removed
- Return type
- put(item)#
Put an item (typically the current time) in the bucket Return 1 if successful, else 0
- class pyrate_limiter.bucket.RedisBucket(maxsize=0, redis_pool=None, bucket_name=None, identity=None, expire_time=None, **_kwargs)#
Bases:
pyrate_limiter.bucket.AbstractBucket
A bucket backed by a Redis instance
- flush()#
Flush/reset bucket
- get(number)#
Get items, remove them from the bucket in the FIFO order, and return the number of items that have been removed
- Return type
- get_connection()#
Obtain a connection from redis pool
- get_pipeline()#
Using redis pipeline for batch operation
- put(item)#
Put an item (typically the current time) in the bucket Return 1 if successful, else 0
- class pyrate_limiter.bucket.RedisClusterBucket(maxsize=0, redis_pool=None, bucket_name=None, identity=None, expire_time=None, **_kwargs)#
Bases:
pyrate_limiter.bucket.RedisBucket
A bucket backed by a Redis cluster
- get_connection()#
Obtain a connection from redis pool