pyrate_limiter.sqlite_bucket module#
- class pyrate_limiter.sqlite_bucket.FileLockSQLiteBucket(**kwargs)#
Bases:
pyrate_limiter.sqlite_bucket.SQLiteBucket
Bucket backed by a SQLite database and file lock. Suitable for usage from multiple processes with no shared state. Requires installing [py-filelock](https://py-filelock.readthedocs.io).
The file lock is reentrant and shared across buckets, allowing a process to access multiple buckets at once.
- class pyrate_limiter.sqlite_bucket.SQLiteBucket(maxsize=0, identity=None, path=PosixPath('/tmp/pyrate_limiter.sqlite'), **kwargs)#
Bases:
pyrate_limiter.bucket.AbstractBucket
Bucket backed by a SQLite database. Will be stored in the system temp directory by default.
Notes on concurrency:
Thread-safe
Safe for use with multiple child processes with a shared initial state and using the same
Limiter
object, e.g. if created withProcessPoolExecutor
ormultiprocessing.Process
.For other usage with multiple processes, see
FileLockSQLiteBucket
.Transactions are locked at the bucket level, but not at the connection or database level.
The default isolation level is used (autocommit).
Multitple buckets may be used in parallel, but a given bucket will only be used by one thread/process at a time.
- Parameters
- close()#
Close the database connection
- property connection#
Create a database connection and initialize the table, if it hasn’t already been done. This is safe to leave open, but may be manually closed with
close()
, if needed.- Return type
- flush()#
Flush/reset bucket
- get(number=1)#
Get items and remove them from the bucket in the FIFO fashion. Return the number of items that have been removed.
- Return type
- lock_acquire()#
Acquire a lock prior to beginning a new transaction
- lock_release()#
Release lock following a transaction