Skip to main content

Simple JSON document storage on disk

Project description

JsonDocStore

Simple JSON document storage on disk.

  • A Python library to organize and query JSON documents on disk, basically, with no running process.
  • Each document is stored as one file named <key>.json. The document key is the filename stem.
  • 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.
  • If you want to query by a field, create an index on it. This will create an index.json file in the store directory. It is not required for basic operations like insert, update, delete, and get.

Installation

pip install jsondocstore

Using from the terminal

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
  • get KEY
  • 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> get user-1
{
  "password": "secret1",
  "role": "admin",
  "username": "alice"
}
jsondocstore> createindex role
jsondocstore> queryby role user
{
  "user-3": {
    "password": "secret3",
    "role": "user",
    "username": "carol"
  }
}

Using from your Python application

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")

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. It returns a mapping of key -> document. 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

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.2.0.tar.gz (7.6 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.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsondocstore-0.2.0.tar.gz
Algorithm Hash digest
SHA256 298b0452ffa986458194ccf059bc532779bb7ad7281f7466bca3e5c875c18ff3
MD5 2ff401e27274e306bd05fc43dab2d4f6
BLAKE2b-256 310fb7b898139e60296b7f387bb9a2a7535faca2d853252f237c9ff155879eb2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: jsondocstore-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 889fcf4b055398eda32d93727cc7283691ea8a45bf368ccd4c5527e0df7678e1
MD5 ba99cfd2138726217e1fd0d2bad6c80a
BLAKE2b-256 ed399382141242df3bb662ca2d138f8b5322a83634886f47b4ad5031a3d0faa3

See more details on using hashes here.

Provenance

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