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.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

msqlite-0.0.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for msqlite-0.0.3.tar.gz
Algorithm Hash digest
SHA256 472686536fa0906977f46fc9a70a2c4d6898cca73b6e8f773c2ac6c9ed2c0c67
MD5 093c1423176c28dfd53e593179b33858
BLAKE2b-256 80fbb20cbf2e8e001e67abf0af96f240d3361a301a805719c8d5742c3b2e5931

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msqlite-0.0.3-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.12.0

File hashes

Hashes for msqlite-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 498e518e67266f8b1d7d4114f447c11ca0b0739ae3f3e2ee178415f2acf9374d
MD5 d8932b434aa5c43f0a6f7438e53c93d2
BLAKE2b-256 ef7fee98a46930dbc5a335e40109511c93eced1bc370816e603468283266dba4

See more details on using hashes here.

Supported by

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