Ruff is a Python linter and formatter written in Rust that replaces Flake8, Black, isort, pyupgrade and autoflake with a single tool. You configure it once in pyproject.toml, run ruff check to lint and ruff format to format, and it finishes in well under a second on most codebases.
Most Python projects still run five code-quality tools, each with its own config, and wire them together with pre-commit. Each tool is fine alone. Running all of them on every save and every CI run is where the friction lives, and slow tools get skipped. This guide covers what Ruff does, how it compares with Pylint, and the exact setup I use for editor, pre-commit and CI. It is current as of Ruff 0.17.6 (November 2026).
You’ll learn:
- What Ruff is and which tools it replaces
- The difference between
ruff checkandruff format - How Ruff compares with Pylint, Flake8 and Black
- A
pyproject.toml, pre-commit and GitHub Actions setup you can copy - How to migrate an existing codebase without drowning in warnings
What is Ruff in Python?
Ruff is an open source linter and code formatter for Python, built in Rust by Astral, the company that also makes the uv package manager. It parses your code once and runs hundreds of lint rules in that single pass, which is why it is typically 10 to 100 times faster than the Python tools it replaces.
What it covers:
| Job | Tool it replaces | Ruff command or rule prefix |
|---|---|---|
| Lint errors and style | Flake8, pycodestyle, Pyflakes | ruff check (E, W, F) |
| Bug-prone patterns | flake8-bugbear and other plugins | ruff check (B, C4, SIM, …) |
| Import sorting | isort | ruff check (I) |
| Modern syntax upgrades | pyupgrade | ruff check (UP) |
| Removing unused code | autoflake | ruff check --fix (F401, F841) |
| Formatting | Black | ruff format |
Ownership note: OpenAI announced on March 19, 2026 that it is acquiring Astral. Both companies have said Ruff, uv and ty stay open source under their existing licenses.
ruff check vs ruff format: what each command does
ruff check finds and fixes problems in what the code does; ruff format only changes how the code looks. They are separate commands, and you should run and enforce both.
ruff check is the linter. It reports issues such as unused imports, undefined names and outdated syntax, each with a rule code:
import os
import sys
print("Hello")
F401 [*] `sys` imported but unused
The [*] means the fix is safe to apply automatically. ruff check --fix . removes the import for you.
ruff format is the formatter. It normalizes spacing, quotes and line breaks, and never changes logic:
# before
x=1+2
print( x )
# after
x = 1 + 2
print(x)
Import sorting lives under ruff check, not ruff format: enable the I rules and run ruff check --select I --fix (or include I in your config) to sort imports.
How to read Ruff rule codes
The letter prefix tells you which original tool the rule comes from: F is Pyflakes, E and W are pycodestyle, B is flake8-bugbear, I is isort, UP is pyupgrade, PL is Pylint. To see what any rule means and why it exists, ask Ruff directly:
ruff rule F401
Ruff vs Pylint, Flake8 and Black
Ruff replaces Flake8, Black and isort outright, and covers the common Pylint checks, but it is not a type checker. This is the decision table I use:
| Tool | Keep it next to Ruff? | Why |
|---|---|---|
| Flake8 + plugins | No | Ruff reimplements Flake8 and the popular plugins (E, F, B, C4, SIM and more) |
| Black | No | ruff format is a drop-in replacement with near-identical output |
| isort | No | Enable Ruff’s I rules |
| pyupgrade, autoflake | No | Enable UP; F401 and F841 with --fix remove dead code |
| Pylint | Usually no | Ruff’s PL rules cover the common checks; Pylint’s cross-module inference finds a few more, at a much higher runtime cost |
| mypy, Pyright or ty | Yes | Ruff does not check types. Run a type checker alongside it |
If your team relies on a specific Pylint check, run ruff rule --all or check the Ruff rules list for it before dropping Pylint. If it is missing, keep Pylint for that one job in CI and let Ruff handle the fast feedback.
How to configure Ruff in pyproject.toml
Put all Ruff settings in pyproject.toml, so your editor, pre-commit and CI read the same rules:
[tool.ruff]
line-length = 88
target-version = "py312"
[tool.ruff.lint]
select = ["E", "F", "B", "UP", "I"]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
Start with a narrow select list and expand it deliberately. E and F are the minimum, and B, UP and I are the next rules I add because they catch real bugs and remove whole categories of review comments. Enabling every rule family on day one produces a wall of warnings that nobody reads.
To silence one rule on one line, use a targeted comment such as # noqa: F401. Avoid project-wide ignore entries for exceptions that apply to a single file; use [tool.ruff.lint.per-file-ignores] instead.
Ruff’s configuration is hierarchical: a pyproject.toml (or ruff.toml) in a subdirectory overrides the root settings for that folder, which helps in monorepos where a legacy service cannot meet the same bar as new code yet.
How to run Ruff in your editor, pre-commit and CI
Run Ruff in three places: the editor for instant feedback, pre-commit to stop bad commits, and CI as the final gate.
Editor. Install the official Ruff extension for VS Code, or point any LSP client at ruff server. Turn on format on save and fix on save, so most issues never reach a commit.
Pre-commit. Pin the hook to the Ruff version you use (0.17.6 at the time of writing) and run the linter before the formatter, because a lint fix can change formatting:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.6
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
CI. Run both checks as separate steps, so a failure tells you whether it was a lint or a format problem:
# .github/workflows/ruff.yml
name: Ruff
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- run: pip install ruff==0.17.6
- run: ruff check .
- run: ruff format --check .
CI uses format --check, which fails on unformatted code instead of silently reformatting it. Pin the same Ruff version in pre-commit and CI; a newer Ruff can add or change rules and produce “it passed locally” failures.
How to migrate an existing codebase to Ruff
Migrate in small, reviewable steps rather than one giant cleanup commit:
- Add the
[tool.ruff]config withselect = ["E", "F"]and remove the Flake8, Black and isort configs. - Run
ruff format .once and commit it alone, so the formatting diff stays out of real changes. Add that commit’s hash to.git-blame-ignore-revssogit blameskips it. - Run
ruff check --fix ., review the diff and commit. - Fix the remaining violations one rule code at a time, one PR per rule.
- Add
I, thenUP, thenBtoselect, repeating steps 3 and 4 for each. - Replace the old hooks in pre-commit and CI with the Ruff setup above.
Fixes marked unsafe are not applied by --fix unless you add --unsafe-fixes. Leave them off for unattended runs; they can change behavior in edge cases.
Common Ruff mistakes
- Running only
ruff check. Linting passing says nothing about formatting. Enforce both commands. - Keeping Black and Ruff’s formatter together. They disagree in small ways and fight over the same lines. Pick
ruff format. - Enabling every rule at once on old code. Start with
EandF, get clean, then expand. - Unpinned versions. An unpinned Ruff in CI can start failing builds after a release adds rules.
- Only running Ruff in CI. Feedback then takes minutes instead of milliseconds. The editor should be the first line, and CI the backstop.
The takeaway
Ruff turns five Python tools into one: ruff check --fix for linting, imports and syntax upgrades, and ruff format for formatting, both configured in pyproject.toml and pinned to the same version everywhere. Keep a type checker next to it, drop Flake8, Black and isort, and migrate one rule family at a time. The same “one config, enforced everywhere” idea is what keeps a growing codebase like the one in FastAPI Project Structure That Survives Growth consistent.
Sources
Related reading
- Small, Fast, Reproducible Python Docker Images
- FastAPI Project Structure That Survives Growth
- Python Task Queues Compared



