Ruff

Ruff is an extremely fast Python linter and formatter written in Rust — running 10-100× faster than existing tools while supporting 700+ lint rules from Flake8, pylint, isort, and more, making it the modern all-in-one solution for Python code quality.

What Is Ruff?

  • Definition: Blazingly fast Python linter and code formatter.
  • Speed: 10-100× faster than Flake8, pylint, isort combined.
  • Language: Written in Rust for maximum performance.
  • Rules: 700+ rules from popular linters in one tool.

Why Ruff Matters

  • Speed: Lint 100K lines in 0.1 seconds vs 10+ seconds with traditional tools.
  • All-in-One: Replaces Flake8, isort, pylint, pyupgrade, and more.
  • Auto-fixing: Automatically fix hundreds of issue types.
  • Drop-in Replacement: Compatible with existing configurations.
  • Active Development: Rapidly improving with frequent releases.

Performance

Speed Comparison:
- Flake8: ~10 seconds for medium projects
- pylint: ~60 seconds for medium projects
- Ruff: ~0.1 seconds (100× faster!)

Real-World Benchmarks:
- Django (300K lines): 12s → 0.15s (80× faster)
- FastAPI (50K lines): 2s → 0.03s (67× faster)
- Pandas (500K lines): 20s → 0.25s (80× faster)

Key Features

Comprehensive Rules:
- E/W: pycodestyle errors and warnings
- F: Pyflakes (undefined names, unused imports)
- I: isort (import sorting)
- N: pep8-naming (naming conventions)
- UP: pyupgrade (modern Python syntax)
- B: flake8-bugbear (common bugs)
- C4: flake8-comprehensions (better comprehensions)
- SIM: flake8-simplify (simplification suggestions)

Auto-fixing:

# Fix issues automatically
ruff check --fix .

# Show what would be fixed
ruff check --fix --diff .

Built-in Formatter:

# Format code (Black-compatible)
ruff format .

Quick Start

# Install
pip install ruff

# Lint current directory
ruff check .

# Auto-fix issues
ruff check --fix .

# Format code
ruff format .

# Watch mode
ruff check --watch .

Configuration

# pyproject.toml
[tool.ruff]
line-length = 88
target-version = "py310"

# Enable rules
select = [
    "E",   # pycodestyle errors
    "W",   # pycodestyle warnings
    "F",   # Pyflakes
    "I",   # isort
    "N",   # pep8-naming
    "UP",  # pyupgrade
    "B",   # flake8-bugbear
]

# Ignore specific rules
ignore = ["E501"]  # Line too long

# Exclude directories
exclude = [".git", "__pycache__", "venv", "migrations"]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]  # Ignore unused imports

Integration

VS Code:

{
    "ruff.enable": true,
    "ruff.organizeImports": true,
    "editor.formatOnSave": true,
    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff"
    }
}

Pre-commit:

repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.1.9
    hooks:
      - id: ruff
        args: [--fix]
      - id: ruff-format

GitHub Actions:

- name: Lint with Ruff
  run: |
    pip install ruff
    ruff check .
    ruff format --check .

Migration

From Flake8 + isort + Black:

# Old workflow (slow)
isort . && black . && flake8 .

# New workflow (fast)
ruff check --fix . && ruff format .

Comparison

vs Flake8: 100× faster, more rules, built-in auto-fix.
vs pylint: 10-100× faster, simpler config, fewer false positives.
vs Black: Ruff format is Black-compatible, comparable speed.
vs isort: Built-in import sorting, much faster.

Best Practices

  • Start Conservative: Enable core rules first (E, F), gradually add more.
  • Use Auto-fix: `ruff check --fix .` fixes most issues automatically.
  • Integrate Early: Add to pre-commit hooks and CI/CD from day one.
  • Combine with Type Checker: `ruff check . && mypy .`
  • Format Then Lint: `ruff format . && ruff check --fix .`

Adoption Strategy

Week 1: Install, run `ruff check .`, configure basic rules.
Week 2: Run `ruff check --fix .`, review changes, add to pre-commit.
Week 3: Add to CI/CD, enforce in pull requests.
Week 4: Enable more rule categories, document in CONTRIBUTING.md.

Why So Fast?

  • Rust: Compiled language vs interpreted Python.
  • Parallel Processing: Multi-threaded execution.
  • Efficient Caching: Smart cache invalidation.
  • Optimized Algorithms: Fast AST parsing.

Ruff is revolutionizing Python linting — replacing multiple slow tools with one blazingly fast solution that saves time in development and CI/CD, making code quality checks instant rather than a bottleneck.

Take ruff further

Ask the copilot about this term, or have our engineers assess it against your process.