Skip to main content

An extremely fast Python linter and code formatter, written in Rust.

Project description

Ruff

Ruff image image image Actions status Discord

Docs | Playground

An extremely fast Python linter and code formatter, written in Rust.

Shows a bar chart with benchmark results.

Linting the CPython codebase from scratch.

  • ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)
  • 🐍 Installable via pip
  • 🛠️ pyproject.toml support
  • 🤝 Python 3.13 compatibility
  • ⚖️ Drop-in parity with Flake8, isort, and Black
  • 📦 Built-in caching, to avoid re-analyzing unchanged files
  • 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports)
  • 📏 Over 800 built-in rules, with native re-implementations of popular Flake8 plugins, like flake8-bugbear
  • ⌨️ First-party editor integrations for VS Code and more
  • 🌎 Monorepo-friendly, with hierarchical and cascading configuration

Ruff aims to be orders of magnitude faster than alternative tools while integrating more functionality behind a single, common interface.

Ruff can be used to replace Flake8 (plus dozens of plugins), Black, isort, pydocstyle, pyupgrade, autoflake, and more, all while executing tens or hundreds of times faster than any individual tool.

Ruff is extremely actively developed and used in major open-source projects like:

...and many more.

Ruff is backed by Astral. Read the launch post, or the original project announcement.

Testimonials

Sebastián Ramírez, creator of FastAPI:

Ruff is so fast that sometimes I add an intentional bug in the code just to confirm it's actually running and checking the code.

Nick Schrock, founder of Elementl, co-creator of GraphQL:

Why is Ruff a gamechanger? Primarily because it is nearly 1000x faster. Literally. Not a typo. On our largest module (dagster itself, 250k LOC) pylint takes about 2.5 minutes, parallelized across 4 cores on my M1. Running ruff against our entire codebase takes .4 seconds.

Bryan Van de Ven, co-creator of Bokeh, original author of Conda:

Ruff is ~150-200x faster than flake8 on my machine, scanning the whole repo takes ~0.2s instead of ~20s. This is an enormous quality of life improvement for local dev. It's fast enough that I added it as an actual commit hook, which is terrific.

Timothy Crosley, creator of isort:

Just switched my first project to Ruff. Only one downside so far: it's so fast I couldn't believe it was working till I intentionally introduced some errors.

Tim Abbott, lead developer of Zulip:

This is just ridiculously fast... ruff is amazing.

Table of Contents

For more, see the documentation.

  1. Getting Started
  2. Configuration
  3. Rules
  4. Contributing
  5. Support
  6. Acknowledgements
  7. Who's Using Ruff?
  8. License

Getting Started

For more, see the documentation.

Installation

Ruff is available as ruff on PyPI.

Invoke Ruff directly with uvx:

uvx ruff check   # Lint all files in the current directory.
uvx ruff format  # Format all files in the current directory.

Or install Ruff with uv (recommended), pip, or pipx:

# With uv.
uv tool install ruff@latest  # Install Ruff globally.
uv add --dev ruff            # Or add Ruff to your project.

# With pip.
pip install ruff

# With pipx.
pipx install ruff

Starting with version 0.5.0, Ruff can be installed with our standalone installers:

# On macOS and Linux.
curl -LsSf https://astral.sh/ruff/install.sh | sh

# On Windows.
powershell -c "irm https://astral.sh/ruff/install.ps1 | iex"

# For a specific version.
curl -LsSf https://astral.sh/ruff/0.12.2/install.sh | sh
powershell -c "irm https://astral.sh/ruff/0.12.2/install.ps1 | iex"

You can also install Ruff via Homebrew, Conda, and with a variety of other package managers.

Usage

To run Ruff as a linter, try any of the following:

