Ruff vs Black comes down to scope: Black is only a code formatter, while Ruff is a linter plus a formatter designed as a drop-in replacement for Black, so one Rust binary can replace Black, isort, flake8 and a stack of flake8 plugins. Ruff's docs report that on Black-formatted projects such as Django and Zulip, over 99.9% of lines come out identical, with a documented list of intentional deviations. For most Python teams in late 2026, moving to Ruff is the sensible default; staying on Black makes sense if you need byte-for-byte Black output or rely on flake8 plugins Ruff does not implement.
This comparison is based on running both tools side by side: Ruff 0.17.6 (released November 19, 2026), Black 26.10.1, flake8 7.5.0 and isort 9.0.2 on Python 3.14, against the same sample project. It covers formatter compatibility and the real deviations, lint coverage (including Ruff 0.16's much bigger default rule set, which changes what you get out of the box), migrating pyproject.toml, pre-commit, CI and editor setup.
Ruff vs Black at a glance
| Black 26.10.1 | Ruff 0.17.6 | |
|---|---|---|
| What it does | Formats code | Lints, auto-fixes, sorts imports and formats |
| Implementation | Python (wheels compiled with mypyc) | Rust, single static binary |
| Formatting style | The Black style | Black's stable style, with documented deviations |
| Configurable style | Line length, target versions, string normalization, magic trailing comma | Same, plus quote style (double/single/preserve), indent style (spaces or tabs), line endings |
| Import sorting | No (use isort) | Yes, I rules via ruff check --fix |
| Lint rules | None | 977 rules in 0.17.6 (ruff rule --all), 400+ enabled by default |
| Notebooks | With the black[jupyter] extra |
Included by default since Ruff 0.6 |
| Markdown code blocks | No | Formatted by default since 0.16.0 |
| Style stability | Stable within a calendar year | Stable style follows Black; changes gated behind preview |
| Speed (vendor-reported) | n/a | "10-100x faster than existing linters (like Flake8) and formatters (like Black)" per the Ruff README |
That speed figure is Astral's own claim; I am not adding my own benchmark numbers. In practice, both are fast enough for pre-commit on a normal project. The speed difference matters most on large monorepos and in editor format-on-save.
How compatible is ruff format with Black?
The Ruff formatter documentation states that "When run over extensive Black-formatted projects like Django and Zulip, > 99.9% of lines are formatted identically." The FAQ adds the important caveat: on code that was not already Black-formatted, expect more differences, especially around end-of-line comments.
I formatted the same messy module with both tools. The only difference was inside an f-string:
--- black
+++ ruff format
@@ -11,7 +11,7 @@
t += i["price"] * i["qty"]
if discount == None:
return t
- print(f"test{discount + 0.5} total {t ** 2 + 10}")
+ print(f"test{discount + 0.5} total {t**2 + 10}")
return t - discount
Ruff formats the expressions inside f-string replacement fields; Black leaves them alone. Everything else, including quote normalization and the wrapping of a long requests.get(...) call, was identical.
The known deviations that actually show up
Ruff maintains a page of known deviations from Black. It lists 24, all described as intentional. The ones I would expect to see in a real diff when switching:
- F-string contents are formatted (shown above).
- Expanded tuples get parentheses. Black and Ruff split this line differently:
# input
values = (a_long_variable_name_one, a_long_variable_name_two), (c_value, d_value,)
# black
values = (a_long_variable_name_one, a_long_variable_name_two), (
c_value,
d_value,
)
# ruff format
values = (
(a_long_variable_name_one, a_long_variable_name_two),
(
c_value,
d_value,
),
)
- Pragma comments do not count toward line width. Trailing
# noqa,# type: ignoreand similar comments are ignored when Ruff decides whether a line is too long, so Ruff does not reflow code just because of a pragma. - Trailing end-of-line comments can lead Ruff to keep a statement expanded where Black would collapse it.
- Implicitly concatenated strings are joined when the result fits on one line.
- Line width uses Unicode width for all tokens, which matters for code with CJK identifiers or comments.
- Black's newer styles diverge in places. The page notes that Black 24+ parenthesizes long conditional expressions and annotations (Ruff defers this), and that Black 2025+ removes parentheses around single-element lists when safe, which Ruff preserves.
None of these change behaviour; they are layout differences. The practical impact is a one-time reformat commit when you switch.
Configuration that Black does not have
Black is deliberately unconfigurable. Ruff keeps Black's style but exposes a few knobs under [tool.ruff.format]:
quote-style = "double" | "single" | "preserve";preserveis the equivalent of Black'sskip-string-normalization = true.indent-style = "space" | "tab".line-ending,skip-magic-trailing-comma, anddocstring-code-format(formats code examples inside docstrings; off by default).
Suppression comments work the same way as Black's: # fmt: off / # fmt: on around statements and # fmt: skip at the end of a line. Ruff also honours YAPF's # yapf: disable / # yapf: enable.
Lint coverage: Ruff vs flake8 and isort
Black never lints, so the fairer lint comparison is Ruff against the flake8 + isort pairing that usually sits next to Black. Ruff implements all Pyflakes (F) rules, a subset of pycodestyle (E/W), and natively re-implements dozens of popular plugins, including flake8-bugbear, isort, pydocstyle, pyupgrade, flake8-bandit and flake8-simplify. The FAQ is also clear about the main limitation: "Ruff does not yet support third-party plugins." If your CI depends on an in-house flake8 plugin or a niche one Ruff has not re-implemented, that is a real reason to keep flake8 for that check.
Running the tools on the same unformatted module:
$ flake8 --max-line-length 88 src/
orders.py:1:1: F401 'os' imported but unused
orders.py:1:1: F401 'sys' imported but unused
orders.py:1:10: E401 multiple imports on one line
orders.py:3:1: F401 'shop.models' imported but unused
orders.py:12:17: E711 comparison to None should be 'if cond is None:'
orders.py:14:26: E221 multiple spaces before operator
orders.py:21:5: E722 do not use bare 'except'
$ ruff check --output-format concise src/
orders.py:1:1: I001 [*] Import block is un-sorted or un-formatted
orders.py:1:8: F401 [*] `os` imported but unused
orders.py:1:12: F401 [*] `sys` imported but unused
orders.py:3:18: F401 [*] `shop.models` imported but unused
orders.py:4:1: UP035 `typing.Dict` is deprecated, use `dict` instead
orders.py:4:1: UP035 `typing.List` is deprecated, use `list` instead
orders.py:8:18: UP006 [*] Use `list` instead of `List` for type annotation
orders.py:8:23: UP006 [*] Use `dict` instead of `Dict` for type annotation
orders.py:18:22: B006 Do not use mutable data structures for argument defaults
orders.py:21:5: E722 Do not use bare `except`
orders.py:28:8: RUF100 [*] Unused `noqa` directive (non-enabled: `E501`)
Found 11 errors.
[*] 7 fixable with `--fix` (1 unsafe fix available with `--fix --unsafe-fixes`).
Three things stand out:
- Ruff found real bugs flake8 missed by default: the mutable default argument (
B006, from bugbear) and outdated typing imports (UP035/UP006, from pyupgrade). It also replaced isort's separate check withI001. - Most findings are auto-fixable.
ruff check --fixremoved the unused imports, sorted the import block and rewroteList[Dict]tolist[dict]. - Ruff did not flag
== None(E711) by default, and flake8 did. That is not an oversight; it comes from the default-rule change described next.
Ruff 0.16 changed the defaults
Before July 2026, a zero-config Ruff enabled 59 rules (E4, E7, E9, F). The Ruff 0.16.0 changelog (released July 23, 2026) says Ruff "now enables a much larger set of rules by default (413, up from 59)", while 18 of the more opinionated pycodestyle and Pyflakes rules left the default set, including E401, E402, E711, E712, E731 and E741. The full list is on the Default Rules page; it now includes bugbear, pyupgrade, isort, pydocstyle, Pylint, flake8-bandit, flake8-simplify and many more.
Consequences for anyone comparing tools or upgrading:
- Old blog posts and Stack Overflow answers that say "Ruff's defaults are minimal" are out of date.
- Upgrading an unconfigured project from 0.15 to 0.16 or later produces a wave of new findings. The 0.16 release post gives the escape hatch: set
select = ["E4", "E7", "E9", "F"]under[tool.ruff.lint]to get the old behaviour back. - If you liked
E711/E712, add them back withextend-select, as in the config below. - 0.16 also made
ruff formatformat Python code blocks inside Markdown files by default. If your docs contain intentionally unformatted snippets, addextend-exclude = ["*.md"]or use<!-- fmt: off -->regions.
Migrating your pyproject.toml from Black, isort and flake8
A typical "before" configuration:
[tool.black]
line-length = 100
target-version = ["py312"]
skip-string-normalization = true
[tool.isort]
profile = "black"
known_first_party = ["shop"]
# .flake8
[flake8]
max-line-length = 100
extend-ignore = E203
per-file-ignores =
tests/*: S101
The Ruff equivalent, which I tested on the sample project:
[project]
requires-python = ">=3.12" # Ruff infers target-version from this
[tool.ruff]
line-length = 100
src = ["src", "tests"] # for first- vs third-party import detection
extend-exclude = ["migrations"]
[tool.ruff.format]
quote-style = "preserve" # was: skip-string-normalization = true
docstring-code-format = true
[tool.ruff.lint]
extend-select = ["E711", "E712"] # None/bool comparisons, dropped from defaults in 0.16
ignore = ["D1"] # don't require docstrings everywhere
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["S101", "PLR2004"] # asserts and magic numbers are fine in tests
[tool.ruff.lint.isort]
known-first-party = ["shop"]
Notes on the mapping:
E203no longer needs ignoring. It existed to stop flake8 fighting Black over slice spacing; Ruff does not enable the conflicting pycodestyle whitespace rules by default.- isort's
profile = "black"is effectively Ruff's default import style. The FAQ says Ruff's sorting is meant to be nearly equivalent to isort with that profile, with small differences around aliased imports, some inline comments and standard-library classification. Not every isort option exists in Ruff. - Formatter-conflicting rules. If you enable rules beyond the defaults, the formatter docs recommend avoiding
W191(tab indentation) andCOM812(missing trailing comma) alongsideruff format.E501can stay on, but the formatter only makes a best-effort attempt to wrap lines, so long strings and comments will still be reported.
Run the migration in this order, and commit each step separately so the history stays reviewable:
ruff check --fix . # lint fixes and import sorting first
ruff format . # then formatting
ruff check . # what's left needs a human
git log --format='%H' -1 >> .git-blame-ignore-revs # after committing the reformat
On my sample this left three findings that need judgement: E711, B006 and E722. Adding the reformat commit to .git-blame-ignore-revs keeps git blame useful; GitHub honours that file automatically.
Pre-commit and CI setups
Pre-commit
The Ruff README's hook configuration, which I ran against the sample repository, replaces the separate black, isort and flake8 hooks. Put the linter first so its fixes are formatted afterwards:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.6
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
For comparison, the Black-based stack it replaces typically looked like this (Black publishes a mypyc-compiled mirror for faster hooks):
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.10.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 9.0.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 7.5.0
hooks:
- id: flake8
GitHub Actions
In CI you want checks, not fixes. With astral-sh/ruff-action, which by default resolves the Ruff version from your pyproject.toml:
name: lint
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/ruff-action@v4.1.0 # runs `ruff check`
- uses: astral-sh/ruff-action@v4.1.0
with:
args: "format --check --diff"
ruff check --output-format github produces inline PR annotations if you run Ruff yourself instead of through the action. Pin the Ruff version in your dev dependencies: with Ruff's minor releases still carrying breaking changes (0.16 changed defaults, 0.17 changed the default target-version to Python 3.11), an unpinned CI can start failing on its own.
Editor integration
- VS Code: Black's integration is Microsoft's
ms-python.black-formatterextension, which runs Black as a formatter only; linting needs a second extension. Ruff'scharliermarsh.ruffextension uses Ruff's built-in language server and handles formatting, diagnostics, quick fixes and import organizing:
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
}
}
- PyCharm: the Ruff editor docs say PyCharm supports Ruff natively from 2025.3, under Python, Tools, Ruff. Black has had built-in PyCharm support for longer.
- Neovim, Helix, Zed, Kate: any LSP client can run
ruff server; on Neovim 0.11+ that is a smalllsp/ruff.luaplusvim.lsp.enable('ruff').
Having one tool in the editor and CI also removes a subtle source of churn: with Black + isort + flake8, it is easy for the editor to run a different version or config than CI. With Ruff, the same binary and pyproject.toml drive both.
If your team is also standardising the JavaScript side, the same consolidation argument applies there; see our Biome vs ESLint guide. And if you already use uv from the same vendor, uvx ruff check . runs Ruff without installing it, which our uv vs Conda vs Pixi comparison covers in the context of environment management.
When to stay on Black
- You need output identical to Black's because a downstream tool, a vendored codebase or an upstream project checks formatting with Black.
- Your organisation pins formatting to Black's yearly stability guarantee: Black's stability policy promises that code formatted by one release "will remain unchanged" with any other release in the same calendar year, with style changes only in the first release of a new year.
- You depend on flake8 plugins Ruff does not implement and do not want two linters. (You can still use
ruff formatwith flake8, but most teams then move the lint side too.)
Upgrading Python is a natural moment to switch, since you are touching tooling anyway; our Python 3.15 upgrade guide covers the rest of that checklist.
Frequently Asked Questions
Is Ruff a full replacement for Black?
For almost every project, yes. ruff format is designed as a drop-in replacement and its docs report over 99.9% identical lines on large Black-formatted codebases. The remaining differences are documented, intentional layout choices such as formatting inside f-strings and parenthesizing expanded tuples.
Can I use Ruff and Black together?
You can use Ruff's linter with Black as the formatter; the FAQ says they work together out of the box if both use the same line-length. Do not run both formatters on the same files, since their small deviations will fight each other on every commit.
Does ruff format sort imports?
No. Import sorting is a lint rule (I001). Run ruff check --select I --fix (or plain ruff check --fix, since I is in the default set from 0.16 onward) before ruff format.
Why does Ruff report far more errors after upgrading?
Ruff 0.16.0 expanded the default rule set from 59 to 413 rules. Either fix the new findings, ignore specific rules, or restore the old defaults with select = ["E4", "E7", "E9", "F"] under [tool.ruff.lint].
Is Ruff faster than Black?
Astral reports Ruff as 10-100x faster than existing linters like Flake8 and formatters like Black; that is a vendor-reported figure. For small projects both feel instant; the difference becomes noticeable on large codebases and in format-on-save.
How do I migrate from Black and isort to Ruff?
Move line-length and target version into [tool.ruff], map skip-string-normalization to quote-style = "preserve", move isort's known_first_party to [tool.ruff.lint.isort], replace the pre-commit hooks with ruff-check and ruff-format, then run ruff check --fix and ruff format in separate commits.
Conclusion
The Ruff vs Black decision is less about formatting, where the two are nearly identical, than about consolidation: Ruff replaces Black, isort, flake8 and a pile of plugins with one fast, well-documented tool configured in pyproject.toml. Switch unless you have a hard requirement for Black's exact output or for unsupported flake8 plugins, pin the Ruff version, account for the 0.16 default-rule expansion, and put the reformat commit in .git-blame-ignore-revs. To review the one-time reformat diff before committing, a code difference checker makes it easy to spot any deviation you care about.