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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.285-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.285-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.285-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.7 MB view details)

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

ruff-0.0.285-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.285.tar.gz.

File metadata

  • Download URL: ruff-0.0.285.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.285.tar.gz
Algorithm Hash digest
SHA256 45866048d1dcdcc80855998cb26c4b2b05881f9e043d2e3bfe1aa36d9a2e8f28
MD5 fe670813a054ee6471e4c8bc2ad1578e
BLAKE2b-256 a1bdc3fce7060f2de586f0a0d4abd48ed1a493672cb3bd365c2dcf01b498627b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.285-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.285-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 de44fbc6c3b25fccee473ddf851416fd4e246fc6027b2197c395b1b3b3897921
MD5 03568318992aee3ed893d9d9e650de27
BLAKE2b-256 739f034620a81d832b3ba51d6357de67c5b1cf95e2fc2fdfdc91845fed24243f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.285-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.285-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a8c6ad6b9cd77489bf6d1510950cbbe47a843aa234adff0960bae64bd06c3b6d
MD5 613259bee765bb0b41a85b35671ccef4
BLAKE2b-256 7c2a084bff75aa7f56fb0f837b7b3f4a753a11da98bd5241c75739f0b33fce79

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.285-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.285-py3-none-win32.whl
Algorithm Hash digest
SHA256 770c5eb6376de024111443022cda534fb28980a9dd3b4abc83992a8770167ba6
MD5 54ba48258ac7eee17553eeb64772f776
BLAKE2b-256 785b79342572702ba15ebda57fdd8a330ef406c0840f51b76da3eb9d968aca74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2933cc9631f453305399c7b8fb72b113ad76b49ae1d7103cc4afd3a423bed164
MD5 58b4ce4da0d3acec99f670bead06d6b4
BLAKE2b-256 53e4c8f56ad9c03398473242277bae05c3802904149384c14ed9020d1284001c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.285-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.285-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e6b1c961d608d373a032f047a20bf3c55ad05f56c32e7b96dcca0830a2a72348
MD5 1269e3c005a91787cd3f06c9ce288bdd
BLAKE2b-256 f6158d003f709b290dea823e03fc0072e17e8a4a334f8854aa208b9ffb3f829e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 5473a4c6cac34f583bff08c5f63b8def5599a0ea4dc96c0302fbd2cc0b3ecbad
MD5 3205dd458e93ff384e8f5ec9ec0db1ca
BLAKE2b-256 4e44d3b1c10a1741e83fd3beda1d21be31c727d6f07826db592b61070f43e75d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7ce67736cd8dfe97162d1e7adfc2d9a1bac0efb9aaaff32e4042c7cde079f54b
MD5 fea1bea3a572d3b9667fc2c761c6905d
BLAKE2b-256 39d6c50340ad710707dff939620caa0f0be408b5a7f327442c85847edb3e0551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72a087712d474fa17b915d7cb9ef807e1256182b12ddfafb105eb00aeee48d1a
MD5 810ca780b6906ad623898c564ddcb753
BLAKE2b-256 683825f6cdd4b574f00fd31e7e81c269209cddda95efbaed8ffb0c6bd2410e1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 5977ce304da35c263f5e082901bd7ac0bd2be845a8fcfd1a29e4d6680cddb307
MD5 99fa923aea5f340fc8cc943b05c85b65
BLAKE2b-256 a90182f061bd005641c22acccf72862fc40cd59b8ce5bfcef2c921cfebcf9cd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 80effdf4fe69763d69eb4ab9443e186fd09e668b59fe70ba4b49f4c077d15a1b
MD5 69a036402e308b87dec9d48383c44d7a
BLAKE2b-256 b47f82dcff376c08c0fd93114131a353e066e3b71777791a8cbc933fb354eabb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 f572c4296d8c7ddd22c3204de4031965be524fdd1fdaaef273945932912b28c5
MD5 5880ff9f0c43b1b614729bbcf076468e
BLAKE2b-256 f2d6337590b9235b802227296c0ef57c717f3d82b944c02729f47589dfa8a4b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b02aae62f922d088bb01943e1dbd861688ada13d735b78b8348a7d90121fd292
MD5 6e0cd82c39ef4c68205681285a5f4b3f
BLAKE2b-256 eb94a70fce8b1d8ec59da0d54f6aa234dae875c28903e1ec40bdba6c2126e388

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1d2a60c102e7a5e147b58fc2cbea12a563c565383effc527c987ea2086a05742
MD5 7159070b4ff325987c6ab39834413e04
BLAKE2b-256 c6f49832d5cb5518fc941f3c4683b82eff37ce6b27a18640561ae41a75ede8be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6c48926156288b8ac005eb1db5e77c15e8a37309ae49d9fb6771d5cf5f777590
MD5 3f1f811367bb97c8200a506c78e915e5
BLAKE2b-256 1b550d6560b01ee88988498b9a6e7931c1cea179478d68ee75a4e38579e1a93b

See more details on using hashes here.

File details

Details for the file ruff-0.0.285-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.285-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0d9ab6ad16742eb78919e0fba09f914f042409df40ad63423c34bb20d350162a
MD5 8af2e93e3905a8b072d12f994d245f34
BLAKE2b-256 89cb91b4e0c0ad1aeea2cbc3370fff2a1ca928cea45fd69388faa59cdc71ba4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.285-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 72a3a0936369b986b0e959f9090206ed3c18f9e5e439ea5b8e6867c6707aded5
MD5 4c9d7b8d65e6465f03786e2065869d32
BLAKE2b-256 76debcc425ec51d906ed804ed2c7903cac45d3c09917f06c8b153156b7592c6d

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