Name | mrjsonstore JSON |
Version |
0.5.0
JSON |
| download |
home_page | None |
Summary | Simple, transparent on-disk JSON store |
upload_time | 2024-10-15 16:20:27 |
maintainer | None |
docs_url | None |
author | Ole Kliemann |
requires_python | >=3.12 |
license | Apache-2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# mrjsonstore
Simple, transparent on-disk JSON store using `atomicwrites`.
## Basic Usage
### Without context
```python
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...
```python
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:
```python
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
```python
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:
```python
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:
```python
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?
Raw data
{
"_id": null,
"home_page": null,
"name": "mrjsonstore",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": null,
"author": "Ole Kliemann",
"author_email": "mail@olekliemann.de",
"download_url": "https://files.pythonhosted.org/packages/26/c6/1ec5d54281b8e95ba405dba01afcff329eb9745f5fd555f6e0b269a0e309/mrjsonstore-0.5.0.tar.gz",
"platform": null,
"description": "# mrjsonstore\nSimple, transparent on-disk JSON store using `atomicwrites`.\n\n## Basic Usage\n\n### Without context\n\n```python\nstore = JsonStore('example.json')\nassert isinstance(store.content, dict)\nstore.content['woohoo'] = 'I am just a Python dictionary'\nresult = store.commit()\nif not result:\n print(f'There was a problem when writing: {result})\n```\n\nYou can also use transactions...\n\n```python\nstore = JsonStore('example.json')\nt = store.transaction()\nstore.content['woohoo'] = 'I am just a Python dictionary'\nresult = t.commit()\nif not result:\n print(f'There was a problem when writing: {result})\n```\n\n... and possibly roll them back:\n\n```python\nstore = JsonStore('example.json')\nstore.content['woohoo'] = 'I am just a Python dictionary'\nt = store.transaction()\nstore.content['woohoo'] = 'I am going to be rolled back!'\nt.rollback()\nassert store.content['woohoo'] == 'I am just a Python dictionary'\n```\n\n### With context\n\n```python\nstore = JsonStore('example.json')\nwith store.transaction() as t:\n store.content['woohoo'] = 'I am just a Python dictionary'\n```\n\nChanges will be committed on context exit, unless there is an exception:\n\n```python\nstore = JsonStore('example.json')\nstore.content['woohoo'] = 'I am just a Python dictionary'\nwith store.transaction() as t:\n store.content['woohoo'] = 'I am going to be rolled back!'\n raise RuntimeError()\n[...]\nassert store.content['woohoo'] == 'I am just a Python dictionary'\n```\n\nIf you want to commit regardless of exceptions, you can choose not to rollback:\n\n```python\nstore = JsonStore('example.json')\nstore.content['woohoo'] = 'I am just a Python dictionary'\nwith store.transaction(rollback=False) as t:\n store.content['woohoo'] = 'I am not going to be rolled back!'\n raise RuntimeError()\n[...]\nassert store.content['woohoo'] == 'I am not going to be rolled back!'\n```\n\nChanges will be committed to disk then.\n\n## TODO\n\n* Add support for concurrency?\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Simple, transparent on-disk JSON store",
"version": "0.5.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "da85bd40305ae4969079f1476339455cabe997827fe04704fd45c1cceeb16ade",
"md5": "e57728b2b29f0a823bcc350a5d4f1c20",
"sha256": "c4b7c5e8b5ec1470037b0c30d92bc98a0604a0ab75a9ee439f18d2029bf3dfae"
},
"downloads": -1,
"filename": "mrjsonstore-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e57728b2b29f0a823bcc350a5d4f1c20",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 7196,
"upload_time": "2024-10-15T16:20:25",
"upload_time_iso_8601": "2024-10-15T16:20:25.521875Z",
"url": "https://files.pythonhosted.org/packages/da/85/bd40305ae4969079f1476339455cabe997827fe04704fd45c1cceeb16ade/mrjsonstore-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "26c61ec5d54281b8e95ba405dba01afcff329eb9745f5fd555f6e0b269a0e309",
"md5": "ca5bba0e434c0e8f8b14568a16ccaa64",
"sha256": "b847839ae6c3a50c9d39ee3793b5397d9b14d9392bfab4d44933065758a45412"
},
"downloads": -1,
"filename": "mrjsonstore-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "ca5bba0e434c0e8f8b14568a16ccaa64",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 6456,
"upload_time": "2024-10-15T16:20:27",
"upload_time_iso_8601": "2024-10-15T16:20:27.068723Z",
"url": "https://files.pythonhosted.org/packages/26/c6/1ec5d54281b8e95ba405dba01afcff329eb9745f5fd555f6e0b269a0e309/mrjsonstore-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 16:20:27",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "mrjsonstore"
}