Execute simple SQLite statements that are multithreaded/multiprocess safe
Project description
msqlite
Multi-threaded/multi-process support on top of SQLite. The intent is to ensure a SQL statement
will get executed, even if other threads or processes are trying to access the DB. Avoids
database is locked
issues.
No additional package dependencies beyond regular Python.
Intended for relatively simple SQL statement execution. Locks the DB file on every access, with built-in retry mechanism.
Even though the DB is locked on every access, typically simple writes are much less than 1 second (more like 1 mS), so this latency is still usable for many use cases.
import time
from pathlib import Path
from msqlite import MSQLite
db_path = Path("temp", "example.sqlite")
db_path.parent.mkdir(exist_ok=True)
with MSQLite(db_path) as db:
# create DB file in case it doesn't already exist
db.execute(f"CREATE TABLE IF NOT EXISTS stuff(id INTEGER PRIMARY KEY, name, color, year)")
now = time.monotonic_ns() # some index value
# insert some data
db.execute(f"INSERT INTO stuff VALUES ({now}, 'plate', 'red', 2020), ({now + 1}, 'chair', 'green', 2019)")
# read the data back out
response = db.execute(f"SELECT * FROM stuff")
for row in response:
print(row)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file msqlite-0.0.8.tar.gz
.
File metadata
- Download URL: msqlite-0.0.8.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9dc43dc981fbe4640c21b78f05803ab782f7b5b25ec797329fb9978b0626787 |
|
MD5 | e760e773aaca30eaf25c6ddaf7e95a8d |
|
BLAKE2b-256 | d70e7edc989f58783b7e26bae22d9feac5bf61491f9b69fa3fd36b569c4a1245 |
File details
Details for the file msqlite-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: msqlite-0.0.8-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 649565a493058d501aa72a8eda5c06b6443e532943f06ead3db9374713aae773 |
|
MD5 | 230e2f97095abdec8e591c4c5ef1e186 |
|
BLAKE2b-256 | 409818233e9a19ba30ffa141bfd6d60a3049060421ff96c2c2a79b0e8505f7b2 |