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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file msqlite-0.5.0.tar.gz.
File metadata
- Download URL: msqlite-0.5.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58e6c6bc5e716447c3f469ce0f30a2f5f6d2cf666a6fa138a5ab95062b6a9245
|
|
| MD5 |
04b4ef0182dd932265df72238c904351
|
|
| BLAKE2b-256 |
9f4d5c7b91b3bc3815586386ebb932d9e47c3885d5950d13fc3fa58b27ff3e84
|
File details
Details for the file msqlite-0.5.0-py3-none-any.whl.
File metadata
- Download URL: msqlite-0.5.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd53777f366f3feb0f002af9f5414ecc64351e1eac3e7bffeda28efb86a4ad87
|
|
| MD5 |
7be8497e6e54c9587526e20eb3db322d
|
|
| BLAKE2b-256 |
336d45938c4660906a1ad2888e2ed3d2139c6b3a22772b6aa5b6e6e6a1efa06b
|