https://github.com/dvec/hotmarkup
Synchronize data structure with markup file
https://github.com/dvec/hotmarkup
arrays configuration configuration-loader configuration-management configurations dictionaries dictionary json markup mit-license pickle python python-library python-package python3 yaml
Last synced: about 2 months ago
JSON representation
Synchronize data structure with markup file
- Host: GitHub
- URL: https://github.com/dvec/hotmarkup
- Owner: dvec
- License: mit
- Created: 2020-06-09T00:53:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-13T23:10:12.000Z (over 5 years ago)
- Last Synced: 2025-12-17T01:13:34.130Z (6 months ago)
- Topics: arrays, configuration, configuration-loader, configuration-management, configurations, dictionaries, dictionary, json, markup, mit-license, pickle, python, python-library, python-package, python3, yaml
- Language: Python
- Homepage:
- Size: 73.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# HOTMARKUP
[](https://travis-ci.com/dvec/hotmarkup)
#### Synchronize data structure with markup file
Currently supported formats: **YAML**, **JSON**, **Pickle**
#### Main features:
- Work with Connection object as usual data structure. You can use features like array slices or methods of `dict` and `list`
- JS-like accessing (foo.bar.buzz instead of foo['bar']['buzz'])
- Mutations logging via `logging` module. Example below
- Reload on file change (pass `reload=False` to connection constructor to disable)
- Update file on every change (pass `save=False` to connection constructor to disable)
- Immutable connections (pass `mutable=False` to connection constructor to enable)
## Installation
```shell script
pip install hotmarkup
```
## Examples
#### [Reload](https://github.com/dvec/hotmarkup/blob/master/examples/reload.py)
```python
from hotmarkup import JsonConnection
connection = JsonConnection('example.json', default={'changed': False})
print(connection.changed) # Out: False
with open('example.json', 'w') as f:
f.write('{"changed": true}')
print(connection.changed) # Out: True
```
#### [Dump](https://github.com/dvec/hotmarkup/blob/master/examples/dump.py)
```python
from hotmarkup import JsonConnection
connection = JsonConnection('example.json', default={'changed': False})
print(open('example.json').read()) # Out: {"changed": false}
connection.changed = True
print(open('example.json').read()) # Out: {"changed": true}
```
#### [Logging](https://github.com/dvec/hotmarkup/blob/master/examples/log.py)
```python
import logging
from hotmarkup import YamlConnection
logging.basicConfig(level=logging.INFO)
connection = YamlConnection('example.yaml', default={'something_important': 'old_value'})
connection.something_important = 'new_value'
```
Output:
```
INFO:example.yaml:Mutation UPDATE example.yaml.something_important=new_value
```
#### [Counter](https://github.com/dvec/hotmarkup/blob/master/examples/counter.py)
```python
from hotmarkup import YamlConnection
connection = YamlConnection('counter.yaml', default={'counter': 0})
connection.counter += 1
print(f'You run this program {connection.counter} times')
```