# How to format pyproject.toml with taplo


[uv](https://pydevtools.com/handbook/reference/uv.md) does not include a built-in formatter for `pyproject.toml`. [Taplo](https://taplo.tamasfe.dev/) is a TOML formatter and validator that keeps `pyproject.toml` files consistently styled across a project.

> [!TIP]
> Taplo formats any TOML file but treats `pyproject.toml` as plain TOML. To sort dependency lists, normalize version specifiers, and generate Python version classifiers, reach for [pyproject-fmt](https://pydevtools.com/handbook/reference/pyproject-fmt.md), a packaging-aware formatter dedicated to `pyproject.toml`.

## Format with uvx

Run taplo as a one-off command without installing it:

```bash
uvx taplo fmt pyproject.toml
```

To check formatting without modifying files (useful in CI):

```bash
uvx taplo check pyproject.toml
```

## Configure taplo

Taplo works with zero configuration, but you can customize its behavior. Add a `[tool.taplo]` section to your `pyproject.toml`:

```toml
[tool.taplo]
include = ["pyproject.toml"]

[[tool.taplo.rule]]
include = ["pyproject.toml"]
keys = ["dependencies", "*-dependencies"]

[tool.taplo.rule.formatting]
reorder_keys = true
```

This configuration reorders keys within dependency tables alphabetically. For the full list of formatting options, see the [Taplo formatter options](https://taplo.tamasfe.dev/configuration/formatter-options.html).

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`:

```yaml
repos:
  - repo: https://github.com/tamasfe/taplo
    rev: release-taplo-cli-0.9.3
    hooks:
      - id: taplo
```

For setup instructions, see [How to set up pre-commit hooks for a Python project](https://pydevtools.com/handbook/how-to/how-to-set-up-pre-commit-hooks-for-a-python-project.md).

## Learn More

- [Taplo documentation](https://taplo.tamasfe.dev/)
- [pyproject-fmt reference](https://pydevtools.com/handbook/reference/pyproject-fmt.md)
- [pyproject.toml reference](https://pydevtools.com/handbook/reference/pyproject.toml.md)
- [How to set up pre-commit hooks for a Python project](https://pydevtools.com/handbook/how-to/how-to-set-up-pre-commit-hooks-for-a-python-project.md)
