High-fidelity WYSIWYG YAML parser and emitter that preserve exact formatting
Project description
hifiyaml
A high-fidelity WYSIWYG YAML parser and emitter that preserves exact formatting, including comments, anchors, aliases, blank lines, and indentation.
Check the more detailed User Guide
Check wiki at https://github.com/hifiyaml/hifiyaml/wiki
Installation
pip install hifiyaml
Quick demo
1. Get an example YAML file
Use jedivar.yaml from the RRFSv2 system as an example.
wget https://raw.githubusercontent.com/NOAA-EMC/rrfs-workflow/refs/heads/rrfs-mpas-jedi/parm/jedivar.yaml
2. Load the YAML data and dump a YAML block using a querystr
Write the following statments into test.py:
import hifiyaml as hy
data = hy.load("jedivar.yaml")
querystr = "cost function/background error/components/1"
hy.dump(data, querystr) # dump to stdout
hy.dump(data, querystr, 'ensbec.yaml') # dump to the file 'ensbec.yaml'
run cd tests; ./test.sh and then check the output yaml files
NOTE: A querystr is a string describing the path from a unique higher level key (or index if a list) to the destination level key (or index), separated with /.
For the following simple YAML file,
demo:
configuration:
suite: YAML
detail:
- meaning:
- Y: Yelling
- A: At
- M: My
- L: Laptop
A query string demo/configuration/detail/0/meaning will return one dictionary item with "meaning" as the key and a list of 4 items as the value, i.e:
- meaning:
- Y: Yelling
- A: At
- M: My
- L: Laptop
3. Availabe functions.
hifiyaml currently provides the following functions:
load, get, dump, drop, modify, next_pos, get_start_pos, dedent, text_to_yblock, strip_indentations, strip_leading_empty_lines
Testing
pip install pytest
python3 -m pytest tests/test_hifiyaml.py -v
and use the shell-based diff tests:
cd tests; ./test.sh
Project details
Release history Release notifications | RSS feed
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 hifiyaml-0.2.0.tar.gz.
File metadata
- Download URL: hifiyaml-0.2.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
452fa20c2e4184a995ec9d7517222595fd7d32b36ccb15ad84f822aefc6ae7f8
|
|
| MD5 |
daaf0a8539b447617d3e6c412866b14a
|
|
| BLAKE2b-256 |
ba56161fe4d13223a7c06a6ba21827d3522958493e72bf74240f75d01f14c28d
|
File details
Details for the file hifiyaml-0.2.0-py3-none-any.whl.
File metadata
- Download URL: hifiyaml-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
448a0c5109348c21d8556088f8e602888dfdbb737a432c2a5480a14efbaf3b23
|
|
| MD5 |
5cae1ce08997666f4f8a90b65888f6dd
|
|
| BLAKE2b-256 |
8baa0f36278ec0affee273940e8d43e6bc628252502f4497b924b8cf19b0cbe0
|