Skip to main content

An extremely fast Python linter, written in Rust.

Project description

Ruff

Ruff image image image Actions status

Discord | Docs | Playground

An extremely fast Python linter, written in Rust.

Shows a bar chart with benchmark results.

Linting the CPython codebase from scratch.

  • ⚡️ 10-100x faster than existing linters
  • 🐍 Installable via pip
  • 🛠️ pyproject.toml support
  • 🤝 Python 3.11 compatibility
  • 📦 Built-in caching, to avoid re-analyzing unchanged files
  • 🔧 Autofix support, for automatic error correction (e.g., automatically remove unused imports)
  • 📏 Over 600 built-in rules
  • ⚖️ Near-parity with the built-in Flake8 rule set
  • 🔌 Native re-implementations of dozens of 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), isort, pydocstyle, yesqa, eradicate, pyupgrade, and autoflake, 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, 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 can also be used as a pre-commit hook:

- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.0.287
  hooks:
    - id: ruff

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, the default configuration is equivalent to:

[tool.ruff]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F"]
ignore = []

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
unfixable = []

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

# Same as Black.
line-length = 88

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

# Assume Python 3.8
target-version = "py38"

[tool.ruff.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10

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

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 for more on the linting command.

Rules

Ruff supports over 600 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 E and F rules. Ruff supports all rules from the F category, and a subset of the E category, omitting those stylistic rules made obsolete by the use of an autoformatter, like 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 autoformatter 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.0.287.tar.gz (1.5 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.0.287-py3-none-win_arm64.whl (5.8 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.287-py3-none-win_amd64.whl (6.0 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.0.287-py3-none-win32.whl (5.7 MB view details)

Uploaded Python 3Windows x86

ruff-0.0.287-py3-none-musllinux_1_2_x86_64.whl (6.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.287-py3-none-musllinux_1_2_i686.whl (5.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.287-py3-none-musllinux_1_2_armv7l.whl (5.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.287-py3-none-musllinux_1_2_aarch64.whl (5.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.287-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.287-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.287-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.287-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.287-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.287-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.287-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.287-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (11.4 MB view details)

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

ruff-0.0.287-py3-none-macosx_10_7_x86_64.whl (5.9 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.287.tar.gz
Algorithm Hash digest
SHA256 02dc4f5bf53ef136e459d467f3ce3e04844d509bc46c025a05b018feb37bbc39
MD5 f770b438d05d7d464ec70d1cff173d58
BLAKE2b-256 32373ff6797d27ea5f231c1baed6852e6d3cf8606a1048105279fd85bcb05c32

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.287-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 44bceb3310ac04f0e59d4851e6227f7b1404f753997c7859192e41dbee9f5c8d
MD5 6c0e8b7746a28261392737cda5b1f6a7
BLAKE2b-256 990ecdf5e2006a47ff95141aab598f16399e9825a9444a4aeb2c35abb5f75bc2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.287-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 26bd0041d135a883bd6ab3e0b29c42470781fb504cf514e4c17e970e33411d90
MD5 a7f2789b582c476952ab6a0c9c079a74
BLAKE2b-256 251b6bd3dbafbd06d9315df1d86408710feeb193cbaf640dfee7f89808975c92

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.287-py3-none-win32.whl
Algorithm Hash digest
SHA256 022f8bed2dcb5e5429339b7c326155e968a06c42825912481e10be15dafb424b
MD5 45e295266504d43605160c5160cc9e15
BLAKE2b-256 62b6dd611b8708aea30e198ae579081ff197d4e77cd8400ed4b0cac5051fa563

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 33d7b251afb60bec02a64572b0fd56594b1923ee77585bee1e7e1daf675e7ae7
MD5 99c0d4742dcc87ff79d57698b3985b21
BLAKE2b-256 59a149fd474905073adff0332d1f3df493ab717216d5782d51db2c576300cab6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.287-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 2918cb7885fa1611d542de1530bea3fbd63762da793751cc8c8d6e4ba234c3d8
MD5 b1a88c25fb4bd9fd12f1e36e64cf2735
BLAKE2b-256 48dc962ca9dd4c2078816d68856df2454c3888cfb7825fdd603c7678479074f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 a24a280db71b0fa2e0de0312b4aecb8e6d08081d1b0b3c641846a9af8e35b4a7
MD5 b6349e8f03c9d8a0c0b40cf3caf6d078
BLAKE2b-256 5254e6eb703b584fb06745ee81c75668be7fb493154f38d6158d2d306b3741d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 150007028ad4976ce9a7704f635ead6d0e767f73354ce0137e3e44f3a6c0963b
MD5 5f3092d87f22a7def340c31d76c812ce
BLAKE2b-256 e0cd0b4dcd51317eb8120bb592f60ad43e688aab14584c6999b4b92d42067165

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3a810a79b8029cc92d06c36ea1f10be5298d2323d9024e1d21aedbf0a1a13e5
MD5 ddaa91569c172290a1e74cb8716d7867
BLAKE2b-256 ac27448521cb90b51890f2a138a258e427211e1c04c71a3da29e8ec47686ba55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 00d579a011949108c4b4fa04c4f1ee066dab536a9ba94114e8e580c96be2aeb4
MD5 83254cc7afdfc93d603ecc3f9c882723
BLAKE2b-256 421afb4cc780d5a12aff7773cee01eb06324bb09ad98c67a20a9d6d4676c00f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2bfb478e1146a60aa740ab9ebe448b1f9e3c0dfb54be3cc58713310eef059c30
MD5 66c070e53dbd3c7cd2711665af1004e6
BLAKE2b-256 62f566350e42e70ef5a6d6d9b1304e72b4ef87fdeebbbe49c90aa00497c4d525

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 06ac5df7dd3ba8bf83bba1490a72f97f1b9b21c7cbcba8406a09de1a83f36083
MD5 d0d58e07d3c8c5cef40e82c2225f565a
BLAKE2b-256 daa0ab135fcba497221d4195cb1e0eb2d8ac87a01b3271f94c72bcee161279ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 66d9d58bcb29afd72d2afe67120afcc7d240efc69a235853813ad556443dc922
MD5 2c05b2c20edeebe792f57711194f12cd
BLAKE2b-256 76e02ebab57b99929c4bc94d5158678b2bcbbffa9e8d52e8389df9f43233756d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1cf4d5ad3073af10f186ea22ce24bc5a8afa46151f6896f35c586e40148ba20b
MD5 25239b90fe9eecf99c407feaafefd002
BLAKE2b-256 c0248cb4413febaa3cbdfe73c6eed3bee96b5497c6c550b8def4d1ad98a99cdb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8ca1ed11d759a29695aed2bfc7f914b39bcadfe2ef08d98ff69c873f639ad3a8
MD5 ed45d001fe24157df978139a42d615ee
BLAKE2b-256 b3c49ef86e5097314307c5314079d8e82067353d4e92fad447e18421f12784d6

See more details on using hashes here.

File details

Details for the file ruff-0.0.287-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e9843e5704d4fb44e1a8161b0d31c1a38819723f0942639dfeb53d553be9bfb5
MD5 f5419c12afbd8a0d33763163d2c80aad
BLAKE2b-256 52c40dd703ccd8934d941cdd93974234c615ec6dd56f7653ba9c63c577a75bd3

See more details on using hashes here.

File details

Details for the file ruff-0.0.287-py3-none-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for ruff-0.0.287-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1e0f9ee4c3191444eefeda97d7084721d9b8e29017f67997a20c153457f2eafd
MD5 d5787ea4a606d7a9add738bd53b84257
BLAKE2b-256 bde4af4037a9a9a23ae58ed41f1f974cfb4112ae4c99209884a01f9dd5ada6d8

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