Skip to main content

High-fidelity YAML parser that preserves formatting

Project description

hifiyaml

High-fidelity YAML parser that preserves formatting.
Original YAML structure and formatting are preserved, including comments, anchors, aliases, etc.
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 python test.py, check the stdout and the ensbec.yaml file.

NOTE: A querystr is a string describing the path from the top 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

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

hifiyaml-0.1.7.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hifiyaml-0.1.7-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file hifiyaml-0.1.7.tar.gz.

File metadata

  • Download URL: hifiyaml-0.1.7.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for hifiyaml-0.1.7.tar.gz
Algorithm Hash digest
SHA256 715d2e6d08eeaa24858e1929d24c1525eb91623fe445d8dd3b6e915bfad9515d
MD5 03bfe8c828fde0ab626d3f0549c3b100
BLAKE2b-256 33c9602f56e6b93e9b5e36c38a97d55d4de12150af83dd0764b6d5a648a80967

See more details on using hashes here.

File details

Details for the file hifiyaml-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: hifiyaml-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for hifiyaml-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2d8b410b9d76390b4781791348b4e3d58987403180061bf0edc2b1aa046b4fcc
MD5 7d5c4e67d832a8eed69de243efd9c27a
BLAKE2b-256 2f191b84471ba75b1f04612b87f83e18b179da4500ff9ab4d95bcc33d0696d93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page