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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.290-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.290-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.290-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.290-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.290-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (11.5 MB view details)

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

ruff-0.0.290-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.290.tar.gz.

File metadata

  • Download URL: ruff-0.0.290.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.290.tar.gz
Algorithm Hash digest
SHA256 949fecbc5467bb11b8db810a7fa53c7e02633856ee6bd1302b2f43adcd71b88d
MD5 02337edeaceb25dc5fcbb29bb7484643
BLAKE2b-256 39bd3db93ba781eb0fd4c37c508c3ee18838c3d2df1450436121dca67e70683a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.290-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.290-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 ae5a92dfbdf1f0c689433c223f8dac0782c2b2584bd502dfdbc76475669f1ba1
MD5 9459a75954c7a11dd0e9fd0064a13895
BLAKE2b-256 93f6f5f2cd14c07ab2e6d34ba0d7605944552b1e8a2e266daad745d95d8e94b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.290-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.290-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f1f49f5ec967fd5778813780b12a5650ab0ebcb9ddcca28d642c689b36920796
MD5 9a637e9efaacad7d8a7364c811ccbeed
BLAKE2b-256 50937f898ca90ccb7c86763f714b04d70b6630f457da1d07450b045a9394a674

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.290-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.290-py3-none-win32.whl
Algorithm Hash digest
SHA256 461fbd1fb9ca806d4e3d5c745a30e185f7cf3ca77293cdc17abb2f2a990ad3f7
MD5 cc803b32973465b1cea77664f81be857
BLAKE2b-256 c93d68e1d7a3569fe815b65dd1259293a1efe392bd64f91351f2e2857ec15dc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ac93eadf07bc4ab4c48d8bb4e427bf0f58f3a9c578862eb85d99d704669f5da0
MD5 481d2f839bc04d32e2204a7719ed57fc
BLAKE2b-256 f5a43d9eb0f75f2c44bc6f8bb56e6a7fe0c9d78466b749c569d0c4505eba1baa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.290-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.290-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 75386ebc15fe5467248c039f5bf6a0cfe7bfc619ffbb8cd62406cd8811815fca
MD5 b2f5b4f3e6f581b601887e72c68be827
BLAKE2b-256 51358e82cdaeaf925cf9c8a13f4ca49ee09bfdcab4f9cb72edd70a76ca2e25b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 150bf8050214cea5b990945b66433bf9a5e0cef395c9bc0f50569e7de7540c86
MD5 eca8ef2ef564d5b747ceb7f7ad10f8bc
BLAKE2b-256 9f39b56caa75c29d6384872b323d8602b286aca9eaf36b871ffa16cbe4b5f813

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2ab41bc0ba359d3f715fc7b705bdeef19c0461351306b70a4e247f836b9350ed
MD5 5d8095416003844bebeec6a0ffeaa1ad
BLAKE2b-256 42b627477ed95194fcda3c0ad21a1c53c346b50de61d110608c4d4579bb248eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb07f37f7aecdbbc91d759c0c09870ce0fb3eed4025eebedf9c4b98c69abd527
MD5 fd43de10da183f9a07dc76034029d456
BLAKE2b-256 ef15dcb0e9edf7b4ed38a469ab73855903924dd93b6f073ec587cb8259ed8e85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 75cdc7fe32dcf33b7cec306707552dda54632ac29402775b9e212a3c16aad5e6
MD5 d1b57ef05647197a13c2e4ad1fd0e65a
BLAKE2b-256 7bf2e6daa7a804c590468d9e7d7cee4e2885b58cb4942eb6fa5e751b85e05773

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 1d9be6351b7889462912e0b8185a260c0219c35dfd920fb490c7f256f1d8313e
MD5 f6948be715f31f46f503d6840abe4317
BLAKE2b-256 53d4bfe7e2135255b6b6aa16c037054aa7eb82dd35dd1e129437fa2e457e1285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 bbd37352cea4ee007c48a44c9bc45a21f7ba70a57edfe46842e346651e2b995a
MD5 7caea0be34e536d1dc40731595dbeea5
BLAKE2b-256 cf26d615c933fde3b761cff0ac86f4774a9505225758dbcd8833d5d4d907afd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 982af5ec67cecd099e2ef5e238650407fb40d56304910102d054c109f390bf3c
MD5 aba9cc8cf3bfe19f942d210aa226fdba
BLAKE2b-256 24f083e363396a9282d375890b512afd74eabf1b411baa8f68ef79542bb56419

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d748c8bd97874f5751aed73e8dde379ce32d16338123d07c18b25c9a2796574a
MD5 8360351954dc7573eddcb8b5f8d76330
BLAKE2b-256 1be056d42a0a676335f486dad4d6a6f36b3ed98ad8a01aeafdd3a8c9d2e8b562

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 35e3550d1d9f2157b0fcc77670f7bb59154f223bff281766e61bdd1dd854e0c5
MD5 5dd139b60beccf945fdc043179eb4023
BLAKE2b-256 4a38f9c5aaf70c2307b3455ebca5205e57d2e3684386bfde1e08f50b41245343

See more details on using hashes here.

File details

Details for the file ruff-0.0.290-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.290-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4ca6285aa77b3d966be32c9a3cd531655b3d4a0171e1f9bf26d66d0372186767
MD5 fd727c50192d47c40d953ff4e3b05ed7
BLAKE2b-256 8dc7ade647b984580b7fea40e6fab2e938cc97b222a35c86b82e687a7fa5d721

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.290-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 0e2b09ac4213b11a3520221083866a5816616f3ae9da123037b8ab275066fbac
MD5 91bfb044223477badd2d57b73be3355f
BLAKE2b-256 1d01a16dde27697128f3320203c622679d8845df170f4d679021e338aa533d3b

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