Ruff

Ruff is a fast linter and code formatter for Python that unifies linting and formatting in one CLI.

Installation and Setup

Ruff is available on PyPI and as a standalone installer. In macOS, it can also be installed from Homebrew:

Windows PowerShell
PS> py -m pip install ruff

PS> powershell -c "irm https://astral.sh/ruff/install.ps1 | iex"
Shell
$ python -m pip install ruff

$ curl -LsSf https://astral.sh/ruff/install.sh | sh
Shell
$ brew install ruff

$ curl -LsSf https://astral.sh/ruff/install.sh | sh

$ python -m pip install ruff

Key Features

  • Lints and formats with a single tool and offers a Black compatible formatter available as ruff format.
  • Large built in ruleset that covers many flake8 plugins and common style checks.
  • Very fast execution with caching and parallel analysis.
  • Flexible configuration through pyproject.toml, ruff.toml, or .ruff.toml.
  • Smooth integration with pre commit and GitHub Actions.

Usage

Lint the current directory:

Shell
$ ruff check .

Apply automatic fixes during linting:

Shell
$ ruff check . --fix

Format code:

Shell
$ ruff format .