Comparison October 30, 2026 · 5 min read

Black vs autopep8 vs YAPF vs Ruff: Which Python Formatter Should You Use?

Python has four formatters you will see in real projects. They differ less in what the code looks like than in how much they change and how much they let you configure. Here is how to choose.

The short answer

At a glance

BlackRuff formatterautopep8YAPF
ApproachReformats everything to one styleBlack-compatible styleFixes PEP 8 violations onlyReformats to a configurable style
ConfigurationVery little (line length, quotes)Very little, like BlackWhich fixes to applyMany style knobs, plus pep8 / google presets
Diff on first runLargeLargeSmallLarge
SpeedFastVery fast (written in Rust)FastSlower on big files
Installpip install blackpip install ruffpip install autopep8pip install yapf
Runblack .ruff format .autopep8 -i -r .yapf -i -r .

Black: "any colour you like, as long as it's black"

Black takes your code, parses it, and prints it back in its own style, ignoring how you laid it out (except for the magic trailing comma). That's the point: two developers who format the same code always get the same result, so layout never comes up in code review.

The trade-off is control. You can set the line length and turn off quote normalization, and that's about it. If you don't like a choice Black makes, you live with it. Most teams find that a good deal.

Ruff formatter: Black's style, much faster

Ruff started as a very fast linter and now includes a formatter designed as a drop-in replacement for Black. Output is almost identical to Black's, and it is much faster on large repositories. If you already run Ruff for linting, using its formatter means one tool and one config file instead of two.

autopep8: minimal changes

autopep8 doesn't impose a style. It looks for PEP 8 violations — wrong indentation, missing whitespace, overly long lines — and fixes just those. Code that's already reasonable is left as it is.

autopep8 --in-place app.py              # safe whitespace fixes
autopep8 --in-place --aggressive app.py # also makes non-whitespace changes

This is useful on a large, old codebase where reformatting every file would bury real changes in the git history. The downside is that two developers can still format the same code differently.

YAPF: configurable

YAPF, from Google, also reformats everything, but you choose the style. Start from a preset and change individual settings in .style.yapf or pyproject.toml:

[tool.yapf]
based_on_style = "pep8"
column_limit = 100

If your organisation has a detailed existing style guide that Black doesn't match, YAPF can usually express it. The cost is that every option is a decision your team has to make and maintain.

Can I use more than one?

Not on the same files — two formatters with different rules will keep undoing each other's changes. Pick one formatter, and pair it with a linter (Ruff, Flake8 or Pylint) to catch problems formatting can't fix, like unused imports or undefined names.

Try Black without installing anything

Paste Python into the free formatter and see exactly what Black would change.

Open the Python Formatter

Summary

New to formatters? Start with How to Format Python Code.