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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.283-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.283-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.283-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.283-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.283.tar.gz.

File metadata

  • Download URL: ruff-0.0.283.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.283.tar.gz
Algorithm Hash digest
SHA256 6ee6928ad7b6b2b103d3b41517ff252cb81506dacbef01bab31fcfd0de39c5bb
MD5 2a055f2b7dad7e7637082641c6c1e804
BLAKE2b-256 93baf1c8b0a7411e7e14b7042376267ea39aaf1c6a13ec3706bec222e6b559a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.283-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.283-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 28732d956171f493b45c096d27f015e34fde065414330b68d59efcd0f3f67d5d
MD5 35825105a42be6fa5e66ddfef30d6da6
BLAKE2b-256 e140815b6c5b4d672c42f8ebe17ec1c9e4b130a1fbee32fa05def3df81076a2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.283-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.283-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 28e3545ff24ae44e13da2b8fc706dd62a374cc74e4f5c1fbc8bc071ab0cc309f
MD5 7e8f6a3dafaa34afed678f69ba364f2e
BLAKE2b-256 d864aa58e12154595e5c0d103f6c697ddce0abc24043178c682eb07eb3b787c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.283-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.283-py3-none-win32.whl
Algorithm Hash digest
SHA256 bd64f9775d96f35a236980ac98ed50fb5c755b227845612a873ad4f247c0cf8d
MD5 05f88ff83d68090686e16b50992e97f9
BLAKE2b-256 b7e348225b5c70828263f8daa56c51f74c198d57c313a68fd452b8dfb6266b09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ad5a3042cbae1b82c3c953be77181a0934a6b02ba476fec4f177eb9c297e19ed
MD5 454545b4d564d31cfc9ac46fc529d9f3
BLAKE2b-256 e0a1dbd532ad395ae7172186c963f3027ffe3cf57c31c187a21ce9d24a569886

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.283-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.283-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 b1eae6990b078883c0cae60f1df0c31d2071f20afcec285baa363b9b6f7321cf
MD5 c2200fd43ea2c8bd79c510c63ea9478b
BLAKE2b-256 31a9261cac06f52ee2650d125aed0991ba92d57b41b849451bbf50be8c1eb86e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 c32eb49ecf190a7bec0305270c864f796b362027b39a7d49c6fb120ea75e7b52
MD5 a10dd7015373b6259c5d84420acedf66
BLAKE2b-256 43965e9d4dcca217984aadea985c9d8da6a675e9b087f5f7c670f94b279848e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c5d72c97daa72f8914bf1b0c0ae4dbffc999e1945c291fa2d37c02ee4fa7f398
MD5 140ecc06295986d9cb5c67463596b454
BLAKE2b-256 53325fd9ae820d328dc008ba13616ec6a031179e640ae626dbd16e3a98c646cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e43d3ab5c0bdb7b7a045411773b18ed115f0590a30c8d267c484393c6b0486ba
MD5 550f8382f2bf05997b08658654bd35cc
BLAKE2b-256 f200c32a28296e2d3c5c4b8d021ebc6755a2c8a7ed4eaba898314b14c056166b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 d539c73e207a13a915bde6c52ae8b2beb0b00c3b975e9e5d808fe288ea354a72
MD5 768be1e29482f7d8fd46e36f25128a1e
BLAKE2b-256 d9243f57050b5f9557cfe1620c5338dfb4c0b507d93d50ffd011d12090543f05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 b773f1dc57e642f707ee0e8bd68a0bc5ec95441367166a276e5dfdf88b21e1bf
MD5 7f37014a23705c97782a865acfb17aaf
BLAKE2b-256 b39413ef9bc2d0f337704f4951b8f6eee1dade1b9aac87bb73da36fa714e05ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 fe095f2c3e8e557f2709945d611efd476b3eb39bdec5b258b2f88cfb8b5d136d
MD5 253b54841702a275adc168e0b1651ae8
BLAKE2b-256 827f86361e8200ef4cb1a13464b28d49f8bb36d915c0ed322f518ff342e80880

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d21b29dc63d8ec246207dd7115ec39814ca74ee0f0f7b261aa82fb9c1cd8dfcf
MD5 d48989b5c2027f6339dc5c60a0b2cabd
BLAKE2b-256 94a8797b6753bd111141d861ac3f25e8b59b8f0cca882197d42bd56074bf3927

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a4d36f0b3beecc01b50933795da718347ee442afa14cced5a60afe20e8335d24
MD5 adc0f1766d641d50095125221a910eb6
BLAKE2b-256 60fd0d57aa40066eec8f4823609d2cb5792500d2c73f5d3006f801b3645d1663

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 03622378270a37c61bb0f430c29f41bdf0699e8791d0d7548ad5745c737723fb
MD5 a018e24294d2531bfd544e02a980294e
BLAKE2b-256 821698565012b1a09fadb7a171e262b0ee024b270e96adf29f2be8df1efa0391

See more details on using hashes here.

File details

Details for the file ruff-0.0.283-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.283-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 742d3c09bb4272d92fcd0a01a203d837488060280c28a42461e166226651a12a
MD5 3cb1b7da386f76dfd91c90802f245037
BLAKE2b-256 8c573c10970d824cf59d427678fbb4b2cd8ec3c313a8c2a8ea831994f4d0a25d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.283-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 d59615628b43c40b8335af0fafd544b3a09e9891829461fa2eb0d67f00570df5
MD5 13105ccf97c23a385a3aaa00b0bd382c
BLAKE2b-256 bd38cba2ef6aca50cc02eef7758434f5fb479cac950398a529b13079dbe92e45

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