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.1.tar.gz (6.5 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.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsondocstore-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 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.1.tar.gz
Algorithm Hash digest
SHA256 f5bfba25658a1191a30f0bdc689625b3e821b71741503f8b6df063b0f3a8942f
MD5 668695331f93d010840341bcac4c218a
BLAKE2b-256 4872695be54c86facc7713ed97216fbc740fbabfd11e501c784f1ba29b703959

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsondocstore-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: jsondocstore-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 036dff96265c96260f4f12617bc27a344d2b5b3dcf81ec8415d40f00c5cfb94d
MD5 d9fb0175a57ae06ac7413cdb3ffdb8a1
BLAKE2b-256 71d6053fd7c0741246f625550eea4c292cef5cb25585f174cd315e5ef61d0afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsondocstore-0.1.1-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