Skip to main content

Read and write values in TOML files while preserving comments and formatting.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tomlrt_cli-1.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tomlrt_cli-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file tomlrt_cli-1.0.1.tar.gz.

File metadata

  • Download URL: tomlrt_cli-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for tomlrt_cli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 131931ec07f486209d01abdc4965b1c6de80d49438bd96f597e34558d1459f17
MD5 5922dc2c04a4e71f1a3b5763e93d74b0
BLAKE2b-256 8c4fe4e2fed9653f5a0904443d2c3fce5a6135cce134b767fddd0992e3d71df2

See more details on using hashes here.

File details

Details for the file tomlrt_cli-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: tomlrt_cli-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for tomlrt_cli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dbb9c5bd08992fddd8d9a7fffe461e7a7a66fb236459e5033d9607cf6f6f4859
MD5 b533ae9412b4938afb825e9be23da9e4
BLAKE2b-256 af39c218858cb9b257b5a886625f0c90700d46302eb478b9173c4ed69e27dbc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page