Ruff: Linting and Formatting Python Fast Enough to Run on Every Save
One Rust binary replaces Flake8, isort, pyupgrade, pydocstyle and Black

Contents
Before Ruff, my Python projects carried a small zoo of linting tools, each doing one job and each with its own configuration file, its own cache directory, and its own multi-second startup cost: Flake8 for style violations, isort for import ordering, pyupgrade for modernising syntax, pydocstyle for docstring conventions, and Black for formatting. Running the full set on a project of a few hundred files took long enough that I’d configured it to run on commit rather than on save, which meant I found out about violations in batches, after I’d already moved on mentally to the next file. That workflow was tolerable. It was never good.
Ruff comes from Astral, the same team whose uv package manager did the equivalent job for pip and Poetry — replacing a slow Python-native tool with a fast Rust one while keeping the same file formats and largely the same workflow. Ruff is a Python linter and formatter written in Rust that reimplements the rule sets of Flake8 (and dozens of its plugins), isort, pyupgrade, pydocstyle, and — as of its formatter — a Black-compatible code formatter, all in one binary. The headline claim is speed: ten to a hundred times faster than the tools it replaces, run as a single pass rather than five separate processes. Having used it daily for a few months now on projects ranging from small automation scripts to a data pipeline with a genuinely large codebase, the speed claim holds up, and it changed something more important than the numbers suggest — it made linting fast enough to run on every save without the editor stuttering, which changes how you actually use it.
Why running five tools was worse than it sounds
The problem with a five-tool linting stack was never really about total runtime, though a full run across a large project could take ten or fifteen seconds. It was that each tool started its own Python interpreter, imported its own dependencies, and walked the file tree independently, so the overhead compounded in a way that felt worse than the sum of its parts. Editor integrations made this bearable by running tools in the background, but “bearable” is a low bar. A save-triggered lint that takes two seconds is invisible. One that takes eight seconds is a context switch, and after enough of those you start ignoring the linter until commit time, at which point it’s an obstacle rather than a guide.

