Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msqlite-0.0.6.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

msqlite-0.0.6-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file msqlite-0.0.6.tar.gz.

File metadata

  • Download URL: msqlite-0.0.6.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for msqlite-0.0.6.tar.gz
Algorithm Hash digest
SHA256 3cb2c07545afdb8ec3cc060443ecdc3c7f2275438e6ac0f948455b1a1b6f02a2
MD5 58bbb0ce2058be31f593127c7d8b35a1
BLAKE2b-256 3b29d7c4f2ce729fd4b015a6f829746f15142ed24aa3fbe4b0ed771388e0522f

See more details on using hashes here.

File details

Details for the file msqlite-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: msqlite-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.8

File hashes

Hashes for msqlite-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 72f544ac2df436cea2ad6f6eb442ccb6e568bc1635cd36d2a48ed9c900193f8a
MD5 0f910d8595adf48d30d4f0ba76528021
BLAKE2b-256 07d32ee2a932657570072975f7211db637fbd1cd8c54527853d52a38e0537e28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page