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 700 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.291
  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 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 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.291.tar.gz (1.6 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.291-py3-none-win_arm64.whl (5.9 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.291-py3-none-win_amd64.whl (6.1 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

ruff-0.0.291-py3-none-musllinux_1_2_x86_64.whl (6.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.291-py3-none-musllinux_1_2_i686.whl (5.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.291-py3-none-musllinux_1_2_armv7l.whl (5.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.291-py3-none-musllinux_1_2_aarch64.whl (5.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.291-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.291-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.291-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.291-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.291-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (6.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.291-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.291-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.291-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (11.6 MB view details)

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

ruff-0.0.291-py3-none-macosx_10_7_x86_64.whl (6.0 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.0.291.tar.gz
  • Upload date:
  • Size: 1.6 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.291.tar.gz
Algorithm Hash digest
SHA256 c61109661dde9db73469d14a82b42a88c7164f731e6a3b0042e71394c1c7ceed
MD5 aa3248bd82d54d302a6c9925e7e78097
BLAKE2b-256 8e9585b2eb58942f044b5334d414aee5be51d54f1605f940e1c3703c68d2fc9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.291-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.9 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.291-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 d867384a4615b7f30b223a849b52104214442b5ba79b473d7edd18da3cde22d6
MD5 9f486c8e62598726dd2d101bd7c83baa
BLAKE2b-256 8e7964bf9d52530bc321f49bc77d933730aaffaabdba284a24eb572193b07b81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.291-py3-none-win_amd64.whl
  • Upload date:
  • Size: 6.1 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.291-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8a69bfbde72db8ca1c43ee3570f59daad155196c3fbe357047cd9b77de65f15b
MD5 5bb6fc896691e5e4f53c3cb4399083bc
BLAKE2b-256 e019922970606c09cbb4ddda693ca3f098fa1fa3b7f8ce24ec684602c93c6320

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.291-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.291-py3-none-win32.whl
Algorithm Hash digest
SHA256 1d5f0616ae4cdc7a938b493b6a1a71c8a47d0300c0d65f6e41c281c2f7490ad3
MD5 dd042fbd563c492ba83a47d72eac0f2d
BLAKE2b-256 b58abeb30a34d030559fe3187465e4958cc54be648dbe2b77767fd10cf6bade4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5383ba67ad360caf6060d09012f1fb2ab8bd605ab766d10ca4427a28ab106e0b
MD5 6110168041d8a69ffba7e622ba19d72c
BLAKE2b-256 15a373c83556ddbd72b6d8015f627a12d08c0385e94cd86dc5897b719467f7f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.291-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 5.9 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.291-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 fd17220611047de247b635596e3174f3d7f2becf63bd56301fc758778df9b629
MD5 0b990cd468ec828c5c0fe1ba1511a840
BLAKE2b-256 c9039e47a9555f48d3394aba31a5fe33e6554f1d997be49c0aa80107508f3362

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 6c06006350c3bb689765d71f810128c9cdf4a1121fd01afc655c87bab4fb4f83
MD5 e98f0b521cf92d9e355966d103b528f1
BLAKE2b-256 2a49f0ab19d7be0057f6de80a75f14607fb2bb5abae2b6a1d104e05a8a4301cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b3eeee1b1a45a247758ecdc3ab26c307336d157aafc61edb98b825cadb153df3
MD5 c0d103641e262991f62af0bbd827724d
BLAKE2b-256 f2524aeb88faea070c2de7a313ef760511d64509be94894c7ece4af1684ce69d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13f0d88e5f367b2dc8c7d90a8afdcfff9dd7d174e324fd3ed8e0b5cb5dc9b7f6
MD5 5a4f05b084ad4e36737e33c58d540df8
BLAKE2b-256 40276460dca11b54bdd0a1bcfc81df80449cf732e8944b0b0913fad8fbe95c7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 8d5b56bc3a2f83a7a1d7f4447c54d8d3db52021f726fdd55d549ca87bca5d747
MD5 336d40884fa4b6d8b20c83ecb8870dd8
BLAKE2b-256 dcbcbd6b34dc2b83c52b2d4af632441bacaab7f0025883056b15f461b2047508

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 b09b94efdcd162fe32b472b2dd5bf1c969fcc15b8ff52f478b048f41d4590e09
MD5 41c6ecc74c13ec469f4bf95ce997fd5a
BLAKE2b-256 d3b7d11d5205fe3c12126dd044f6649ff436d026f4efa594abdb92a7c773ec01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 b75f5801547f79b7541d72a211949754c21dc0705c70eddf7f21c88a64de8b97
MD5 f8df1110fd7f08b038d93348373895fd
BLAKE2b-256 105fc049e57e55c956508285294fa7afb0945ef19c5c12f1f247f916b6fa6b06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 87671e33175ae949702774071b35ed4937da06f11851af75cd087e1b5a488ac4
MD5 283342d1fe0f22329cdc6f6755899db4
BLAKE2b-256 4700a41fadb19b0f73ef50fa0a89a6c74427d9b54a577aed98bd2dd74af7989b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 b727c219b43f903875b7503a76c86237a00d1a39579bb3e21ce027eec9534051
MD5 d7eddfc1dc8f6a1688650b0e7e2b1724
BLAKE2b-256 9ea5c156efe5c0ae3843c760b837013691f4640b1861d070b01c384a59ecc02e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a04b384f2d36f00d5fb55313d52a7d66236531195ef08157a09c4728090f2ef0
MD5 1cec87284c0afc7ad460b8123f16d374
BLAKE2b-256 6f4487c77137a23c867970dc42c12e9e695a5765cf72d97cf1eed261f50dff66

See more details on using hashes here.

File details

Details for the file ruff-0.0.291-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.291-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6ab44ea607967171e18aa5c80335237be12f3a1523375fa0cede83c5cf77feb4
MD5 c5b8c13493d48d2dd07cbd333b9b0a50
BLAKE2b-256 858be06fc87918fd2eabb801f4ed5ec6d97cb33c1b8aa34e854481ed3f764131

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.291-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b97d0d7c136a85badbc7fd8397fdbb336e9409b01c07027622f28dcd7db366f2
MD5 6684aa8bf1ad6240d5177cb3318fa9fd
BLAKE2b-256 7a8c702467bfcdc4fc0a8d553f4ee0f87f91e967b7283c628f02610e12e08de7

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