A threadsafe sqlite worker.
This library implements a thread pool pattern with sqlite3 being the desired output.
sqllite3 implementation lacks the ability to safely modify the sqlite3 database with multiple threads outside of the compile time options. This library was created to address this by bringing the responsibility of managing the threads to the python layer and is agnostic to the server setup of sqlite3.
Install
You can use pip:
sudo pip install sqlite3worker
You can use setup.py:
sudo python setup.py install
Alternatively one can use pip to install directly from the git repository without having to clone first:
sudo pip install git+https://github.com/dashawn888/sqlite3worker#egg=sqlite3worker
One may also use pip to install on a per-user basis without requiring super-user permissions:
pip install --user git+https://github.com/dashawn888/sqlite3worker#egg=sqlite3worker
Example
from sqlite3worker import Sqlite3Worker
sql_worker = Sqlite3Worker("/tmp/test.sqlite")
sql_worker.execute("CREATE TABLE tester (timestamp DATETIME, uuid TEXT)")
sql_worker.execute("INSERT into tester values (?, ?)", ("2010-01-01 13:00:00", "bow"))
sql_worker.execute("INSERT into tester values (?, ?)", ("2011-02-02 14:14:14", "dog"))
results = sql_worker.execute("SELECT * from tester")
for timestamp, uuid in results:
print(timestamp, uuid)
sql_worker.close()
When to use sqlite3worker
If you have multiple threads all needing to write to a sqlite3 database this library will serialize the sqlite3 write requests.
When NOT to use sqlite3worker
If your code DOES NOT use multiple threads then you don’t need to use a thread safe sqlite3 implementation.
If you need multiple applications to write to a sqlite3 db then sqlite3worker will not protect you from corrupting the data.
Internals
The library creates a queue to manage multiple queries sent to the database. Instead of directly calling the sqlite3 interface, you will call the Sqlite3Worker which inserts your query into a Queue.Queue() object. The queries are processed in the order that they are inserted into the queue (first in, first out). In order to ensure that the multiple threads are managed in the same queue, you will need to pass the same Sqlite3Worker object to each thread.
Python docs for sqlite3
Metadata
Release files for sqlite3worker 1.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sqlite3worker-1.1.7.tar.gz | 6.0 kB | Without provenance | Details |
Release files / sqlite3worker-1.1.7.tar.gz
| Download URL | sqlite3worker-1.1.7.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
465980404cb843ed10e77475418ab4adb1320bbf1be2455425bed6af1d11dd4d
|
|
BLAKE2b-256 checksum How to use checksums |
df992bf5b9423450fe6d81f319b116aac3ced1bc66fbbf3d97d1e4098bf16250
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sqlite3worker 1.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.