searchable json database with persistence
Project description
json_database
Searchable, persistent Python dict database backed by JSON files — for those times when SQL is overkill.
Install
pip install json_database
Encryption features additionally require pycryptodomex:
pip install json_database pycryptodomex
Quick Start
from json_database import JsonStorage, JsonDatabase
from json_database.search import Query
# Persistent dict
with JsonStorage("/tmp/config.json") as cfg:
cfg["host"] = "localhost"
cfg["port"] = 5432
# auto-saved on exit
# Searchable list-of-records
with JsonDatabase("users", "/tmp/users.jsondb") as db:
db.add_item({"name": "Alice", "role": "admin"})
db.add_item({"name": "Bob", "role": "user"})
admins = db.search_by_value("role", "admin")
# Fluent query builder
results = Query(db).equal("role", "user").build()
Features
- Pure Python, minimal dependencies (
combo_lockonly) - Persistent dict (
JsonStorage) and list-of-records database (JsonDatabase) - Recursive search by key and key/value pair, with optional fuzzy matching
- Fluent
Querybuilder for multi-condition filtering - AES-256-GCM encryption at rest (
EncryptedJsonStorage) - XDG Base Directory compliant variants for Linux applications
- File locking via
combo_lockfor safe concurrent access - Supports commented JSON files (
//and#line comments) - Arbitrary Python objects stored via automatic
jsonify_recursivelyconversion
Configuration / Key Options
| Class | Default path | Use for |
|---|---|---|
JsonStorage(path) |
user-specified | any persistent dict |
JsonStorageXDG(name) |
~/.cache/json_database/{name}.json |
cache / temp data |
JsonConfigXDG(name) |
~/.config/json_database/{name}.json |
app settings |
JsonDatabaseXDG(name) |
~/.local/share/json_database/{name}.jsondb |
persistent records |
EncryptedJsonStorage(key, path) |
user-specified | sensitive data at rest |
Note: Item IDs in
JsonDatabaseare stable list indices.add_itemandappendreturn the zero-based slot index of the new item. Removing an item tombstones its slot rather than shifting subsequent IDs, so an ID obtained fromadd_itemorget_item_idremains valid for the lifetime of the database file. Tombstoned slots are invisible to iteration, search,__contains__, and__len__; accessing one viadb[item_id]raisesInvalidItemID.
Warning: Encryption keys longer than 16 bytes are silently truncated to 16 bytes. Always use exactly 16 bytes.
Documentation
- Installation — dependencies, Python version support
- Quick Start — 5-minute walkthrough with examples
- API Reference — all public classes and methods
- Encryption — AES-GCM details, key rules, security notes
- XDG Paths — XDG spec support and path resolution
- Search and Query — all filter methods, fuzzy matching
- Development — running tests, CI, contributing
- Architecture — class hierarchy, data flow, design
HiveMind Integration
The HiveMind database-plugin adapter that used to ship as
json_database.hpm:JsonDB has been extracted into its own package,
hivemind-json-db-plugin,
so it can release on a HiveMind-aligned cadence and json_database doesn't pull
in hivemind-plugin-manager for users who don't need it.
For the 1.x line, pip install json_database[hpm] continues to work — it now
transitively installs hivemind-json-db-plugin so the hivemind.database
entry point remains available without code changes. The [hpm] extra will
be removed in 2.0.0; users should migrate to
pip install hivemind-json-db-plugin directly.
License
MIT
Project details
Release history Release notifications | RSS feed
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 json_database-1.0.2a1.tar.gz.
File metadata
- Download URL: json_database-1.0.2a1.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18b17b5b40472a29a1dc8553786ba9f1bc32f0edd8d71ac7b229d27a7b734a60
|
|
| MD5 |
ed699a27c46109ef8a58ee9b4e3aa094
|
|
| BLAKE2b-256 |
e75f2a93f18b08e44552f3dbf9147e935bc38eee93a9b44ffbd410c643d5295d
|
File details
Details for the file json_database-1.0.2a1-py3-none-any.whl.
File metadata
- Download URL: json_database-1.0.2a1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd5364ccc5663dcd8790592d1b48b1977469c4f1d1be3ae97aa73ea9a29a4e57
|
|
| MD5 |
9604194d7ca8a10e65dfd10043e5362a
|
|
| BLAKE2b-256 |
dea07b1c3847a4b8008ca538dcd6989c27dc14847575d5d80e73abeefee101d9
|