toml-sort
Toml sorting library
What it is and what it does
toml-sort is a command-line utility and Python library for sorting and formatting TOML configuration files. It sorts tables and arrays of tables, optionally sorts keys within tables, and preserves comments and whitespace structure where possible. The tool can be used as a standalone CLI tool, integrated into build workflows for linting, or called as a Python library from other code.
The package handles four types of comments (header, footer, inline, and block) with fine-grained control over which to preserve or strip. It supports configuration via pyproject.toml with per-key overrides using glob-style wildcards, making it suitable for projects that want consistent TOML formatting across multiple files or as part of a CI/CD pipeline.
Use it for:
- Normalize and sort TOML files in a project as part of pre-commit hooks or CI linting.
- Automatically organize pyproject.toml or other config files to a consistent structure.
- Batch-format multiple TOML files with consistent rules via CLI or programmatic API.
- Check whether TOML files conform to a sorted format without modifying them.
- Configure per-section sort rules for complex TOML structures using overrides.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Command-line utility and Python library to sort and format TOML files while preserving comments and standardizing whitespace.
Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real problem for projects using TOML configuration files. It is useful both as a CLI tool for ad-hoc formatting and as part of automated workflows. The permissive MIT license poses no barrier.
Install
toml-sort on PyPI
pip
pip install toml-sortuv
uv add toml-sortpoetry
poetry add toml-sortInstalling toml-sort
Before you install
Low friction install with a single runtime dependency (tomlkit). Active maintenance with recent releases and no known vulnerabilities.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions.
Quickstart
pip install toml-sort
# Command line
toml-sort input.toml -o output.toml
# Or in-place
toml-sort --in-place input.toml
# Check without modifying
toml-sort --check input.toml
Requires Python 3.9 or later.
Verify before relying
- Whether the library API (as opposed to CLI) is documented and stable for programmatic use.
- Performance characteristics on large TOML files or deeply nested structures.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — tomlkit |
| Maintenance | actively maintained — 143 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 723,427/month — #5,226 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: toml_sort-0.24.4-py3-none-any.whl
Keywords: toml, sort, cli, unix, utility
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
sort-linesAlphabetizes lines in files based on…
permissive · top 15,000 on PyPI
tomlParses and generates TOML configuration files,…
permissive · top 1,000 on PyPI
tox-toml-fmtFormats tox.toml files with consistent style…
permissive · top 15,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
rtomlrtoml parses and serializes TOML files and…
permissive · top 5,000 on PyPI
tomlrtReads and writes TOML files while preserving…
permissive · top 15,000 on PyPI
pyproject-fmtFormats pyproject.toml files with consistent,…
permissive · top 5,000 on PyPI
tomli-wTomli-W serializes Python dictionaries to TOML…
permissive · top 1,000 on PyPI
natsortnatsort provides natural sorting for strings…
permissive · top 1,000 on PyPI
toml-cliCommand-line tool for reading, writing, and…
permissive · top 15,000 on PyPI