Skip to main content

Simple JSON document storage on disk

Project description

JsonDocStore

Simple JSON document storage on disk.

Each document is stored as one file named <key>.json. The document key is the filename stem, not a field inside the JSON body.

If you want to organize documents into different folders, use one JsonDocStore instance per folder. Each instance manages only the JSON files in its own directory.

What It Does

  • Stores one JSON document per file.
  • Reads documents directly by filename.
  • Uses optional in-memory indexes defined in index.json.
  • Provides an interactive CLI in cli.py.

Data Model

  • get(key) reads <key>.json.
  • insert(key, doc) writes <key>.json.
  • Valid keys may contain letters, digits, ., _, and -. No whitespace.

Schema

index.json is optional.

  • create=True creates the directory if needed. It does not create index.json.
  • index_fields defines which fields are indexed in memory.
  • get(), insert(), delete(), and list_all() work without index.json.
  • query_by() only works when an index exists. Querying without an index, or on a non-indexed field, raises an error.
  • Indexes work only on top-level document fields, not nested paths.

Example:

{
  "index_fields": ["email", "status"]
}

For example, this works:

{
  "email": "alice@example.com",
  "profile": {
    "city": "Rome"
  }
}
  • you can index email
  • you cannot index profile.city

CLI

Start the interactive shell:

jsondocstore /path/to/store

Commands:

  • list prints document filenames only
  • listindexes prints indexed fields, or [] if there is no index.json
  • queryby FIELD VALUE
  • createindex FIELD
  • deleteindex FIELD
  • insert KEY JSON_DOCUMENT
  • update KEY JSON_DOCUMENT
  • delete KEY
  • exit

Example session:

$ jsondocstore ./data
jsondocstore> insert user-1 '{"username": "alice", "password": "secret1", "role": "admin"}'
jsondocstore> insert user-2 '{"username": "bob", "password": "secret2", "role": "user"}'
jsondocstore> insert user-3 '{"username": "carol", "password": "secret3", "role": "user"}'
jsondocstore> update user-2 '{"username": "bob", "password": "secret2", "role": "admin"}'
jsondocstore> list
[
  "user-1.json",
  "user-2.json",
  "user-3.json"
]
jsondocstore> createindex role
jsondocstore> queryby role user
[
  {
    "password": "secret2",
    "role": "user",
    "username": "bob"
  },
  {
    "password": "secret3",
    "role": "user",
    "username": "carol"
  }
]

Library

from jsondocstore import JsonDocStore

store = JsonDocStore("./data", create=True)
store.insert("user-1", {"username": "alice", "password": "secret1", "role": "admin"})
store.insert("user-2", {"username": "bob", "password": "secret2", "role": "user"})
store.insert("user-3", {"username": "carol", "password": "secret3", "role": "user"})
store.update("user-2", {"username": "bob", "password": "secret2", "role": "admin"})
names = store.list_all()
store.create_index("role")
admins = store.query_by("role", "admin")
doc = store.get("user-1")

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

jsondocstore-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

jsondocstore-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file jsondocstore-0.1.0.tar.gz.

File metadata

  • Download URL: jsondocstore-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for jsondocstore-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6bb28c3cd88566f217a7ad96e218132456e74416200a9c58a579ae9d08406be8
MD5 7f523ff2edbbc414c576a8c4d34de6b1
BLAKE2b-256 baecec0dfbf02cc83d0f37a5e299d593913cdeb1361bfb332300c022db1c9d2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsondocstore-0.1.0.tar.gz:

Publisher: publish.yml on mortensi/jsondocstore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jsondocstore-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: jsondocstore-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for jsondocstore-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2c3fa4306800cb1095b42ccab3c437d9532dcb1d96ac96345fbfc1298c78034
MD5 934d42641bd6fef5d44f32eb66dcb1c4
BLAKE2b-256 665bbdbc71c1fc72fe851f46ef2973eba31542057abfb25b5b35b3b816606744

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsondocstore-0.1.0-py3-none-any.whl:

Publisher: publish.yml on mortensi/jsondocstore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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