I just built and released Yamlium! a faster PyYAML alternative that preserves formatting

Posted by GuidoInTheShell@reddit | Python | View on Reddit | 18 comments

Hey everyone!
Long term lurker of this and other python related subs, and I'm here to tell you about an open source project I just released, the python yaml parser yamlium!

Long story short, I had grown tired of PyYaml and other popular yaml parser ignoring all the structural components of yaml documents, so I built a parser that retains all structural comments, anchors, newlines etc! For a PyYAML comparison see here

Other key features:

Short example

Input yaml:

# Default user
users:
  - name: bob
    age: 55 # Will be increased by 10
    address: &address
      country: canada
  - name: alice
    age: 31
    address: *address

Manipulate:

from yamlium import parse

yml = parse("my_yaml.yml")

for key, value, obj in yml.walk_keys():
    if key == "country":
        obj[key] = value.str.capitalize()
    if key == "age":
        value += 10
print(yml.to_yaml())

Output:

# Default user
users:
  - name: bob
    age: 65 # Will be increased by 10
    address: &address
      country: Canada
  - name: alice
    age: 41
    address: *address