Ruff: The Extremely Fast Python Linter and Formatter — The Complete Guide in 9 Chapters

Ruff is the tool that changed how Python developers think about code quality. For years, keeping a Python codebase clean meant assembling a chain of separate utilities: one to catch style errors, another to sort imports, a third to reformat code, and a fourth to remove what was no longer used. Each tool had its own configuration, its own quirks, and its own share of waiting time. Ruff replaces that chain with a single, extremely fast program that lints and formats Python code, and it does so quickly enough that checking an entire project feels instant.

This guide explains Ruff from the ground up. It covers what the tool is and why its speed matters, how to install it, how to run your first check, how to configure it for a real project, how its rule system works, how automatic fixes behave, and how teams use it in large repositories and continuous integration. It also compares Ruff with the tools it replaces, so you can decide whether — and how — to adopt it. The version discussed here is Ruff 0.17.6, the latest stable release at the time of writing, published on 19 November 2026.

1. What Is Ruff?

Ruff is an extremely fast Python linter and code formatter written in Rust. It is developed by Astral, the company also behind the Python package manager uv and the Python type checker ty. Because Ruff is written in Rust rather than Python, it can scan thousands of files in a fraction of the time a Python-based linter needs, and its authors report that it runs 10 to 100 times faster than comparable tools such as Flake8 and Black.

The Ruff logo
The Ruff logo (Simple Icons, CC0 1.0)

Ruff combines two jobs that used to require two tools. As a linter, it analyses source code without running it and reports problems: unused imports, undefined names, style violations, questionable constructs, and much more. As a formatter, it rewrites code into a consistent layout, the way Black does. The two functions share one binary, one configuration file, and one set of conventions, which removes a whole class of disagreements between tools.

The project ships with more than 900 built-in rules, covering the checks of many older tools at once. It is designed as a drop-in replacement for Flake8, isort, and Black, and it can also take over the work of pydocstyle, pyupgrade, and autoflake. Its configuration lives in pyproject.toml, the standard Python project file, and it supports Python 3.15, the newest Python release line. Ruff is released under the MIT licence, and its source code is open for anyone to read, use, and contribute to.

2. Why Ruff’s Speed Matters

Speed is not a vanity metric for a linter. A slow check is a check that developers skip, postpone, or run only in continuous integration, long after the code was written. When a full-project lint takes minutes, feedback arrives too late to be useful: the author has moved on, the context is gone, and fixing the report becomes a chore. When the same check takes well under a second, it can run on every save, on every commit, and in every pull request without anyone noticing the wait.

Ruff achieves its speed in two ways. First, it is a compiled Rust binary, so it does not pay the start-up and interpretation costs of a Python program. Second, it caches its results: files that have not changed are not re-analysed, so repeated runs on a large codebase touch only what is new. The practical result is that a developer can lint a project of tens of thousands of lines before the editor has finished refreshing.

That speed changes team behaviour. Pre-commit hooks stop being a source of friction. Continuous integration pipelines spend less time on style checks and more on tests. Reviewers see cleaner pull requests because the mechanical issues were already fixed locally. In large open-source projects — Ruff is used by Apache Airflow, FastAPI, Hugging Face, Pandas, and SciPy — the savings compound across hundreds of contributors and thousands of daily runs.

3. Installing Ruff

Installing Ruff takes a minute, and there are several routes to the same binary. The most familiar route for Python developers is pip:

pip install ruff

If you already manage your Python environment with uv, Astral’s fast package manager, you can install Ruff the same way you install any other tool:

uv pip install ruff

Standalone installers are available for macOS, Linux, and Windows, and Ruff is also distributed through common package managers such as Homebrew. Editor support is built in rather than bolted on: the official Ruff extension for Visual Studio Code runs the linter and formatter inside the editor, underlining problems as you type and formatting on save. Similar integrations exist for other editors through the language server protocol.

Once installed, confirm the version you have:

ruff --version

You should see a version number such as ruff 0.17.6. If the number is older, upgrade before following the rest of this guide, because rule names and defaults do occasionally change between releases.

