Blogs

Ruff Python Linter and Formatter: Setup Guide for 2026

  • Python
  • Tooling
  • Backend Development
  • Ruff
Terminal output showing a fast code linting and formatting pass
Photo by Emile Perron on Unsplash

In short: Ruff is a Rust-based Python linter and formatter that replaces Flake8 and its plugins, Black, isort, pyupgrade and autoflake with one tool configured in pyproject.toml. Run ruff check –fix for linting and ruff format for formatting as two separate steps, and enforce both in your editor, pre-commit and CI. It does not replace a type checker.

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 check and ruff 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:

JobTool it replacesRuff command or rule prefix
Lint errors and styleFlake8, pycodestyle, Pyflakesruff check (E, W, F)
Bug-prone patternsflake8-bugbear and other pluginsruff check (B, C4, SIM, …)
Import sortingisortruff check (I)
Modern syntax upgradespyupgraderuff check (UP)
Removing unused codeautoflakeruff check --fix (F401, F841)
FormattingBlackruff 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:

ToolKeep it next to Ruff?Why
Flake8 + pluginsNoRuff reimplements Flake8 and the popular plugins (E, F, B, C4, SIM and more)
BlackNoruff format is a drop-in replacement with near-identical output
isortNoEnable Ruff’s I rules
pyupgrade, autoflakeNoEnable UP; F401 and F841 with --fix remove dead code
PylintUsually noRuff’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 tyYesRuff 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:

  1. Add the [tool.ruff] config with select = ["E", "F"] and remove the Flake8, Black and isort configs.
  2. 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-revs so git blame skips it.
  3. Run ruff check --fix ., review the diff and commit.
  4. Fix the remaining violations one rule code at a time, one PR per rule.
  5. Add I, then UP, then B to select, repeating steps 3 and 4 for each.
  6. 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 E and F, 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

Frequently asked questions

What is Ruff in Python?
Ruff is an open source linter and code formatter for Python, written in Rust by Astral. One binary covers the jobs of Flake8 and its plugins, Black, isort, pyupgrade and autoflake, and it is usually 10 to 100 times faster than running those tools separately.
What does ruff check do?
ruff check lints your code: it reports problems such as unused imports, undefined names and outdated syntax, each with a rule code like F401. With –fix it also rewrites the problems it can fix safely. It does not change formatting; that is ruff format.
Is Ruff better than Pylint?
For most projects Ruff is the better default: it is far faster and covers the common Pylint checks through its PL rules. Pylint still finds some issues Ruff does not, because it infers types across modules. Teams that need those checks usually pair Ruff with a type checker such as mypy, Pyright or ty.
Can Ruff replace Black?
Yes. ruff format is designed as a drop-in replacement for Black, and on most codebases it produces almost the same output. Remove Black from pre-commit and CI once ruff format is enforced, so the two formatters never fight.

Tell me about your next project

Have an AI agent, a backend or a full product in mind? Send a short note and we can talk it through.