Ruff Setup
Ruff is a Rust-based linter and formatter that replaces flake8, isort, pyupgrade, and dozens of plugins in a single fast tool. It is the default linter for Python 3.14 projects.
Search across all documentation pages
Ruff is a Rust-based linter and formatter that replaces flake8, isort, pyupgrade, and dozens of plugins in a single fast tool. It is the default linter for Python 3.14 projects.
uv add --group dev ruff[tool.ruff]
line-length = 88
target-version = "py314"
[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "SIM"]uv run ruff check .
uv run ruff format .When to reach for this:
# pyproject.toml
[tool.ruff]
line-length = 88
target-version = "py314"
src = ["src", "tests"]
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"B", # bugbear
"SIM", # simplify
]
ignore = ["E501"] # line length handled by formatter
[tool.ruff.lint.isort]
known-first-party = ["myapp"]
[tool.ruff.format]
quote-style = "double"uv run ruff check . --fix
uv run ruff format .
uv run ruff check . # verify cleanWhat this demonstrates:
select enables rule categories; ignore suppresses specific codes--fix auto-corrects safe violations (imports, pyupgrade, some bugbear)ruff format provides Black-compatible formattingB = bugbear, I = isort)| Code | Source | Catches |
|---|---|---|
| E, W | pycodestyle | Style violations |
| F | pyflakes | Undefined names, unused imports |
| I | isort | Import order |
| UP | pyupgrade | Outdated syntax |
| B | bugbear | Common bugs |
| SIM | simplify | Overly complex code |
[tool.ruff] in pyproject.toml.E501; let ruff format handle line length.target-version - pyupgrade won't suggest 3.14 syntax. Fix: set target-version = "py314".src paths - first-party import detection fails. Fix: set src = ["src"] for src-layout projects.
| Alternative | Use When | Don't Use When |
|---|---|---|
| flake8 + plugins | Legacy config investment | Starting fresh |
| pylint | Deep semantic analysis needed | Speed matters |
| Black only | Format-only, no lint | You want one tool |
ruff format is Black-compatible. Most teams use ruff for both lint and format.
# noqa: F401 on the line, or # ruff: noqa for all rules on that line.
Many rules support --fix. Some (logic errors) require manual fixes.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-formatruff check lints. ruff format formats. Run both in CI.
ruff linter lists rule codes. ruff rule E501 explains a specific rule.
Yes. Use src and per-directory pyproject.toml or extend config.
Yes. Ruff catches style and obvious bugs; mypy catches type errors. Run both.
Typically 10-100x faster on medium-to-large codebases.
ruff>=0.9 per the project stack. Pin exact version in pre-commit rev.
Stack versions: This page was written for Python 3.14.0, FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 19, 2026