4. Your First Lint and Format with Ruff

The fastest way to understand Ruff is to run it on a small, imperfect file. Create a file called example.py with a deliberately messy example:

import os
import sys


def greet(name):
    print( "Hello, " + name )
    return
Source code on a screen
Source code on a screen (Sai Kiran Anagani, CC0, via Unsplash/Wikimedia Commons)

Now run the linter:

ruff check example.py

Ruff reports the unused imports — os and sys are imported but never used — and any other problems it finds, each with a rule code, a short description, and the exact line and column. Run the formatter next:

ruff format example.py

The formatter rewrites the spacing and layout into a consistent style, for example normalising the spaces around the string concatenation. The two commands are deliberately separate: checking finds problems, formatting fixes layout. To let Ruff repair the safe problems it found, add the fix flag:

ruff check --fix example.py

With that flag, Ruff removes the unused imports itself. The workflow — check, review, fix, format — becomes a habit that takes seconds, and it is the same workflow whether the project has one file or ten thousand.

5. Configuring Ruff in pyproject.toml

Ruff works well with no configuration at all, but a real project needs its rules written down so that every developer and every machine agrees. Configuration lives in pyproject.toml, under a [tool.ruff] section. A sensible starting point looks like this:

[tool.ruff]
line-length = 88
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "I", "W"]
ignore = ["E501"]

Each setting has a clear purpose. The line-length setting controls the maximum line length that the formatter and the style rules assume; 88 characters is the value Black popularised, and it remains a good default. The target-version setting tells Ruff which Python version the code must run on, so it does not suggest syntax that older interpreters cannot understand. The select list chooses which rule groups are active, and ignore switches off individual rules that do not fit the project — here, the line-length rule itself, for teams that prefer the formatter to handle long lines.

Two further settings are worth knowing early. The preview flag enables rules and behaviours that are still being tested, which is useful for teams that want to try new checks before they become defaults. And fixable and unfixable lists control which rules Ruff is allowed to repair automatically, so a team can enable a rule for reporting while keeping its fixes manual.

6. The Ruff Rule System: More Than 900 Rules Explained

Ruff’s rules are organised by prefix, and each prefix corresponds to a family of checks, often inherited from an earlier tool. The most common prefixes are worth memorising: E and W cover style errors and warnings in the tradition of pycodestyle; F covers the pyflakes checks for unused imports, undefined names, and similar defects; I covers import sorting in the style of isort; UP suggests modern Python syntax in the spirit of pyupgrade; D covers docstring conventions from pydocstyle; and B covers bug-prone patterns identified by flake8-bugbear.

With more than 900 rules available, no team enables all of them at once. The usual approach is to start with a small, strict core — the E, F, and I groups — and add groups gradually, fixing the new findings in small batches. Ruff also supports the ALL selector, which turns on every rule, but that is best treated as an experiment: run it once, read the report, and choose the groups that genuinely help your codebase.

Rules can be tuned per file. A test directory, for example, often needs looser rules than production code, and generated files should usually be skipped entirely. Ruff expresses that with per-file-ignores, a setting that maps file patterns to the rules that do not apply to them. Keeping these exceptions in the configuration file, rather than in scattered comments, means the whole team can see and review them.

7. Fixing Code Automatically — and Safely

Automatic fixing is Ruff’s most productive feature and the one that needs the most care. The basic form is simple:

ruff check --fix .

Run from the project root, this scans the whole project and repairs every problem that Ruff considers safe to fix: unused imports are removed, import order is corrected, and simple style violations are rewritten. A second, stronger form exists for fixes that change behaviour in edge cases:

ruff check --fix --unsafe-fixes .

The distinction matters. A safe fix is one that cannot change what the program does. An unsafe fix might, for example, remove a variable that looks unused but is read through some indirect mechanism. Ruff marks those fixes as unsafe and leaves them out by default, so a team can choose its own level of risk.

