Skip to main content

sqlite-worker

Sqlite-Worker is a Python package providing a thread-safe interface for SQLite database operations. It ensures safe concurrent access to SQLite databases and simplifies executing database queries from different threads.

Features

  • Thread-safe SQLite database operations
  • Queue-based query execution
  • Simple and easy-to-use API
  • Initialization actions executed once upon database connection
  • Regular commits for continuous query streams

Installation

To install, run:

pip3 install sqlite-worker

Creating a Worker Instance

To create a basic instance of Sqlite3Worker by specifying the path to your SQLite database file:

from sqlite_worker import SqliteWorker
worker = SqliteWorker("/path/to/your/database.db")

Worker instance with Initialization Actions

Create a SqliteWorker instance with initialization actions (such as setting pragmas):

from sqlite_worker import SqliteWorker

init_actions = [
    "PRAGMA journal_mode=WAL;",
    "PRAGMA synchronous=NORMAL;",
    "PRAGMA temp_store=MEMORY;"
]

worker = SqliteWorker("/path/to/your/database.db", execute_init=init_actions)

Worker Instance with Regular Commits

Create a SqliteWorker instance with initialization actions and set a maximum query count for regular commits:

from sqlite_worker import SqliteWorker

init_actions = [
    "PRAGMA journal_mode=WAL;",
    "PRAGMA synchronous=NORMAL;",
    "PRAGMA temp_store=MEMORY;"
]

worker = SqliteWorker("/path/to/your/database.db", execute_init=init_actions, max_count=50)

Execute Queries

Creating a table

worker.execute("CREATE TABLE example (id INTEGER PRIMARY KEY, name TEXT)")

Inserting data

worker.execute("INSERT INTO example (name) VALUES (?)", ("Alice",))

Fetching data

token = worker.execute("SELECT * FROM example")
results = worker.fetch_results(token)
print(results)

Closing the Worker

After completing all database operations, close the worker to ensure proper cleanup:

worker.close()

Contributing

Contributions to the Sqlite-Worker are welcome! Please refer to the project's issues and pull request sections for contributions.

Release files for sqlite-worker 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlite-worker 0.0.4
File Size Uploaded
sqlite_worker-0.0.4.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlite-worker 0.0.4
File Interpreter ABI Platform
sqlite_worker-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / sqlite_worker-0.0.4.tar.gz

Download URL sqlite_worker-0.0.4.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fb140087e3fc03756f18527523d8ea68db73b1a1edd0c58383208b2414e2588e
BLAKE2b-256 checksum
How to use checksums
695b04bb5d11c15a0cb69fe15a36e0ba6b6d8546c23b4f1e036d5f21f2ef4a80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.6

Release files / sqlite_worker-0.0.4-py3-none-any.whl

Download URL sqlite_worker-0.0.4-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
943fb405c0738ceecc8c0173e10f041bdc6a3f972abcb55e3f5fe5b2330c5efa
BLAKE2b-256 checksum
How to use checksums
a0dd54226adb200cf6370e3ca4a7bf6370d5e96d616777aa0a2829c68db93c68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page