pyproject-fmt is an opinionated formatter for pyproject.toml files, designed to enforce a consistent format similar to how Black formats Python code. It intentionally provides minimal configuration options to establish a single standard format, which helps in reducing configuration time, producing smaller diffs, and simplifying code reviews. The current version is 2.21.1, and it maintains an active release cadence.
pip install pyproject-fmtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use `pyproject-fmt` to format a `pyproject.toml` file. The `run` function processes the file(s) and returns an exit code, where 0 indicates success. It also creates a temporary `pyproject.toml` if one doesn't exist for a runnable example.
Embrace the opinionated formatting or use pre-commit hooks to automate formatting without manual intervention. Understand that configuration choices are deliberately limited.
Prefer `uv tool install pyproject-fmt` or `pipx install pyproject-fmt` for managing the tool.
Review the project's documentation on 'Table Organization' to understand the enforced structure. Allow the formatter to apply its intended order.
Familiarize yourself with the string wrapping rules in the documentation. Use `skip_wrap_for_keys` in configuration if specific string keys should not be wrapped.
Be aware of the configuration precedence. If you're using a shared config, ensure local project settings aren't unintentionally overriding it, or deliberately use local settings for project-specific overrides.
Accept that lists will be formatted according to the tool's strict line-length rules, expanding to multiple lines if necessary, without the 'magic comma' influencing this behavior.
Install `pyproject-fmt` using pip, preferably within a virtual environment: `pip install pyproject-fmt`
Provide a valid path to an existing `pyproject.toml` file or a directory containing one. For the current directory, use: `pyproject-fmt .`
Review and correct the TOML syntax in your `pyproject.toml` file to resolve the parsing issue.