There was also a correctness cost to running separate tools: isort and Black could disagree about import formatting in edge cases, Flake8’s line-length rules and Black’s line-wrapping decisions occasionally fought each other, and keeping five configuration files in sync — .flake8, setup.cfg, pyproject.toml sections for three different tools — meant configuration drift was a constant low-grade annoyance across a team’s repositories.
What Ruff actually checks
Ruff ships with several hundred lint rules organised into named rule sets, most directly mirroring a Flake8 plugin you may already recognise:
E/W— pycodestyle errors and warnings (the core PEP 8 checks Flake8 has always run).F— Pyflakes (unused imports, undefined names, and similar logic errors).I— isort-equivalent import sorting.UP— pyupgrade (flags old-style syntax that can be modernised for your target Python version).B— flake8-bugbear (common bug patterns that aren’t strictly PEP 8 violations, like mutable default arguments).SIM— flake8-simplify (unnecessarily complex code that has a simpler equivalent).C90— mccabe complexity checks.
There’s also a D rule set covering docstring conventions (the pydocstyle equivalent), configurable to Google, NumPy, or PEP 257 style via [tool.ruff.lint.pydocstyle] convention = "google". I turn this on selectively — for a shared library that other scripts import, consistent docstrings genuinely help; for a one-off automation script that only I will ever read, enforcing docstring style is more overhead than it’s worth, and I leave D out of the select list entirely for those projects.
You don’t need to memorise the letters. ruff check --select ALL will show you everything available, and the sane starting point most projects converge on is a moderate subset rather than everything at once — turning on every rule immediately tends to produce a wall of findings on any pre-existing codebase, most of which aren’t worth the churn of fixing in one pass.
Configuration
Ruff reads configuration from pyproject.toml, which means one file instead of the five I used to juggle:
| |
Running it is deliberately simple — two commands cover linting and formatting:
| |
That last comment isn’t marketing copy — it’s what I actually measured on a project of that size, and it’s the number that made me trust the “run on every save” claim enough to wire it into my editor rather than leaving it as a pre-commit step.
Wiring it into pre-commit and CI
For anyone running pre-commit hooks, Ruff ships an official hook that replaces the separate Flake8, isort, and Black hooks in one entry:
| |
In CI, the same two commands run without --fix, so a violation fails the build instead of silently rewriting code the reviewer never sees:
| |
If you’re already running self-hosted GitHub Actions runners, the speed difference is even more noticeable, because you’re not paying for a hosted runner’s cold-start overhead on top of the linting itself — a full check-and-format pass on a self-hosted runner finishes before some hosted runners have finished provisioning.
Troubleshooting the common friction points
A rule fires on code you consider intentional. Every rule can be silenced per-line with # noqa: RULE_CODE, or per-file with the per-file-ignores table shown above. Resist the urge to add a blanket # noqa with no code attached — it silences everything on that line, including future violations you’d actually want to catch.
The formatter disagrees with existing Black-formatted code. Ruff’s formatter targets Black compatibility closely but isn’t a byte-for-byte guarantee across every Black version and configuration. If you’re migrating a codebase already formatted with Black, run ruff format . once, review the diff, and commit it as a single dedicated formatting commit rather than mixing it into a feature change — the same discipline you’d want for any large-scale reformat.
ruff check --fix changes more than expected. Some fixes Ruff applies are marked “unsafe” because they can change runtime behaviour in edge cases (certain SIM simplifications, for instance). By default, --fix only applies safe fixes; if you want the full set, --unsafe-fixes is opt-in and deliberately named to make you think twice before scripting it into CI.
Import sorting conflicts with an existing isort configuration. Ruff’s I rule set covers the common isort options (known-first-party, section ordering, combine-as-imports) via [tool.ruff.lint.isort], but it doesn’t support every isort plugin or profile. If your project depends on an isort profile Ruff doesn’t replicate, it’s worth checking the isort compatibility table in Ruff’s documentation before assuming a migration will be a straight swap.
Editor integration
The editor experience is where the speed actually pays off day to day. Ruff ships a language-server implementation (ruff server, formerly the separate ruff-lsp package) that editors talk to over the Language Server Protocol, the same mechanism Pyright and most modern type checkers use. In VS Code, the official Ruff extension wires it up with a couple of settings:
| |
Neovim users get the same server through nvim-lspconfig’s ruff entry, and it slots into whatever completion and diagnostics setup you’re already running for other language servers. What actually changed my habits wasn’t the integration mechanism, which is unremarkable and works the way every other LSP-backed linter does — it was that the diagnostics update fast enough to feel synchronous with typing, rather than lagging a beat behind the way a slower background linter does. Squiggly underlines that appear before you’ve finished the line train you to fix things immediately instead of accumulating a backlog you deal with later.
A concrete before-and-after
To put a number on the abstract “it’s faster” claim, here’s what changed on a real project of mine: a data-collection service with roughly 340 Python files. The old five-tool pipeline (Flake8 with six plugins, isort, pyupgrade, pydocstyle, Black) took around eleven seconds for a full check-and-format pass on a cold cache, and the pre-commit hook — running against staged files only — still added a noticeable pause to every commit. After switching to Ruff with an equivalent rule selection, the same full pass takes under 400 milliseconds. The pre-commit hook is no longer something I notice happening at all.
The more interesting change wasn’t the raw number, it was what I stopped doing because of it. I used to batch style fixes into their own commits because running the linters mid-edit was disruptive enough to break flow. Now I fix a violation the moment it’s flagged, which means style-only commits have essentially disappeared from that repository’s history — the linter’s output and the code change happen together, the way code review always assumed they would.
One more habit worth adopting: ruff check --diff
Before running --fix on a codebase you haven’t linted before, ruff check --diff shows exactly what would change without touching a single file — the same idea as git diff for a hypothetical commit. On a legacy codebase inheriting years of inconsistent style, I run this first, skim it for anything that looks like it would change behaviour rather than style (rare, but it happens with some of the bugbear rules), and only then run --fix for real. It’s a five-second habit that’s saved me from committing an automated fix I hadn’t actually reviewed more than once.
What it doesn’t do
Ruff is a linter and formatter, not a type checker — it won’t catch the class of bugs that mypy or Pyright catch, like passing a string where a function expects an integer, and it won’t validate that your type hints are internally consistent across a call chain. I still run a type checker separately in CI; Ruff and a type checker are complementary tools solving different problems, and conflating them is a common early mistake for teams adopting Ruff and assuming it covers everything Flake8’s ecosystem of plugins ever touched. It also doesn’t replace a security-focused scanner like Bandit for anything beyond the handful of security-adjacent rules (S prefix) it has adopted from flake8-bandit — useful as a first pass, not a substitute for a dedicated audit if that’s part of your process.
Is it worth switching
For any Python project still running Flake8, isort, and Black as three separate tools, switching to Ruff is close to a strict improvement: same rule coverage for the common cases, one configuration file instead of three, and a speed difference large enough to change your workflow rather than just your CI minutes. The migration for a typical project is an afternoon: install Ruff, port your Flake8 select/ignore list into [tool.ruff.lint], run ruff format . once and review the diff, then delete the old tool configs.
The case for holding off is narrow: if your project leans heavily on a specific Flake8 plugin Ruff hasn’t reimplemented, or a type-checker-adjacent Flake8 plugin you can’t replace, check Ruff’s rule list for that plugin’s equivalent before committing to a full migration. For everyone else — and that’s the overwhelming majority of Python projects I’ve seen — this is one of the rare developer tooling upgrades with almost no downside and an immediately visible payoff every single time you hit save. Even the migration effort scales down gracefully: a small personal script collection can adopt Ruff in ten minutes by deleting the old configs and dropping in a single [tool.ruff] block, while a large multi-team codebase can roll it out gradually by starting with a narrow select list matching the existing Flake8 configuration and widening it over subsequent sprints once the team is comfortable with the new diagnostics. Either path ends at the same place: one fast tool instead of several slow ones, and a lint pass quick enough that nobody has a reason to skip it.




