Skip to main content

tomlrt-cli

A command-line tool for reading and writing values in TOML files while preserving comments, formatting, and key ordering. Think jq, but for TOML.

Why use this?

Most TOML libraries either can't write (Python's tomllib) or destroy comments and formatting when they do (tomli-w). tomlrt-cli uses a round-trip parser under the hood, so you can update a single value in a TOML file from a shell script or CI pipeline without mangling the rest of the document.

Common use cases:

  • Bumping version numbers in pyproject.toml from CI
  • Pinning container digests in config files
  • Reading specific values for shell variable assignment
  • Scripted config modifications that respect hand-crafted formatting

Prerequisites

  • Python 3.12 or newer
  • uv (for development and running from source)

No prerequisites for end users — install and run directly with uvx:

uvx tomlrt-cli --help

Usage

Read an entire file

tomlrt-cli config.toml

Outputs the full document to stdout (comments and formatting preserved).

Read a specific value

tomlrt-cli --path project.version pyproject.toml

Outputs just the value at that path.

Write a value (to stdout)

tomlrt-cli --path project.version --value "2.0.0" pyproject.toml

Outputs the full modified document to stdout. The original file is not changed.

Write a value (to file)

tomlrt-cli --path project.version --value "2.0.0" --output pyproject.toml pyproject.toml

Writes the modified document to the output file. Use the same path for input and output to edit in-place.

Path syntax

Keys are separated by dots. Keys that contain dots or special characters can be quoted or bracketed:

# Simple dotted path
tomlrt-cli --path version.v26.alpine config.toml

# Quoted key (key "3.14" contains a dot)
tomlrt-cli --path 'version."3.14".alpine' config.toml

# Bracket notation (same result)
tomlrt-cli --path 'version["3.14"].alpine' config.toml

All three notations are interchangeable and can be mixed in a single path.

Flags

Flag Short Description
--path -p TOML key path to read or write
--value -v Value to assign at the given path
--output -o Write result to this file (default: stdout)
--version -V Print version and exit
--help -h Print help and exit

Development

Setup

git clone <repo-url>
cd tomlrt-cli
uv sync

Running tests

This project uses Tryke, a Rust-based test runner with a Jest-style API:

task test

The test suite has two files:

  • tests/test_cli.py — Integration tests that exercise main() end-to-end with temporary TOML files. Verifies argument parsing, file I/O, and output routing.
  • tests/test_parse_path.py — Unit tests for the path parser covering dotted, quoted, and bracket notation. Includes a Hypothesis property test that fuzzes bare-key round-tripping to catch edge cases.

Linting and formatting

task lint

Build and publish

task build       # Produces sdist + wheel in dist/
task publish     # Upload to PyPI

Troubleshooting

KeyError when using --path

The path does not exist in the document. Double-check key names — TOML keys are case-sensitive. Run without --path to see the full document structure.

Quoted keys not working

Make sure your shell isn't stripping the quotes. Wrap the entire --path value in single quotes:

tomlrt-cli --path 'version."3.14".alpine' config.toml

--value didn't change the file

Without --output, changes go to stdout only. Add --output <file> to persist:

tomlrt-cli --path key --value new --output config.toml config.toml

ModuleNotFoundError: tomlrt

Run via uv run tomlrt-cli (which manages the virtualenv) or install with uv sync first.

Metadata

Release files for tomlrt-cli 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tomlrt-cli 1.0.1
File Size Uploaded
tomlrt_cli-1.0.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tomlrt-cli 1.0.1
File Interpreter ABI Platform
tomlrt_cli-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / tomlrt_cli-1.0.1.tar.gz

Download URL tomlrt_cli-1.0.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
131931ec07f486209d01abdc4965b1c6de80d49438bd96f597e34558d1459f17
BLAKE2b-256 checksum
How to use checksums
8c4fe4e2fed9653f5a0904443d2c3fce5a6135cce134b767fddd0992e3d71df2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / tomlrt_cli-1.0.1-py3-none-any.whl

Download URL tomlrt_cli-1.0.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbb9c5bd08992fddd8d9a7fffe461e7a7a66fb236459e5033d9607cf6f6f4859
BLAKE2b-256 checksum
How to use checksums
af39c218858cb9b257b5a886625f0c90700d46302eb478b9173c4ed69e27dbc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page