Ruff is a Python linter and formatter written in Rust. It's 10-100x faster than existing tools and can replace Flake8, isort, pyupgrade, and Black — all in one binary.
What Makes Ruff Special?
- 100x faster — lints entire projects in milliseconds
- All-in-one — replaces Flake8 + isort + pyupgrade + Black
- 800+ rules — from Flake8, pycodestyle, pyflakes, and more
- Auto-fix — fixes most issues automatically
- Drop-in — same rules you already know
The Hidden API: Programmatic Usage
import subprocess
import json
# Get lint results as JSON
result = subprocess.run(
['ruff', 'check', '--output-format', 'json', 'src/'],
capture_output=True, text=True
)
diagnostics = json.loads(result.stdout)
for d in diagnostics:
print(f"{d['filename']}:{d['location']['row']} - {d['code']}: {d['message']}")
Configuration API
# pyproject.toml
[tool.ruff]
line-length = 100
target-version = "py312"
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"RUF", # ruff-specific rules
]
ignore = ["E501"]
fixable = ["ALL"]
[tool.ruff.lint.isort]
known-first-party = ["myproject"]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
CLI API
# Lint
ruff check src/
# Lint with auto-fix
ruff check --fix src/
# Format (replaces Black)
ruff format src/
# Check + format in one command
ruff check --fix src/ && ruff format src/
# Show what would change
ruff format --diff src/
# Pre-commit integration
ruff check --fix --exit-non-zero-on-fix src/
Quick Start
pip install ruff
ruff check . # Lint
ruff format . # Format
ruff check --fix . # Auto-fix
Why Python Teams Switch to Ruff
A developer shared: "Our CI linting step took 3 minutes with Flake8 + isort + Black. Ruff does the same in 0.3 seconds. We also deleted 5 config files and replaced them with 15 lines in pyproject.toml. The migration took 10 minutes."
Optimizing Python workflows? Email spinov001@gmail.com or check my tools.
Still using Flake8 + Black? Give Ruff a try!
Top comments (0)