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 500 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.284
  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 500 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.284.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.284-py3-none-win_arm64.whl (5.4 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.284-py3-none-win_amd64.whl (5.6 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

ruff-0.0.284-py3-none-musllinux_1_2_x86_64.whl (5.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.284-py3-none-musllinux_1_2_i686.whl (5.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.284-py3-none-musllinux_1_2_armv7l.whl (5.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.284-py3-none-musllinux_1_2_aarch64.whl (5.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.284-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.284-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.284-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.284-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.284-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.284-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.284-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.284-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.6 MB view details)

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

ruff-0.0.284-py3-none-macosx_10_7_x86_64.whl (5.5 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.0.284.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.284.tar.gz
Algorithm Hash digest
SHA256 ebd3cc55cd499d326aac17a331deaea29bea206e01c08862f9b5c6e93d77a491
MD5 bb188c0a844531f42921824900d7f3c9
BLAKE2b-256 ce8af69eb801a82c6192ac3e8ed135dc0055f65fa7cee7798008f1a75b54945e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.284-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.4 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.284-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 1292cfc764eeec3cde35b3a31eae3f661d86418b5e220f5d5dba1c27a6eccbb6
MD5 67d2ab4d388f243f461686e44b141180
BLAKE2b-256 21a04392c875edd69441587e17a7041bf0bfc893d684b4e4d9166d44d7a7b7c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.284-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.6 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.284-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f67ed868d79fbcc61ad0fa034fe6eed2e8d438d32abce9c04b7c4c1464b2cf8e
MD5 bb2a411026ffdae08c5b066497d74957
BLAKE2b-256 8a19dee5d945772de39830cdacfff5b6ee274968e8e09c233d9ea282818b3b84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.284-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.284-py3-none-win32.whl
Algorithm Hash digest
SHA256 735cd62fccc577032a367c31f6a9de7c1eb4c01fa9a2e60775067f44f3fc3091
MD5 92ad9890aa0eb81ea805638f63d01244
BLAKE2b-256 d704e05129235c6b71f843a812808d939dda30c0874fea1c12007061a260025a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 88295fd649d0aa1f1271441df75bf06266a199497afd239fd392abcfd75acd7e
MD5 6c5d3cbf09430a86b31494893216140f
BLAKE2b-256 46c61b9d40fbcdd2e8a5a1fbef92f0d1c5c55b632f9d36e704fdb169508632fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.284-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 5.4 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.284-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d29dfbe314e1131aa53df213fdfea7ee874dd96ea0dd1471093d93b59498384d
MD5 376230afa5af7bbc8dabbf5b59844935
BLAKE2b-256 c8bb85f6415f87d3300f2719095a8dd379484da042a76d58a4fef04ba9fc98d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 e37e086f4d623c05cd45a6fe5006e77a2b37d57773aad96b7802a6b8ecf9c910
MD5 cfa08245f5a87fb83221e1345f57eb8b
BLAKE2b-256 f203d25a0266abc3df6267589d86330214e1d6d2583f1c94206039209a8c0af9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f86b2b1e7033c00de45cc176cf26778650fb8804073a0495aca2f674797becbb
MD5 520b7f3ac81f82a6f2b0367f5bc60570
BLAKE2b-256 dc297f75eb219effb8f256adc5be879af863494733ffe94b63ac522aa7134b85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c4c79ae3308e308b94635cd57a369d1e6f146d85019da2fbc63f55da183ee29b
MD5 81f2b7227aed994a13b46fb1d65e9ed1
BLAKE2b-256 bcda75543925543cb000cfc39c1ca1b4cd1b4bef39868da32d79b36de6fcb27d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 d1d098ea74d0ce31478765d1f8b4fbdbba2efc532397b5c5e8e5ea0c13d7e5ae
MD5 fdafa50910801d4235f3b05f3bc03eca
BLAKE2b-256 93dd7dc6e56cbf0dfb8cea86f60f26cb511f12c9694c5fffc4ef5b0a6701111f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 b2fe880cff13fffd735387efbcad54ba0ff1272bceea07f86852a33ca71276f4
MD5 6d6ecdfdcf3652e31119ff5536985250
BLAKE2b-256 9e29895765d896970b2fe633651a86a57f25baafc5b058b74b70592e8b31df09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 0a3218458b140ea794da72b20ea09cbe13c4c1cdb7ac35e797370354628f4c05
MD5 f304f8f1d2c454e6f508aafa165002f0
BLAKE2b-256 7341f75d55d75cc53c3230ec3bff6325e9aef0e5daea5d176eee4993eb252fdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b3660b85a9d84162a055f1add334623ae2d8022a84dcd605d61c30a57b436c32
MD5 280c0fa9650cacce6d69a3b58e820387
BLAKE2b-256 21d308984f8493156f2b9cfc86159075d5116dce861ddda2715b9b125e5cb3e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 bcaf85907fc905d838f46490ee15f04031927bbea44c478394b0bfdeadc27362
MD5 d7442eda2dee8658aaabfe1f59e406b7
BLAKE2b-256 e2c58fc7057de618e6602a371687f34515aa6ca6282255a5f9dfd5b6734d4162

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1d1f7096038961d8bc3b956ee69d73826843eb5b39a5fa4ee717ed473ed69c95
MD5 947c613f86fd7d5850b808eed2752d79
BLAKE2b-256 67f4e9551e84f68988545101bbc363a6f0eec62c269be4df7632c6cdd7d9d929

See more details on using hashes here.

File details

Details for the file ruff-0.0.284-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.284-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a3930d66b35e4dc96197422381dff2a4e965e9278b5533e71ae8474ef202fab0
MD5 26d0a7a5a996c39a2a14c701e425aa37
BLAKE2b-256 cb72162879b9bf8b23749465299d7c46781ede5ebd05302127556b5a217d43fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.284-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8b949084941232e2c27f8d12c78c5a6a010927d712ecff17231ee1a8371c205b
MD5 03c7789219e6b3fbe73a5ed0f28395f0
BLAKE2b-256 4847b6562cbe5b20984662011f27a8349215145a167940f8188041b50ba3799b

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