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
JsonDocStoreinstance 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.jsonfile in the store directory. It is not required for basic operations likeinsert,update,delete, andget.
Installation
pip install jsondocstore
Using from the terminal
Start the interactive shell:
jsondocstore /path/to/store
Commands:
listprints document filenames onlylistindexesprints indexed fields, or[]if there is noindex.jsonget KEYqueryby FIELD VALUEcreateindex FIELDdeleteindex FIELDinsert KEY JSON_DOCUMENTupdate 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
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=Truecreates the directory if needed. It does not createindex.json.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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
298b0452ffa986458194ccf059bc532779bb7ad7281f7466bca3e5c875c18ff3
|
|
| MD5 |
2ff401e27274e306bd05fc43dab2d4f6
|
|
| BLAKE2b-256 |
310fb7b898139e60296b7f387bb9a2a7535faca2d853252f237c9ff155879eb2
|
Provenance
The following attestation bundles were made for jsondocstore-0.2.0.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.0.tar.gz -
Subject digest:
298b0452ffa986458194ccf059bc532779bb7ad7281f7466bca3e5c875c18ff3 - Sigstore transparency entry: 1260734035
- Sigstore integration time:
-
Permalink:
mortensi/jsondocstore@3584531d9804e7ed71732ab3b7b8661ddfde77e7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/mortensi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3584531d9804e7ed71732ab3b7b8661ddfde77e7 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
889fcf4b055398eda32d93727cc7283691ea8a45bf368ccd4c5527e0df7678e1
|
|
| MD5 |
ba99cfd2138726217e1fd0d2bad6c80a
|
|
| BLAKE2b-256 |
ed399382141242df3bb662ca2d138f8b5322a83634886f47b4ad5031a3d0faa3
|
Provenance
The following attestation bundles were made for jsondocstore-0.2.0-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.0-py3-none-any.whl -
Subject digest:
889fcf4b055398eda32d93727cc7283691ea8a45bf368ccd4c5527e0df7678e1 - Sigstore transparency entry: 1260734044
- Sigstore integration time:
-
Permalink:
mortensi/jsondocstore@3584531d9804e7ed71732ab3b7b8661ddfde77e7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/mortensi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3584531d9804e7ed71732ab3b7b8661ddfde77e7 -
Trigger Event:
release
-
Statement type: