{"id":5080,"library":"toml-sort","title":"TOML Sort","description":"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.","status":"active","version":"0.24.4","language":"en","source_language":"en","source_url":"https://github.com/pappasam/toml-sort","tags":["TOML","formatting","sorting","CLI","configuration","pre-commit"],"install":[{"cmd":"pip install toml-sort","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Requires Python 3.9 or newer. Support for Python 3.7 and 3.8 was dropped in version 0.24.0.","package":"python","optional":false},{"reason":"Core dependency for TOML parsing and manipulation. Version >=0.13.2 is required; older versions (<0.13.2) are no longer supported since v0.24.0.","package":"tomlkit","optional":false}],"imports":[{"symbol":"sort_toml_string","correct":"from toml_sort.tomlsort_tool import sort_toml_string"},{"symbol":"sort_toml_file","correct":"from toml_sort.tomlsort_tool import sort_toml_file"}],"quickstart":{"code":"from toml_sort.tomlsort_tool import sort_toml_string\n\nunsorted_toml = '''\n[database]\nports = [8000, 8001, 8002]\nenabled = true\n\n[owner]\nname = \"Tom\"\ndob = 1979-05-27T07:32:00-08:00\n'''\n\nsorted_toml = sort_toml_string(unsorted_toml)\nprint(sorted_toml)","lang":"python","description":"Demonstrates how to sort a TOML string programmatically using the `sort_toml_string` function."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or later.","message":"Version 0.24.0 dropped official support for Python 3.7 and 3.8. Users should upgrade to Python 3.9 or newer.","severity":"breaking","affected_versions":">=0.24.0"},{"fix":"Update `tomlkit` to version 0.13.2 or newer (`pip install --upgrade tomlkit`).","message":"Version 0.24.0 removed support for `tomlkit` versions older than 0.13.2. Ensure `tomlkit` is updated.","severity":"breaking","affected_versions":">=0.24.0"},{"fix":"Upgrade to version 0.24.2 or later, which includes a fix for this regression.","message":"Sorting inline tables with keys containing trailing spaces could cause a `ValueError` in versions 0.24.0 and 0.24.1. This was a regression.","severity":"gotcha","affected_versions":"0.24.0, 0.24.1"},{"fix":"Use `toml-sort --all <file>` or add `sort_all = true` under `[tool.toml_sort]` in your `pyproject.toml`.","message":"By default, `toml-sort` only sorts non-inline tables and arrays of tables. To sort all keys, including scalars and non-table entries, use the `--all` CLI option or configure `sort_all = true` in `pyproject.toml`.","severity":"gotcha","affected_versions":"All"},{"fix":"Review the documentation for comment handling options if comments are unexpectedly altered or removed. Use `--no-comments`, `--no-header`, etc., as needed.","message":"Comment handling can be complex. While `toml-sort` strives to preserve comments, specific types of comments (header, footer, inline, block) can be selectively disabled via CLI switches, which will lead to their removal.","severity":"gotcha","affected_versions":"All"},{"fix":"Be aware of the precedence order. Use CLI arguments for temporary overrides or specific runs, and `pyproject.toml` for project-wide default configurations.","message":"`toml-sort` can be configured via `pyproject.toml` under the `[tool.toml_sort]` section. Command-line arguments will always take precedence over `pyproject.toml` settings in case of conflicts.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}