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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: msqlite-0.0.5.tar.gz
  • Upload date:
  • Size: 3.9 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.5.tar.gz
Algorithm Hash digest
SHA256 d7221071a555fab3c8f6ba716f58a633506eaf7af7e4d05ee049e91fd3b86661
MD5 1f19ac4d0fdd02386b3cafcbb62aa937
BLAKE2b-256 4efd33b5cffaefea2a07ec29dffcf97b31d1c9df799b62372542f71280b9e974

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msqlite-0.0.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 34732170a641bec7863c681472b9435d51c7fbe976a622f04d54ebdc50ea677f
MD5 342b0bf79c4c005e186f2ad27fbd6d7c
BLAKE2b-256 51942b04bbc8d239749cd3a9b6785d9be22ea6c2266a122266b1a96728832c55

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