files-edit-ymllisted
Install: claude install-skill bitranox/bitranox-skills
# Edit YAML with a Python library, never by hand
## Overview
Build and edit YAML by round-tripping through a Python data structure with a YAML library, then
re-load to confirm it parses. Editing YAML as raw text (typing it, `sed`, regex, string
concatenation) produces indentation and quoting errors that break the file or, worse, load as the
wrong structure. A library serialization is syntactically correct by construction; re-loading it
verifies it.
## Library
- **`ruamel.yaml`** - preferred for editing an EXISTING file: it round-trips and preserves comments
and key order (YAML 1.2). It does NOT preserve LAYOUT out of the box - see "Round-tripping keeps
comments, not layout" below, and pin the two settings there before you dump.
`pip install ruamel.yaml`.
- **`PyYAML`** (`import yaml`) - fine for generating a NEW file or when comments do not matter;
`yaml.safe_load` / `yaml.safe_dump`. Note: it drops comments and reorders, so do not use it to
round-trip a hand-commented config.
See **bitranox:coding-python-use-modern-libraries** for the wider list. Reach for the structured editors
for the other formats too: **bitranox:files-edit-json**, **bitranox:files-edit-toml**, **bitranox:files-edit-xml**.
**Safety:** never load untrusted YAML with PyYAML `yaml.load()` or a custom `Loader` - the
`!!python/object` tags execute arbitrary code. Use `yaml.safe_load`. `ruamel.yaml`'s default
`YAML()` is the safe round-trip loader (only `YAML(typ="unsafe")` is dangerous).
## Pa