ruff check                          # Lint all files in the current directory (and any subdirectories).
ruff check path/to/code/            # Lint all files in `/path/to/code` (and any subdirectories).
ruff check path/to/code/*.py        # Lint all `.py` files in `/path/to/code`.
ruff check path/to/code/to/file.py  # Lint `file.py`.
ruff check @arguments.txt           # Lint using an input file, treating its contents as newline-delimited command-line arguments.

Or, to run Ruff as a formatter:

ruff format                          # Format all files in the current directory (and any subdirectories).
ruff format path/to/code/            # Format all files in `/path/to/code` (and any subdirectories).
ruff format path/to/code/*.py        # Format all `.py` files in `/path/to/code`.
ruff format path/to/code/to/file.py  # Format `file.py`.
ruff format @arguments.txt           # Format using an input file, treating its contents as newline-delimited command-line arguments.

Ruff can also be used as a pre-commit hook via ruff-pre-commit:

- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.12.2
  hooks:
    # Run the linter.
    - id: ruff-check
      args: [ --fix ]
    # Run the formatter.
    - id: ruff-format

Ruff can also be used as a VS Code extension or with various other editors.

Ruff can also be used as a GitHub Action via ruff-action:

name: Ruff
on: [ push, pull_request ]
jobs:
  ruff:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/ruff-action@v3

Configuration

Ruff can be configured through a pyproject.toml, ruff.toml, or .ruff.toml file (see: Configuration, or Settings for a complete list of all configuration options).

If left unspecified, Ruff's default configuration is equivalent to the following ruff.toml file:

# Exclude a variety of commonly ignored directories.
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".ipynb_checkpoints",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pyenv",
    ".pytest_cache",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    ".vscode",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "venv",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.9
target-version = "py39"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

Note that, in a pyproject.toml, each section header should be prefixed with tool.ruff. For example, [lint] should be replaced with [tool.ruff.lint].

Some configuration options can be provided via dedicated command-line arguments, such as those related to rule enablement and disablement, file discovery, and logging level:

ruff check --select F401 --select F403 --quiet

The remaining configuration options can be provided through a catch-all --config argument:

ruff check --config "lint.per-file-ignores = {'some_file.py' = ['F841']}"

To opt in to the latest lint rules, formatter style changes, interface updates, and more, enable preview mode by setting preview = true in your configuration file or passing --preview on the command line. Preview mode enables a collection of unstable features that may change prior to stabilization.

See ruff help for more on Ruff's top-level commands, or ruff help check and ruff help format for more on the linting and formatting commands, respectively.

Rules

Ruff supports over 800 lint rules, many of which are inspired by popular tools like Flake8, isort, pyupgrade, and others. Regardless of the rule's origin, Ruff re-implements every rule in Rust as a first-party feature.

By default, Ruff enables Flake8's F rules, along with a subset of the E rules, omitting any stylistic rules that overlap with the use of a formatter, like ruff format or Black.

If you're just getting started with Ruff, the default rule set is a great place to start: it catches a wide variety of common errors (like unused imports) with zero configuration.

Beyond the defaults, Ruff re-implements some of the most popular Flake8 plugins and related code quality tools, including:

For a complete enumeration of the supported rules, see Rules.

Contributing

Contributions are welcome and highly appreciated. To get started, check out the contributing guidelines.

You can also join us on Discord.

Support

Having trouble? Check out the existing issues on GitHub, or feel free to open a new one.

You can also ask for help on Discord.

Acknowledgements

Ruff's linter draws on both the APIs and implementation details of many other tools in the Python ecosystem, especially Flake8, Pyflakes, pycodestyle, pydocstyle, pyupgrade, and isort.

In some cases, Ruff includes a "direct" Rust port of the corresponding tool. We're grateful to the maintainers of these tools for their work, and for all the value they've provided to the Python community.

Ruff's formatter is built on a fork of Rome's rome_formatter, and again draws on both API and implementation details from Rome, Prettier, and Black.

Ruff's import resolver is based on the import resolution algorithm from Pyright.

Ruff is also influenced by a number of tools outside the Python ecosystem, like Clippy and ESLint.

Ruff is the beneficiary of a large number of contributors.

Ruff is released under the MIT license.

Who's Using Ruff?

Ruff is used by a number of major open-source projects and companies, including:

Show Your Support

If you're using Ruff, consider adding the Ruff badge to your project's README.md:

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

...or README.rst:

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
    :target: https://github.com/astral-sh/ruff
    :alt: Ruff

...or, as HTML:

<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff" style="max-width:100%;"></a>

License

This repository is licensed under the MIT License

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ruff-0.12.2.tar.gz (4.4 MB view details)

Uploaded Source

Built Distributions

ruff-0.12.2-py3-none-win_arm64.whl (10.7 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.12.2-py3-none-win_amd64.whl (11.6 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.12.2-py3-none-win32.whl (10.5 MB view details)

Uploaded Python 3Windows x86

ruff-0.12.2-py3-none-musllinux_1_2_x86_64.whl (11.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.12.2-py3-none-musllinux_1_2_i686.whl (11.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.12.2-py3-none-musllinux_1_2_armv7l.whl (10.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.12.2-py3-none-musllinux_1_2_aarch64.whl (10.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.12.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.12.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (11.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.12.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (12.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.12.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (12.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.12.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (11.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.12.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (10.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.12.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.12.2-py3-none-macosx_11_0_arm64.whl (10.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

ruff-0.12.2-py3-none-macosx_10_12_x86_64.whl (11.2 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

ruff-0.12.2-py3-none-linux_armv6l.whl (10.4 MB view details)

Uploaded Python 3

File details

Details for the file ruff-0.12.2.tar.gz.

File metadata

  • Download URL: ruff-0.12.2.tar.gz
  • Upload date:
  • Size: 4.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for ruff-0.12.2.tar.gz
Algorithm Hash digest
SHA256 d7b4f55cd6f325cb7621244f19c873c565a08aff5a4ba9c69aa7355f3f7afd3e
MD5 7d40d5df2d6a471668c444c36d994587
BLAKE2b-256 6c3dd9a195676f25d00dbfcf3cf95fdd4c685c497fcfa7e862a44ac5e4e96480

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-win_arm64.whl.

File metadata

  • Download URL: ruff-0.12.2-py3-none-win_arm64.whl
  • Upload date:
  • Size: 10.7 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for ruff-0.12.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 48d6c6bfb4761df68bc05ae630e24f506755e702d4fb08f08460be778c7ccb12
MD5 a722bbba33ea5651adfd5a6d74121ccc
BLAKE2b-256 e21f72d2946e3cc7456bb837e88000eb3437e55f80db339c840c04015a11115d

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-win_amd64.whl.

File metadata

  • Download URL: ruff-0.12.2-py3-none-win_amd64.whl
  • Upload date:
  • Size: 11.6 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for ruff-0.12.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 dca8a3b6d6dc9810ed8f328d406516bf4d660c00caeaef36eb831cf4871b0639
MD5 f8db8e0a116114b278c31ea114a9b711
BLAKE2b-256 94478abf129102ae4c90cba0c2199a1a9b0fa896f6f806238d6f8c14448cc748

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-win32.whl.

File metadata

  • Download URL: ruff-0.12.2-py3-none-win32.whl
  • Upload date:
  • Size: 10.5 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for ruff-0.12.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 369ffb69b70cd55b6c3fc453b9492d98aed98062db9fec828cdfd069555f5f1a
MD5 43c3efeae0387b0e6b222d8edf361c40
BLAKE2b-256 51de8589fa724590faa057e5a6d171e7f2f6cffe3287406ef40e49c682c07d89

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4987b8f4ceadf597c927beee65a5eaf994c6e2b631df963f86d8ad1bdea99342
MD5 33fc3a71b68a348ac8fe43e3dfddbf14
BLAKE2b-256 1cb799c34ded8fb5f86c0280278fa89a0066c3760edc326e935ce0b1550d315d

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 71a4c550195612f486c9d1f2b045a600aeba851b298c667807ae933478fcef04
MD5 20c13a900f228342509cd2bd68a6748f
BLAKE2b-256 f50c9f344583465a61c8918a7cda604226e77b2c548daf8ef7c2bfccf2b37200

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 2a4a20aeed74671b2def096bdf2eac610c7d8ffcbf4fb0e627c06947a1d7078d
MD5 95415984ba22119d2bafa3994f7338eb
BLAKE2b-256 869126a6e6a424eb147cc7627eebae095cfa0b4b337a7c1c413c447c9ebb72fd

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6aa7e623a3a11538108f61e859ebf016c4f14a7e6e4eba1980190cacb57714ce
MD5 5ff57fab7b0c7ff38e353c69f59b7783
BLAKE2b-256 b7b645ab96070c9752af37f0be364d849ed70e9ccede07675b0ec4e3ef76b63b

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6932323db80484dda89153da3d8e58164d01d6da86857c79f1961934354992da
MD5 66399f3f059d2e2c07c41ff7947bc6f5
BLAKE2b-256 87e50c270e458fc73c46c0d0f7cf970bb14786e5fdb88c87b5e423a4bd65232b

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 793d8859445ea47591272021a81391350205a4af65a9392401f418a95dfb75c9
MD5 d870f4ff0f65fa8b1adc6b4bd4a1068b
BLAKE2b-256 88a95a55266fec474acfd0a1c73285f19dd22461d95a538f29bba02edd07a5d9

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 ce48f675c394c37e958bf229fb5c1e843e20945a6d962cf3ea20b7a107dcd9f4
MD5 f45ceae638a0bad45196e915a9269312
BLAKE2b-256 d87008991ac46e38ddd231c8f4fd05ef189b1b94be8883e8c0c146a025c20a19

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 45fc42c3bf1d30d2008023a0a9a0cfb06bf9835b147f11fe0679f21ae86d34b1
MD5 94f7177381f99dfd730433661b0d3386
BLAKE2b-256 439f1f6f98f39f2b9302acc161a4a2187b1e3a97634fe918a8e731e591841cf4

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3b8b94317cbc2ae4a2771af641739f933934b03555e51515e6e021c64441532d
MD5 4862182181aa53e2ef58b85cebec10f1
BLAKE2b-256 50faf15089bc20c40f4f72334f9145dde55ab2b680e51afb3b55422effbf2fb6

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 73448de992d05517170fc37169cbca857dfeaeaa8c2b9be494d7bcb0d36c8f4b
MD5 0abb906a6bfc243708a1e1999ec374e6
BLAKE2b-256 9beb928814daec4e1ba9115858adcda44a637fb9010618721937491e4e2283b8

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3eb3a6b2db4d6e2c77e682f0b988d4d61aff06860158fdb413118ca133d57922
MD5 b208c04e024e5bbeda0ce774034c8395
BLAKE2b-256 339100cff7102e2ec71a4890fb7ba1803f2cdb122d82787c7d7cf8041fe8cbc1

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8ae64755b22f4ff85e9c52d1f82644abd0b6b6b6deedceb74bd71f35c24044cc
MD5 a030866dac96046456ee451e4c566eb6
BLAKE2b-256 3e21967b82550a503d7c5c5c127d11c935344b35e8c521f52915fc858fb3e473

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 09e4cf27cc10f96b1708100fa851e0daf21767e9709e1649175355280e0d950e
MD5 4f6d1638a78ec96195d04c9e247e1afa
BLAKE2b-256 b14b5da0142033dbe155dc598cfb99262d8ee2449d76920ea92c4eeb9547c208

See more details on using hashes here.

File details

Details for the file ruff-0.12.2-py3-none-linux_armv6l.whl.

File metadata

File hashes

Hashes for ruff-0.12.2-py3-none-linux_armv6l.whl
Algorithm Hash digest
SHA256 093ea2b221df1d2b8e7ad92fc6ffdca40a2cb10d8564477a987b44fd4008a7be
MD5 1f66fd35fb7e3e8c94f4d744aa4b426b
BLAKE2b-256 74b62098d0126d2d3318fd5bec3ad40d06c25d377d95749f7a0c5af17129b3b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page