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.
- You instantiate a
JsonDocStoreobject with a root directory where your JSON documents will be stored. If you want to organize documents into different folders, use oneJsonDocStoreinstance per folder. Each instance manages only the JSON files in its own directory. E.g.JsonDocStore("./data/users")andJsonDocStore("./data/products"). - Each document is stored as a file named
<key>.json. The document key is the filename stem. - If you want to query by a field, create an index on it. This will create an
index.jsonfile in the store directory. Currently, only exact match is supported. It is not required for basic operations likeinsert,update,delete, andget. The index is in-memory, not persisted to disk and is rebuilt when the store is opened.
Installation
pip install jsondocstore
API docs are available at:
https://mortensi.github.io/jsondocstore/
Using from the terminal
Start the interactive shell:
jsondocstore /path/to/store
The directory must already exist. The CLI does not create it for you.
Commands:
listprints document filenames onlylistindexesprints indexed fields, or[]if there is noindex.jsonget KEYqueryby FIELD VALUEcreateindex FIELDdeleteindex FIELDinsert KEY JSON_DOCUMENTvalid keys may contain letters, digits,.,_, and-. No whitespace.update KEY JSON_DOCUMENTdelete KEYexit
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
Learn the API by reading the API reference.
Example:
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")
Schema
The schema file index.json is optional and required only if you want to use indexes.
index_fieldsdefines which fields are indexed in memory.get(),insert(),delete(), andlist_all()work withoutindex.json.query_by()only works when an index exists. It returns a mapping ofkey -> 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
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 jsondocstore-0.2.1.tar.gz.
File metadata
- Download URL: jsondocstore-0.2.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae137d3d6bdeaa03ac52a2af4cc4c7032686165863d09bca39a47909fb0792b4
|
|
| MD5 |
bd8dc7e545c74950e0d3be743b627998
|
|
| BLAKE2b-256 |
725cd2b473a8a4bf3ad4a0e1f1f277331aa06013a3c1094def91600b660207cb
|
Provenance
The following attestation bundles were made for jsondocstore-0.2.1.tar.gz:
Publisher:
publish.yml on mortensi/jsondocstore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsondocstore-0.2.1.tar.gz -
Subject digest:
ae137d3d6bdeaa03ac52a2af4cc4c7032686165863d09bca39a47909fb0792b4 - Sigstore transparency entry: 1270582160
- Sigstore integration time:
-
Permalink:
mortensi/jsondocstore@955c0c30ac8af2c266de4e08239266e2d87dfe7b -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/mortensi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@955c0c30ac8af2c266de4e08239266e2d87dfe7b -
Trigger Event:
release
-
Statement type:
File details
Details for the file jsondocstore-0.2.1-py3-none-any.whl.
File metadata
- Download URL: jsondocstore-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b6bcaccf5a9a242ed4c8a30af5835328e3f2828f345c6df0709884e6494c1b4
|
|
| MD5 |
2965bdb7235d255f0432578f912bb273
|
|
| BLAKE2b-256 |
e103490046105aa6336207d02e0d23e583609b4a21ce6e50b46c029da9abcc9d
|
Provenance
The following attestation bundles were made for jsondocstore-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on mortensi/jsondocstore
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsondocstore-0.2.1-py3-none-any.whl -
Subject digest:
7b6bcaccf5a9a242ed4c8a30af5835328e3f2828f345c6df0709884e6494c1b4 - Sigstore transparency entry: 1270582293
- Sigstore integration time:
-
Permalink:
mortensi/jsondocstore@955c0c30ac8af2c266de4e08239266e2d87dfe7b -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/mortensi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@955c0c30ac8af2c266de4e08239266e2d87dfe7b -
Trigger Event:
release
-
Statement type: