TOML Editor
Edit .toml files without shell escaping issues. Three tools available:
| Tool | Lang | In-place | Pros | Reference |
|---|---|---|---|---|
| toml-cli | Rust | No (prints) | Format-preserving, comments intact | references/toml-cli.md |
| yq | Python | Yes (-i) |
jq-like syntax, widely known | references/yq.md |
| tmq | Go | Yes | Zero-dependency binary, fast | references/tmq.md |
Recommendation: Prefer toml-cli for Pi-hole configs and other human-edited files where comment preservation matters. Prefer yq -t -i for automated transformations (CI, scripts). Pull the reference doc for your chosen tool above.
Installation (one-time)
# toml-cli — Rust
cargo install toml-cli
# or no-install: npx @toml-tools/editor set config.toml key "value"
# yq — Python
pip install yq
# or no-install: uvx yq -t -i '.key = "value"' config.toml
# tmq — Go
go install github.com/tmq/tmq@latest
Workflows
Adding a custom DNS record to Pi-hole v6
yq -t -i '.dns.hosts += ["10.13.37.180 myservice.lan"]' /etc/pihole/pihole.toml
pihole restartdns
Patching pyproject.toml
# Add a dependency
yq -t -i '.project.dependencies += ["httpx>=0.27"]' pyproject.toml
# Add optional dependency group
yq -t -i '.project.optional-dependencies.dev = ["pytest>=8"]' pyproject.toml
# Set Python version requirement
yq -t -i '.project.requires-python = ">=3.11"' pyproject.toml
Array append with toml-cli
toml get /etc/pihole/pihole.toml dns.hosts \
| python3 scripts/append-toml-array.py "10.13.37.180 radarr.lan" \
| toml set /etc/pihole/pihole.toml dns.hosts
Validation
python3 scripts/validate-toml.py file.toml
# or inline:
python3 -c "import tomllib; tomllib.load(open('file.toml','rb'))"
Safety
- Back up before bulk edits:
cp file.toml file.toml.bak - Validate after every edit
yqstrips comments and reorders keys — usetoml-cliwhen formatting matters- toml-cli has no
-i— pipe to temp file and rename - No tool does true inline editing — they rewrite the file. Use version control.