Easy transactional database for Python dicts, backed by SQLite
Project description
itemdb
The itemdb library allows you to store and retrieve Python dicts in a database on the local filesystem, in an easy, fast, and reliable way.
Based on the rock-solid and ACID compliant SQLite, but with easy and
explicit transactions using a with statement. It provides a simple
object-based API, with the flexibility to store (JSON-compatible) items
with arbitrary fields, and add indices when needed.
Originally developed as part of TimaTagger and MyPaaS.
Installation
pip install itemdb
Quick usage example
import itemdb
# Open the database and make sure there is a table with appopriate indices
db = itemdb.ItemDB(":memory:")
db.ensure_table("persons", "!name", "age")
# Add some items to the db
with db:
db.put_one("persons", name="Jane", age=22)
db.put_one("persons", name="John", age=18, fav_number=7)
db.put("persons", {"name": "Guido"}, {"name": "Anne", "age": 42})
# Update an item
with db:
db.put_one("persons", name="John", age=19, fav_number=8)
# Query items
db.count_all("persons") # -> 4
db.select("persons", "age > ?", 20) # -> list of 2 items
See the guide for details.
Async
The AsyncItemDB class provides the same API, but async:
import itemdb
db = await itemdb.AsyncItemDB(":memory:")
await db.ensure_table("persons", "!name", "age")
async with db:
await db.put_one("persons", name="Jane", age=22)
...
Alternatively, a decorator is provided to turn a normal function into an async one (running in a separate thread).
@asycify
def your_db_interaction_logic(...):
db = ItemDB(filename)
...
async def your_async_code(...):
await your_db_interaction_logic(...)
License
MIT
Developers
- Run
ruff formatto autoformat. - Run
ruff checkto lint. - Run
pytest teststo run unit tests.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file itemdb-1.3.0.tar.gz.
File metadata
- Download URL: itemdb-1.3.0.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a20016cab6d36909b7426daaf08d058eeee3aeae2527d4a8a9c1fb23b3f9ea1
|
|
| MD5 |
69f26477482f4de8425cb9a196b23078
|
|
| BLAKE2b-256 |
611bcb18febeda59392c0478ea8eb60d2e266d690d7d45d58cbe4dee7026a7ee
|
File details
Details for the file itemdb-1.3.0-py3-none-any.whl.
File metadata
- Download URL: itemdb-1.3.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4902f1bef0cca87d00a352060dd95681fffc424a1a798c72ba759fe7cd12622c
|
|
| MD5 |
ae7e22e27304c328bb2492b757ac18ee
|
|
| BLAKE2b-256 |
0633f916c6835e5a3a85367753bfe3c8474cb14a6bd81820befd69626b4c91fe
|