Skip to main content

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.

Unit Tests codecov PyPI PyPI - Python Version License: MIT

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_lock only)
  • Persistent dict (JsonStorage) and list-of-records database (JsonDatabase)
  • Recursive search by key and key/value pair, with optional fuzzy matching
  • Fluent Query builder for multi-condition filtering
  • AES-256-GCM encryption at rest (EncryptedJsonStorage)
  • XDG Base Directory compliant variants for Linux applications
  • File locking via combo_lock for safe concurrent access
  • Supports commented JSON files (// and # line comments)
  • Arbitrary Python objects stored via automatic jsonify_recursively conversion

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 JsonDatabase are stable list indices. add_item and append return the zero-based slot index of the new item. Removing an item tombstones its slot rather than shifting subsequent IDs, so an ID obtained from add_item or get_item_id remains valid for the lifetime of the database file. Tombstoned slots are invisible to iteration, search, __contains__, and __len__; accessing one via db[item_id] raises InvalidItemID.

Warning: Encryption keys longer than 16 bytes are silently truncated to 16 bytes. Always use exactly 16 bytes.

Documentation

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

json_database-1.0.3a1.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_database-1.0.3a1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file json_database-1.0.3a1.tar.gz.

File metadata

  • Download URL: json_database-1.0.3a1.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for json_database-1.0.3a1.tar.gz
Algorithm Hash digest
SHA256 be8fd3cb0c164e6dee39c3730d27be3b4755d3da09fa85645cc1bd1caded0556
MD5 33cd4b4f39c36198b1bf8a1ef7746340
BLAKE2b-256 1b798099047d145ce901e4a6566557f990195f4fd34deb97b8e3ae0c51087055

See more details on using hashes here.

File details

Details for the file json_database-1.0.3a1-py3-none-any.whl.

File metadata

File hashes

Hashes for json_database-1.0.3a1-py3-none-any.whl
Algorithm Hash digest
SHA256 df97861341cb9219a1ec884390fbb0984c0f177ed035694e3c710fd5c09fb605
MD5 1311af5ef87f5c3e4ca8e31ed06c2434
BLAKE2b-256 c847b6413b627e869730df3cbc2a159020bffd4fc270d0b344b15c783d15f1e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page