toml-sort is a Python library and command-line utility for sorting and formatting TOML files. It provides features like sorting tables and arrays of tables, preserving comments, and standardizing whitespace and indentation. The library is actively maintained, with frequent releases, and is currently at version 0.24.4.
pip install toml-sortVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to sort a TOML string programmatically using the `sort_toml_string` function.
Upgrade your Python environment to 3.9 or later.
Update `tomlkit` to version 0.13.2 or newer (`pip install --upgrade tomlkit`).
Upgrade to version 0.24.2 or later, which includes a fix for this regression.
Use `toml-sort --all <file>` or add `sort_all = true` under `[tool.toml_sort]` in your `pyproject.toml`.
Review the documentation for comment handling options if comments are unexpectedly altered or removed. Use `--no-comments`, `--no-header`, etc., as needed.
Be aware of the precedence order. Use CLI arguments for temporary overrides or specific runs, and `pyproject.toml` for project-wide default configurations.