Astral · ultra-fast Python linter + formatter · one tool for flake8/black/isort/pyupgrade · verified against Ruff 0.16 (2026)

Ruff cheat sheet

Ruff (Rust, by Astral) is a Python linter and formatter that runs 10–100× faster than the tools it replaces — Flake8 (+dozens of plugins), Black, isort, pyupgrade, pydocstyle, bandit and more — behind two commands: ruff check (lint) and ruff format (format). Config lives in pyproject.toml. This sheet targets Ruff 0.16, which enables far more rules by default and adds # ruff: ignore line suppressions.

the two commands rules & categories config (pyproject) formatter suppress & integrate gotcha most common

Verified 2026-08-24 against the official docs at docs.astral.sh/ruff and the astral-sh/ruff repo (Ruff 0.16). Single static binary; the formatter is intentionally Black-compatible.

Outline

Two commands do everything: ruff check and ruff format. The rest is choosing rules and suppressing the odd false positive.

Run

  1. 1 · Install & the two commands
  2. 2 · Autofix & watch

Rules

  1. 3 · Rule codes & categories
  2. 4 · Discover rules

Configure

  1. 5 · pyproject.toml basics
  2. 6 · select / ignore / per-file

Format

  1. 7 · The formatter

Everyday

  1. 8 · Suppressing warnings
  2. 9 · pre-commit & editors
  3. 10 · Gotchas
  4. Worth memorizing

Run It

Two subcommands: lint and format.

1Install & the two commands0.16
2Autofix & watchfix automatically

Rules

Each rule has a code; codes group into categories by the tool they came from.

3Rule codes & categoriesthe prefixes
4Discover rulesexplore

Configure

One [tool.ruff] block controls both linter and formatter.

5pyproject.toml basicsproject config
6select / ignore / per-filechoose rules

Formatter

The Black-compatible half.

7The formatterruff format

Everyday

Silence false positives and wire into your workflow.

8Suppressing warningsnoqa
9pre-commit & editorsautomate
!Common gotchasread before shipping

Worth memorizing

two commandsruff check (lint) + ruff format; replaces flake8/black/isort/pyupgrade/bandit
--fix does the boring workunused imports, sorting, rewrites; --unsafe-fixes for the rest (review)
rule prefixesE/W style, F bugs, I imports, B bugbear, UP upgrade, SIM simplify
config under [tool.ruff.lint]select/ignore moved there in 0.2
select replaces, extend-select addsknow which you want
per-file-ignoresF401 in __init__, S101 in tests
format = Black-compatiblebyte-for-byte for most code; import sort is lint rule I
# noqa: CODE, not bare# ruff: noqa at file top for whole-file
not a type checkerpair with mypy; ruff-pre-commit for automation