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.
table_name = "example"
schema = {"id PRIMARY KEY": int, "name": str, "color": str, "year": int}
db_path = Path("temp", "example.sqlite")
db_path.parent.mkdir(exist_ok=True)
# Write and read data.
with MSQLite(db_path, table_name, schema) as db:
now = time.monotonic_ns() # some index value
# insert some data
db.execute(f"INSERT INTO {table_name} VALUES ({now}, 'plate', 'red', 2020), ({now + 1}, 'chair', 'green', 2019)")
# read the data back out
response = db.execute(f"SELECT * FROM {table_name}")
for row in response:
print(row)
# Read data out. No longer needs the schema.
with MSQLite(db_path, table_name) as db:
response = db.execute(f"SELECT * FROM {table_name}")
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.4.0.tar.gz
.
File metadata
- Download URL: msqlite-0.4.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a51d948a4a1cf2c9c7b9617e537cb3d5b1a0b5b875a20f3aa955871287a81290 |
|
MD5 | 16fbf1c9e094470474bfcf80e2f2cf8b |
|
BLAKE2b-256 | f3f2485f1c5509fcc3a63dac2855c280df288152dd31397a81fde132e3b88235 |
File details
Details for the file msqlite-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: msqlite-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97eeabd84d3dcdfa4d698a097fe72d44cd65e917dc1007fd79274bd6f89f930b |
|
MD5 | 39ff8c6c8226f8aa1f569d1cd28da459 |
|
BLAKE2b-256 | 942d6ed2299d53ce5f13dbc729c76018b8d188cac7c5d783bd0cbe77bc321d64 |