How to format pyproject.toml with taplo
uv does not include a built-in formatter for pyproject.toml. Taplo is a TOML formatter and validator that keeps pyproject.toml files consistently styled across a project.
Format with uvx
Run taplo as a one-off command without installing it:
uvx taplo fmt pyproject.tomlTo check formatting without modifying files (useful in CI):
uvx taplo check pyproject.tomlConfigure taplo
Taplo works with zero configuration, but you can customize its behavior. Add a [tool.taplo] section to your pyproject.toml:
[tool.taplo]
include = ["pyproject.toml"]
[[tool.taplo.rule]]
include = ["pyproject.toml"]
keys = ["dependencies", "*-dependencies"]
[tool.taplo.rule.formatting]
reorder_keys = trueThis configuration reorders keys within dependency tables alphabetically. For the full list of formatting options, see the Taplo configuration reference.
You can also use a standalone .taplo.toml file in your project root if you prefer to keep tool configuration separate.
Add taplo as a pre-commit hook
To run taplo automatically before each commit, add it to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/tamasfe/taplo
rev: release-taplo-cli-0.9.3
hooks:
- id: taploFor setup instructions, see How to set up pre-commit hooks for a Python project.