Skip to main content

Sort TOML keys without changing table hierarchy

Project description

toml-tidy

Sort TOML keys while preserving table hierarchy and source formatting where tomlkit supports it.

Install

uv tool install .

Usage

toml-tidy pyproject.toml
toml-tidy pyproject.toml --check
toml-tidy pyproject.toml --in-place --order natural

Without --in-place, sorted TOML is written to standard output.

--check writes nothing and exits with status 1 when the file requires sorting.

--in-place rewrites the file only when sorting changes it.

Ordering

natural is the default and compares digit runs numerically, so item2 precedes item10.

alpha uses case-insensitive lexical order.

Both modes compare TOML's parsed logical key, not source quoting.

Dotted keys such as b.a = 2 sort with their sibling direct keys by their parsed dotted path, segment by segment, so a precedes b.a, which precedes b.z.

For example, [plugins.omo] precedes [plugins."omo-kit"], while the quoted spelling remains unchanged in output.

Preservation

Direct keys and sibling explicit table declarations are sorted recursively within their parent table.

Array-of-tables declarations such as [[items]] sort by name among their sibling tables, while the element order inside each array of tables remains unchanged.

Parent-child hierarchy remains unchanged.

Standalone comments move with the following key or table declaration.

Whitespace between entries remains after the preceding entry, and trailing whitespace remains at its table boundary.

Inline comments, value formatting, and key quoting remain attached to their parsed tomlkit items.

Keys inside inline tables are not reordered.

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

toml_tidy-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

toml_tidy-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toml_tidy-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 toml_tidy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc28472575861917966b330ad9bba9f05dd6c28fa444efc01944f89d41da9bfa
MD5 0f441e228573cd111ec24a7acd842048
BLAKE2b-256 d7934506c652a61ba83ac4ce1ec67688b61bf64ae32602e5e4e04aff78fe8a04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toml_tidy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 toml_tidy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a738b3fe4ae3f7447e69bd392faddccc6ad002c6a98c72538cfbc154797cc644
MD5 5a7e4bb8bf1164a80c7d825e25fb9d15
BLAKE2b-256 fa6a22e6343587c7ebc7f086b1ec82958169cb7e9673a0592119141d5ca690c5

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