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.286
  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.286.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.286-py3-none-win_arm64.whl (5.5 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.286-py3-none-win_amd64.whl (5.7 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.0.286-py3-none-win32.whl (5.3 MB view details)

Uploaded Python 3Windows x86

ruff-0.0.286-py3-none-musllinux_1_2_x86_64.whl (5.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.286-py3-none-musllinux_1_2_i686.whl (5.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.286-py3-none-musllinux_1_2_armv7l.whl (5.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.286-py3-none-musllinux_1_2_aarch64.whl (5.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.286-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.286-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.286-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.286-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.286-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.286-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.286-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.286-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.8 MB view details)

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

ruff-0.0.286-py3-none-macosx_10_7_x86_64.whl (5.6 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.286.tar.gz
Algorithm Hash digest
SHA256 f1e9d169cce81a384a26ee5bb8c919fe9ae88255f39a1a69fd1ebab233a85ed2
MD5 1329151ab85a59ccb11068ef2184b8ca
BLAKE2b-256 ebeef89d4771d787983e34a3c715e3e527e4be150d895066e1008ffb46f98ce7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.286-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 1d6142d53ab7f164204b3133d053c4958d4d11ec3a39abf23a40b13b0784e3f0
MD5 78fae4a3408057feafae79c432b96ee6
BLAKE2b-256 f9b92857fe6a0823c23a121dd13669351e15c5d3dbf1440234b11f37144f556d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.286-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5d295c758961376c84aaa92d16e643d110be32add7465e197bfdaec5a431a107
MD5 4f22042317f5ca676cb1e2ed25260921
BLAKE2b-256 acb9d656cb16e2aea48311d6450077c0c90c3daa3becaac409693a1c73cbdc8e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.286-py3-none-win32.whl
Algorithm Hash digest
SHA256 556e965ac07c1e8c1c2d759ac512e526ecff62c00fde1a046acb088d3cbc1a6c
MD5 3ce128e5611602c31ed3f1430bcb3d5e
BLAKE2b-256 764d7bf8a5b9dfb2615a54b1f5ebe3cc49bb5173dff86b05830163579a889a42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9b6b116d1c4000de1b9bf027131dbc3b8a70507788f794c6b09509d28952c512
MD5 276f6edb3a31719005b1d90455a20295
BLAKE2b-256 57ea066e383c01b0bda942863754be6930b07263ceefc8e0c733386f133cfbd6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.286-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 26afc0851f4fc3738afcf30f5f8b8612a31ac3455cb76e611deea80f5c0bf3ce
MD5 5e1caf68598926b1863f3fbf6e30be05
BLAKE2b-256 212cabb06b19ac05c3d77395e3b9fced87e390ae0022b46cd6104e0d9039901b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 3dad93b1f973c6d1db4b6a5da8690c5625a3fa32bdf38e543a6936e634b83dc3
MD5 923216b3eca14c1c677e46c96392d574
BLAKE2b-256 8e01975254624a2a0741a6e4f28fae7dc72168bd0be367b20cfef29e4a60ea3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d73cfb1c3352e7aa0ce6fb2321f36fa1d4a2c48d2ceac694cb03611ddf0e4db6
MD5 a9bb56aa33e973a7b40c33ecb7022fc3
BLAKE2b-256 01816ee7fab0e11c193cdb3e80810fc2adb5d00aaeecb5ed4fa12603cf99bad3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 559aa793149ac23dc4310f94f2c83209eedb16908a0343663be19bec42233d25
MD5 179f98fa9ae4f308d47a46811613809b
BLAKE2b-256 d408454db6d95e440a92fbc42d2c5da711ef9063712102f91ea3b7b1b480062d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 47549c7c0be24c8ae9f2bce6f1c49fbafea83bca80142d118306f08ec7414041
MD5 6503b7fb54b33199459f878ef9e2b996
BLAKE2b-256 96ba083f56dc0a347af88c77ca63fce6e8dcfc0880be0450bcd219541b4fe487

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 ddb61a0c4454cbe4623f4a07fef03c5ae921fe04fede8d15c6e36703c0a73b07
MD5 1d6c53ed212873b2e66eedff4f55031f
BLAKE2b-256 319ce60add2327184b1e816499984a014ea74b1c10b13e4ef14e38ee5d5f29d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 0433683d0c5dbcf6162a4beb2356e820a593243f1fa714072fec15e2e4f4c939
MD5 825e5f355e6ce0cddb05cc98b4446932
BLAKE2b-256 bbe8102d4390174f7c4a0ddfc334fa30c92448f8093d7ad3c59b2681b56a6495

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 88c8e358b445eb66d47164fa38541cfcc267847d1e7a92dd186dddb1a0a9a17f
MD5 c66ffa1fb598693bc0f9e3e3484be94c
BLAKE2b-256 ef7aaf285a7737f3373fcad23ad9b83f4a3ded55f68001d00a1597aba2501f18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 acc4598f810bbc465ce0ed84417ac687e392c993a84c7eaf3abf97638701c1ec
MD5 6450f115c1ad578f4f50a6e2ab568f99
BLAKE2b-256 1bca91aee28242bbb746e1fffd3416925d9cecf97561e99c947a61388da0a73c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8301f0bb4ec1a5b29cfaf15b83565136c47abefb771603241af9d6038f8981e8
MD5 04efe02061ffa815812b7e0a2e3b84a4
BLAKE2b-256 0750721a4de26c4c4a9a59f1900ebc2eff8a8565b684ad0f144f1be0c734b6e3

See more details on using hashes here.

File details

Details for the file ruff-0.0.286-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.286-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 68ed8c99c883ae79a9133cb1a86d7130feee0397fdf5ba385abf2d53e178d3fa
MD5 179d8386e9d07fb35efc4bd5caa8418c
BLAKE2b-256 93ba8c6ba7d2314e231a761a596732a2b014538bd6c80142ffc759807721d64d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.286-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8e22cb557e7395893490e7f9cfea1073d19a5b1dd337f44fd81359b2767da4e9
MD5 30ee0bdb4a9bc649b1090f58d257d894
BLAKE2b-256 7e271ed13b9e50c4bb317b269f6167e2346ebf84ce35bcda984266ada79278f2

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