Simple, transparent on-disk JSON store
Project description
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?
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 mrjsonstore-0.5.0.tar.gz.
File metadata
- Download URL: mrjsonstore-0.5.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.0-122-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b847839ae6c3a50c9d39ee3793b5397d9b14d9392bfab4d44933065758a45412
|
|
| MD5 |
ca5bba0e434c0e8f8b14568a16ccaa64
|
|
| BLAKE2b-256 |
26c61ec5d54281b8e95ba405dba01afcff329eb9745f5fd555f6e0b269a0e309
|
File details
Details for the file mrjsonstore-0.5.0-py3-none-any.whl.
File metadata
- Download URL: mrjsonstore-0.5.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.0-122-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b7c5e8b5ec1470037b0c30d92bc98a0604a0ab75a9ee439f18d2029bf3dfae
|
|
| MD5 |
e57728b2b29f0a823bcc350a5d4f1c20
|
|
| BLAKE2b-256 |
da85bd40305ae4969079f1476339455cabe997827fe04704fd45c1cceeb16ade
|