ruff

ruff is an extremely fast Python linter and code formatter written in Rust that consolidates the functionality of Black, Flake8, pylint, isort, pyupgrade, and dozens of plugins into a single unified tool.

Speed and Performance

  • 10-100x faster than traditional tools like Flake8 and Black
  • On a 250,000 line codebase (Dagster), completes linting in 0.4 seconds vs Pylint’s 2.5 minutes
  • Fast enough to run on-save without noticeable delay
  • Drop-in parity with existing tools (output closely matches Black/Flake8)

What It Replaces

ruff consolidates functionality from:

  • Flake8 (plus dozens of plugins like flake8-bugbear)
  • Black (code formatter)
  • isort (import sorting)
  • pydocstyle (docstring validation)
  • pyupgrade (syntax modernization)
  • autoflake (unused import removal)

Single configuration file via pyproject.toml eliminates multi-file setup burden.

Core Commands

ruff check                    # Lint current directory  
ruff check path/to/code/      # Lint specific directory  
ruff format                   # Format code  
ruff check --fix              # Auto-fix issues  

Rule System

  • 800+ built-in lint rules
  • Default enables Flake8’s F rules (error codes) and subset of E rules
  • Per-file rule configuration for fine-grained control
  • Automatic fixing for many rules (removable unused imports, syntax rewrites, etc.)

Configuration Example

[tool.ruff]  
line-length = 100  
  
[tool.ruff.lint]  
select = ["E4", "E7", "E9", "F"]  
ignore = ["E501"]  
  
[tool.ruff.lint.per-file-ignores]  
"some_file.py" = ["F841"]  
  
[tool.ruff.format]  
quote-style = "double"  

Integration

  • Editor support: First-party VS Code integration and other IDE plugins
  • Pre-commit hooks: Ready-to-use pre-commit configuration
  • CI/CD pipelines: Clean output format suitable for automation
  • Monorepo-friendly: Hierarchical configuration support

Design Influences

  • Formatter based on Rome’s formatter, Prettier, and Black
  • Import resolver inspired by Pyright’s algorithm
  • Rule implementation draws from tools like ESLint and Clippy

Key Strengths

  • Exceptional speed makes it practical for real-time feedback
  • Single tool eliminates tool fragmentation and configuration complexity
  • 800+ rules catch common errors without manual setup
  • Powerful auto-fix capabilities reduce manual remediation
  • Growing adoption across Python ecosystem

When to Use

ruff is ideal for:

  • Projects wanting unified linting and formatting
  • Teams prioritizing build speed
  • Migrations from Black/Flake8 (straightforward drop-in)
  • Codebases needing multiple rule sets without tool sprawl

See Also