codemod-yaml
Lib to modify yaml inplace
What it is and what it does
codemod-yaml is a library for making targeted edits to YAML files while preserving formatting. It uses tree-sitter to parse YAML and allows you to modify document structure programmatically, then write the result back with minimal changes to whitespace and layout on unmodified lines. This makes it suitable for automation tools and codemods that need to update YAML configuration files without introducing unnecessary formatting noise into version control diffs.
The library is inspired by tomlkit and pyupgrade, adopting their philosophy of format-preserving edits. It exposes a simple API where you parse a YAML file into a stream object, modify its contents like a Python dict, and serialize it back to bytes. The main constraint is Python version support: runtime usage works back to 3.9, but development and full mypy compatibility require 3.10-3.12.
Use it for:
- Update version strings in CI/CD configuration files while keeping formatting intact for minimal git diffs.
- Automate bulk changes to Kubernetes manifests or Helm values without reformatting the entire document.
- Build codemods that modify application configuration YAML files as part of refactoring or migration workflows.
- Programmatically edit Docker Compose or other YAML-based infrastructure-as-code files with surgical precision.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Modifies YAML documents in place with surgical precision, preserving all whitespace and formatting on unchanged lines to produce minimal diffs.
Yes. The package solves a real problem—format-preserving YAML edits—with low install friction, active maintenance, permissive licensing, and no known vulnerabilities. It is well-suited for automation and codemod tools where minimal diffs matter. The narrow Python version window for development is not a blocker for runtime use.
Install
codemod-yaml on PyPI
pip
pip install codemod-yamluv
uv add codemod-yamlpoetry
poetry add codemod-yamlInstalling codemod-yaml
Before you install
Low friction installation with only two runtime dependencies (tree-sitter and tree-sitter-yaml). Actively maintained with recent releases; last commit 2026-05-12. Requires Python 3.9+, though development and full linting support is limited to 3.10-3.12.
License in practice
MIT license permits commercial and private use with minimal restrictions; you must include a copy of the license and copyright notice.
Quickstart
from codemod_yaml import parse
stream = parse(somepath.read_bytes())
if stream["version"] == ["2.7"]:
stream["version"][:] = ["3.6", "3.13"]
somepath.write_bytes(stream.text)
Requires Python 3.9+; tree-sitter and tree-sitter-yaml must be installed and available.
Verify before relying
- Whether tree-sitter-yaml is automatically installed or must be installed separately as a system dependency.
- Performance characteristics and scalability limits for large or deeply nested YAML documents.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — tree-sitter, tree-sitter-yaml |
| Maintenance | actively maintained — 507 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 183,143/month — #10,072 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: codemod_yaml-0.7.0-py3-none-any.whl
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
codemod-toxParses and modifies tox.ini configuration…
permissive · top 15,000 on PyPI
imperfectParses and edits configparser-compatible INI…
permissive · top 15,000 on PyPI
tree-sitter-yamlA tree-sitter parser grammar for YAML files…
permissive · top 5,000 on PyPI
in-placeProvides an InPlace class for reading and…
permissive · top 15,000 on PyPI
htmlminMinifies HTML by removing unnecessary…
permissive · top 5,000 on PyPI
patchParses and applies unified diff patches to…
permissive · top 15,000 on PyPI
libcstlibcst parses Python source code into a…
permissive · top 1,000 on PyPI
yqyq is a command-line processor that applies jq…
permissive · top 5,000 on PyPI
yamlfixyamlfix is a command-line YAML formatter that…
copyleft · top 5,000 on PyPI