yaml
yaml
¶
Centralised YAML I/O — round-trip mode everywhere.
Facade over ruamel.yaml's ceremony-heavy YAML() class: callers get
a minimal load / dump / literal_block / YAMLError surface
instead of instance creation, typ selection, stream management, and config
attributes.
Adapter from ruamel.yaml's stream-oriented API to the string-based
convention used throughout the ecosystem (path.read_text() → load(text)
→ modify → dump(data) → path.write_text(text)).
CommentedMap is a dict subclass — isinstance(x, dict), .get(),
x["key"], .setdefault() all work transparently. Pydantic v2
model_validate() accepts dict subclasses, so read-side validation is
unchanged.
__all__ = ['load', 'dump', 'literal_block', 'YAMLError']
module-attribute
¶
load(text)
¶
dump(data, *, default_flow_style=False)
¶
Round-trip dump to a YAML string, preserving comments and order.
Key order is preserved (insertion order for new dicts, original order for
round-tripped data). sort_keys is always False — the caller never
needs to pass it.
Source code in src/terok_util/yaml.py
literal_block(text)
¶
Mark text to dump as a literal block scalar (|).
Multi-line text, such as a Dockerfile snippet, then stays one
readable block in the file instead of a quoted line full of \n
escapes. Text a block cannot carry — a control character, or a
line break other than \n — dumps double-quoted with escapes
instead, so it always loads back unchanged. The value is still a
str and compares equal to text.