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.12 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 700 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:

pip install ruff

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.1.9
  hooks:
    # Run the linter.
    - id: ruff
      args: [ --fix ]
    # Run the formatter.
    - id: ruff-format

Ruff can also be used as a VS Code extension or alongside any other editor through the Ruff LSP.

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@v3
      - uses: chartboost/ruff-action@v1

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:

[tool.ruff]
# 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.8
target-version = "py38"

[tool.ruff.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]+?))$"

[tool.ruff.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"

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

ruff check path/to/code/ --select F401 --select F403 --quiet

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 700 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 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

MIT

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.1.9.tar.gz (1.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ruff-0.1.9-py3-none-win_arm64.whl (6.8 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.1.9-py3-none-win_amd64.whl (7.1 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.1.9-py3-none-win32.whl (6.5 MB view details)

Uploaded Python 3Windows x86

ruff-0.1.9-py3-none-musllinux_1_2_x86_64.whl (7.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.1.9-py3-none-musllinux_1_2_i686.whl (7.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.1.9-py3-none-musllinux_1_2_armv7l.whl (6.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.1.9-py3-none-musllinux_1_2_aarch64.whl (6.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.1.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.1.9-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (8.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.1.9-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (7.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.1.9-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (8.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.1.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (7.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.1.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (6.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.1.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.1.9-py3-none-macosx_10_12_x86_64.whl (7.2 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

ruff-0.1.9-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (14.1 MB view details)

Uploaded Python 3macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: ruff-0.1.9.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9.tar.gz
Algorithm Hash digest
SHA256 b041dee2734719ddbb4518f762c982f2e912e7f28b8ee4fe1dee0b15d1b6e800
MD5 8dab64f994c5347c4489f23d1ffdd260
BLAKE2b-256 6d50a3b468c0aa5da0ba0485e250398252848cf44a1bcc930f0365e80ca1ae7a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.9-py3-none-win_arm64.whl
  • Upload date:
  • Size: 6.8 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 0e17f53bcbb4fff8292dfd84cf72d767b5e146f009cccd40c2fad27641f8a7a9
MD5 5c06d36f614c4434c09207a82052ba64
BLAKE2b-256 56438cb73e3d8206461cf07978239779890a9240abfe325cfc2206439bea906a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.9-py3-none-win_amd64.whl
  • Upload date:
  • Size: 7.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c497d769164df522fdaf54c6eba93f397342fe4ca2123a2e014a5b8fc7df81c7
MD5 5cd7038367c076b2c6ddc37647ef1a14
BLAKE2b-256 44492c5295edd51486e70572d7c0f4f0c4a3de707d1e64f44cb442549fb9bf58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.9-py3-none-win32.whl
  • Upload date:
  • Size: 6.5 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9-py3-none-win32.whl
Algorithm Hash digest
SHA256 8151425a60878e66f23ad47da39265fc2fad42aed06fb0a01130e967a7a064f4
MD5 886c883562e6d7d69cfb2fb986eb66ab
BLAKE2b-256 bbe14500197f81405564f24d51397a183e503c32bff5adfb3b29e057af379bec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.9-py3-none-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 7.5 MB
  • Tags: Python 3, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 331aae2cd4a0554667ac683243b151c74bd60e78fb08c3c2a4ac05ee1e606a39
MD5 82749ab0272ce4636c3c8ef8b2a2e442
BLAKE2b-256 db7faf898aea1aaa7fb56e9c1fa15b577ffd89eef8c119b5351708cb4ac277e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.9-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 7.1 MB
  • Tags: Python 3, musllinux: musl 1.2+ i686
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e6837202c2859b9f22e43cb01992373c2dbfeae5c0c91ad691a4a2e725392464
MD5 22747b9651ae5a96920e799946ecb2d8
BLAKE2b-256 2765f8c610a0c37905ef26c98f4d8cf477ecabded10d36c6fe987f5b1a68860b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.9-py3-none-musllinux_1_2_armv7l.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: Python 3, musllinux: musl 1.2+ ARMv7l
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.9-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 837c739729394df98f342319f5136f33c65286b28b6b70a87c28f59354ec939b
MD5 76f902ef3bee20dfdeeccf80ca006709
BLAKE2b-256 ceb1d6b4a175cc56ab2fc33f80d7d877ddfbdbaf8a30a471089faf54f4277482

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 aa8344310f1ae79af9ccd6e4b32749e93cddc078f9b5ccd0e45bd76a6d2e8bb6
MD5 efae88488aa1d82cd4c1e58faf8944e0
BLAKE2b-256 0ddfff92d9153a4572708be25edf8d03f2b06dbe532d25cfc9b48259c1e5c4cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 479ca4250cab30f9218b2e563adc362bd6ae6343df7c7b5a7865300a5156d5a6
MD5 9f2c1a6be2726b83ec570ba80ea92252
BLAKE2b-256 eec073cd8e083ca0fac4a53c0c2386624ae682d23cf51735f02f53aec9511ded

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 744dfe4b35470fa3820d5fe45758aace6269c578f7ddc43d447868cfe5078bcb
MD5 03b4da2cc6b6b3369a642018bb977d18
BLAKE2b-256 b687f5f9275f179cd35435d003eb7ae319d1ef7b544ff3b597cbd2c57a3cb365

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2aec598fb65084e41a9c5d4b95726173768a62055aafb07b4eff976bac72a592
MD5 5e03b63e8a1b9866a1d2aace3b5b04c0
BLAKE2b-256 2ff52fd84888ea55d1032e1f9dcf19a5fc525e99f32c6f0ca608440add68f01d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 69dac82d63a50df2ab0906d97a01549f814b16bc806deeac4f064ff95c47ddf5
MD5 8d9610a5fb64ef59dbb9b53df0c5ff0b
BLAKE2b-256 f8bb5943bba9026c11c6a216c6ae90bef83225df2ffa744d88a437be2c1707c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4d0738917c203246f3e275b37006faa3aa96c828b284ebfe3e99a8cb413c8c4b
MD5 b842d24ff365997b257886cdbd84e0c7
BLAKE2b-256 7791404f7fd13f4b52b5f5d9b77bd39c7a25c90cbdcf8d1e31b60fc8ff59212c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1e63bf5a4a91971082a4768a0aba9383c12392d0d6f1e2be2248c1f9054a20da
MD5 ecfc130872d73d2420f5b80eaea4e257
BLAKE2b-256 ad077d5ef754fbe8a8fc4b6e0a68c056d9a49c273cdc2e87f2f56f6805250e03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 104aa9b5e12cb755d9dce698ab1b97726b83012487af415a4512fedd38b1459e
MD5 e51d2aa7653c0637c71cfefded79b193
BLAKE2b-256 6956ee732b3e0b8fe45718fe9378817877ec5ebd4699ec3694049cc1a37dacd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 28d920e319783d5303333630dae46ecc80b7ba294aeffedf946a02ac0b7cc3db
MD5 56be7a37d093736a5b6a58f6e580210f
BLAKE2b-256 0b897ca0c369eab58aa997516e07f097d01bb589552e77ed78c09cc318be6518

See more details on using hashes here.

File details

Details for the file ruff-0.1.9-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for ruff-0.1.9-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e6a212f436122ac73df851f0cf006e0c6612fe6f9c864ed17ebefce0eff6a5fd
MD5 0840e8f49a3839b5c38c3417abcd7f67
BLAKE2b-256 a608a333f9b28df9b7e9943fc1e36a87f7fc35c0b87f2162621ea226e3de051c

See more details on using hashes here.

Supported by

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