The safe habit is to run automatic fixes on a clean working tree, then review the resulting diff before committing, exactly as you would review a colleague’s change. In continuous integration, the check should run without the fix flag, so that a failing build means a human needs to look, not that a machine silently rewrote the code. Used that way, automatic fixing removes the repetitive part of code review and leaves the judgement to people.

8. Ruff in Real Projects, Monorepos, and Teams

Small projects and large ones use Ruff differently. In a single-package project, one configuration file at the root is enough. In a monorepo, Ruff’s hierarchical configuration becomes valuable: settings cascade from parent directories to child directories, so a shared root configuration can define the common rules while each package overrides what it needs. A data-processing package and a web service in the same repository can share a line length and a rule set, yet differ in the rules that apply to their tests.

Editor integration is what makes the configuration stick. With the Ruff extension installed, problems appear as you type, fixes are one keystroke away, and formatting happens on save. The experience is close to having a reviewer sitting beside you, and it is the same in a small script and in a large Python codebase such as a multi-agent system built with CrewAI, where consistent style across many cooperating modules is what keeps the project readable. The same discipline pays off in machine-learning projects, including code that works with the Transformers library, where long files and many contributors make style drift almost inevitable without an automated check.

For teams, the standard setup is a pre-commit hook that runs Ruff on changed files, plus a continuous-integration job that runs ruff check and ruff format --check on the whole repository. The format check fails the build if any file is not formatted, which ends arguments about style in code review: the formatter is the authority, and its output is not a matter of taste. Combined with uv for environment management, the whole Python toolchain — installing packages, managing versions, linting, and formatting — comes from one vendor and one set of conventions, which reduces the number of tools a new contributor must learn.

9. Ruff Versus Flake8, Black, and isort

Ruff’s claim to replace Flake8, Black, and isort is best judged tool by tool. Against Flake8, Ruff offers the same style and defect checks, plus hundreds more rules, at a speed Flake8 cannot match, and without the plugin management that Flake8 setups often require. Against Black, Ruff’s formatter produces output that is compatible with Black’s style in the great majority of cases, so a project formatted with Black can usually switch without reformatting its entire history. Against isort, Ruff’s import sorting follows the same conventions and runs as part of the same check.

Migration is usually straightforward. A project that already uses Flake8 and Black can adopt Ruff incrementally: first run Ruff’s formatter and confirm the diff is small, then enable the lint rules group by group, fixing or suppressing findings as they appear. Ruff’s documentation includes a guide for migrating from each of these tools, including the configuration equivalents for the most common settings.

There are still reasons to keep an older tool. A project with a heavily customised Flake8 plugin, or a formatter configuration that depends on a Black behaviour Ruff does not reproduce, should migrate carefully and test the result. For most new projects, however, the calculation is simple: one tool, one configuration, and a check that finishes before you notice it. That is why Ruff has become the default choice for new Python projects, and why established projects such as Apache Airflow, FastAPI, Hugging Face, Pandas, and SciPy have adopted it.

Conclusion: Should You Adopt Ruff?

Ruff earns its reputation. It is a single, extremely fast Python linter and formatter, written in Rust by Astral, that replaces Flake8, Black, isort, pydocstyle, pyupgrade, and autoflake with one binary and one configuration file. It ships with more than 900 rules, supports Python 3.15, caches its work, fixes safe problems automatically, and integrates natively with editors such as Visual Studio Code. Version 0.17.6, released on 19 November 2026, is the current stable release, and the project is distributed under the permissive MIT licence.

The adoption path is low risk: install it, run it on a copy of your code, enable the rules gradually, and let the formatter settle questions of style. The payoff is a codebase that stays clean without slowing anyone down — and a review process that spends its time on design and logic, which is where human attention belongs.

Sources

  • Ruff Documentation — the official Ruff documentation from Astral, including installation, configuration, and the full rule reference.
  • Ruff Releases on GitHub — the release history of the Ruff project, including version 0.17.6, released on 19 November 2026.
  • Ruff on PyPI — the Ruff package page, listing the MIT licence and the current release.
  • The Ruff Repository on GitHub — the open-source Ruff repository, maintained by Astral.

Leave a Comment