YAML 1.2 Support for PyYAML

0.0.4 · active · verified Thu Apr 16

This module provides YAML 1.2 Core Schema support on top of PyYAML. It acts as an extension, depending on and inheriting from PyYAML, rather than being a fork. It enables all YAML 1.2 Core Schema tags for PyYAML's BaseLoader. Developed as an alternative while native YAML 1.2 support was pending in PyYAML, it is actively maintained. The current version is 0.0.4, released in October 2024, with a focused release cadence for improvements and fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates loading and dumping YAML 1.2 compliant data using `yamlcore.CoreLoader` and `yamlcore.CoreDumper` with the standard `PyYAML` `yaml.load` and `yaml.dump` functions. It highlights the differences in how YAML 1.1 and 1.2 interpret certain literals.

import yaml
from yamlcore import CoreLoader, CoreDumper

yaml_string = """
--- 1.1:
- yes
- no
- 1__0
- 10:20
- +0b100
- 0x4_2
core:
- true
- 0o10
- 0x42
- ~
- .inf
"""

# Load using CoreLoader for YAML 1.2 compliance
data = yaml.load(yaml_string, Loader=CoreLoader)
print("Loaded data (Python object):")
print(data)

# Dump using CoreDumper for YAML 1.2 compliance
output_yaml = yaml.dump(data, Dumper=CoreDumper)
print("\nDumped data (YAML string):")
print(output_yaml)

# Example with a simple dictionary
simple_data = {'name': 'Alice', 'age': 30, 'is_active': True}
simple_yaml = yaml.dump(simple_data, Dumper=CoreDumper, default_flow_style=False)
print("\nSimple data dumped to YAML:")
print(simple_yaml)

view raw JSON →