mrjsonstore
Simple, transparent on-disk JSON store using atomicwrites.
Basic Usage
Without context
store = JsonStore('example.json')
assert isinstance(store.content, dict)
store.content['woohoo'] = 'I am just a Python dictionary'
result = store.commit()
if not result:
print(f'There was a problem when writing: {result})
You can also use transactions...
store = JsonStore('example.json')
t = store.transaction()
store.content['woohoo'] = 'I am just a Python dictionary'
result = t.commit()
if not result:
print(f'There was a problem when writing: {result})
... and possibly roll them back:
store = JsonStore('example.json')
store.content['woohoo'] = 'I am just a Python dictionary'
t = store.transaction()
store.content['woohoo'] = 'I am going to be rolled back!'
t.rollback()
assert store.content['woohoo'] == 'I am just a Python dictionary'
With context
store = JsonStore('example.json')
with store.transaction() as t:
store.content['woohoo'] = 'I am just a Python dictionary'
Changes will be committed on context exit, unless there is an exception:
store = JsonStore('example.json')
store.content['woohoo'] = 'I am just a Python dictionary'
with store.transaction() as t:
store.content['woohoo'] = 'I am going to be rolled back!'
raise RuntimeError()
[...]
assert store.content['woohoo'] == 'I am just a Python dictionary'
If you want to commit regardless of exceptions, you can choose not to rollback:
store = JsonStore('example.json')
store.content['woohoo'] = 'I am just a Python dictionary'
with store.transaction(rollback=False) as t:
store.content['woohoo'] = 'I am not going to be rolled back!'
raise RuntimeError()
[...]
assert store.content['woohoo'] == 'I am not going to be rolled back!'
Changes will be committed to disk then.
TODO
- Add support for concurrency?
Metadata
Release files for mrjsonstore 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mrjsonstore-0.5.0.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mrjsonstore-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.7 kB
Release files / mrjsonstore-0.5.0.tar.gz
| Download URL | mrjsonstore-0.5.0.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b847839ae6c3a50c9d39ee3793b5397d9b14d9392bfab4d44933065758a45412
|
|
BLAKE2b-256 checksum How to use checksums |
26c61ec5d54281b8e95ba405dba01afcff329eb9745f5fd555f6e0b269a0e309
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/5.15.0-122-generic
|
Release files / mrjsonstore-0.5.0-py3-none-any.whl
| Download URL | mrjsonstore-0.5.0-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4b7c5e8b5ec1470037b0c30d92bc98a0604a0ab75a9ee439f18d2029bf3dfae
|
|
BLAKE2b-256 checksum How to use checksums |
da85bd40305ae4969079f1476339455cabe997827fe04704fd45c1cceeb16ade
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/5.15.0-122-generic
|