Skip to main content

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

Project description

tomlrs-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). tomlrs-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 tomlrs-cli --help

Usage

Read an entire file

tomlrs-cli config.toml

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

Read a specific value

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

Outputs just the value at that path.

Write a value (to stdout)

tomlrs-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)

tomlrs-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
tomlrs-cli --path version.v26.alpine config.toml

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

# Bracket notation (same result)
tomlrs-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 tomlrs-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

uv build       # Produces sdist + wheel in dist/
uv 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:

tomlrs-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:

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

ModuleNotFoundError: tomlrt

Run via uv run tomlrs-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

tomlrs_cli-0.1.0.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.

tomlrs_cli-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file tomlrs_cli-0.1.0.tar.gz.

File metadata

  • Download URL: tomlrs_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","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 tomlrs_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 51004c583b3771173f16b4d12ee9ed19aaa07da7321ceb21e20c6626a4739d0c
MD5 f0d49baabe53cb6bb45346eafc262f56
BLAKE2b-256 fef64c612a1956b6e154a8b65e9b6ac41404ee928b5f7196be66886b55f5be18

See more details on using hashes here.

File details

Details for the file tomlrs_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tomlrs_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","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 tomlrs_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 118c7a9f5cf76213b90955ba47ca6aa3b8ee291651f8a72452a00cd740df8e91
MD5 f4b982f65ab27bf5cfd3977396727e68
BLAKE2b-256 603bdf2d4052987e86c144e32af254349f8f6e133f4f46bcfc73354d92fab36f

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