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.

    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


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

Uploaded Source

Built Distribution

msqlite-0.2.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for msqlite-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b325ad2001ca79b2ba95d2cdf17a630a2e11b256b0e7194af70986eee134452a
MD5 4ae7241aa2c0fe5430884f379cbafeab
BLAKE2b-256 bb13ef657539dc742128ff854c27a18be24a84da4585827b09641f8719c3d9b3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for msqlite-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eda05748ed3854f3c59a8ec11e3659fa7ee3c7dbc55b99d459f6d7f666d6002e
MD5 dacbc7a15515c5238dd4a2e77dd09d66
BLAKE2b-256 89b139ebb72c3d6783cb92340dc19f59aa491edd96d1c5e4c89b3df254792e99

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