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.281
  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.10.
target-version = "py310"

[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.281.tar.gz (1.4 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.281-py3-none-win_arm64.whl (5.3 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.281-py3-none-win_amd64.whl (5.5 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.0.281-py3-none-win32.whl (5.2 MB view details)

Uploaded Python 3Windows x86

ruff-0.0.281-py3-none-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.281-py3-none-musllinux_1_2_i686.whl (5.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.281-py3-none-musllinux_1_2_armv7l.whl (5.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.281-py3-none-musllinux_1_2_aarch64.whl (5.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.281-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.281-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.281-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.281-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.281-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.281-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.281-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.281-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.4 MB view details)

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

ruff-0.0.281-py3-none-macosx_10_7_x86_64.whl (5.4 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.0.281.tar.gz
  • Upload date:
  • Size: 1.4 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.281.tar.gz
Algorithm Hash digest
SHA256 bab2cdfa78754315cccc2b4d46ad6181aabb29e89747a3b135a4b85e11baa025
MD5 18b5d1248a04a6acbccd42579f187d64
BLAKE2b-256 1adcdad85977aaa046f05ad8eacb8c58ddad02f6fb95a31320a85426f9efc574

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.281-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.3 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.281-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 42a92a62fc841f7444821444553fd6e1e700bb55348f24e8ec39afdd4e3d0312
MD5 5a35942387ae5ad81ce2df58903b6897
BLAKE2b-256 013786bbb5bdb70487b745b837a67e716d0bc9e86dd71f740acbe598279ba283

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.281-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.5 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.281-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 70f921438bf09f04c0547cf64c137c87ef33cbec2b64be12b8caa87df261a016
MD5 236d5462a7803e6de0bca687ca504409
BLAKE2b-256 7929cbb990bf4e275e9b7e89bb3408163f305892ffbce1a62c866b2d0e564413

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.281-py3-none-win32.whl
  • Upload date:
  • Size: 5.2 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.281-py3-none-win32.whl
Algorithm Hash digest
SHA256 7b781f6a7ed35196e6565ed32f57d07b852b0dcd7158c6c7669c8b5d0f8cf97a
MD5 a95a2ab04b28894f3edfd9b0299186df
BLAKE2b-256 0a3a64c1dde041a2e4b0c88f4c3a89da5f88160c3e119b42ecbb39a84af1cfc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 29a22b7a6433ce0b4e601897e8a5dd58a75c75c01afee9b8922ebbdd1fe51e51
MD5 19df51cb806182114c79fac6a376abbc
BLAKE2b-256 c2f6402d24acf9405a43aa8b637650c19230a256ba7b0f0899fb2734685e2814

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.281-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 5.3 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.281-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 54bab7128167057ee5987bbd9f925fbf105071068de9d8474ca7c38f684b8463
MD5 fe065c81fb704cbc943cc581538aeba1
BLAKE2b-256 e27144398794a8cf1d1382947a1c36530835ab4ee9a78ab7f3a336c11ad435d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 24d0defeb2c6a1b16a4230840d1138e08bc4ef2318496fa6ff7ddbf3a443626f
MD5 6eab063628678fb90a993605810ef288
BLAKE2b-256 df578b256400ea22d35d1621e6c0e82e9de90c448d55f11d28fba8e9da1750db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cbf279fd9c2ca674896656df2d82831010afd336a6703a060fe08d6f2358e47b
MD5 6ec3062fbd77b91496d667daa5f059d4
BLAKE2b-256 bca622073beaf45849bcf93b0e51cca1004b957b598e3bfa65c6d43a5ae5fb7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f5b8ccaabad61e2d50494df820b7bafd94eac13f10d2d8b831994c1618801a9
MD5 9eb2a06f136788104daea0a7f4fd2b52
BLAKE2b-256 d452958db90f22fc7f075b4d4159b6ef522f14f0f779c4157a8f0e9689b9e2db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 2ccb875a4000bcba6cc61cb9d3cd5969d6b0921b5234f0ef99ad75f74e8935ef
MD5 1dc42a9515f7fb892e0894a11c10d95a
BLAKE2b-256 841822cd2267662f75ec57f18b889a8992f3e36267f85741cd3e628c4acafdfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 dd3c94260a148e955fb46f41d4bcecd857c75794e9f06ebfa7f9be65cfed9621
MD5 bb8bbfa0ea1834d9a6830d9a2e4372b0
BLAKE2b-256 0e8e2f718c68d3f1037cc8e1c5c4f8b0a25dcba9e7a17c6e9d4068ae79d8e6ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 6d34cae6ef6c6b6fd6d4f09271fbf635db49e6b788da1b2e1dea11a29f1c2a11
MD5 a0b6cfe4af4d739818ce561fb3610310
BLAKE2b-256 108aaa05144aa6a0117c5e10dbdcbceecfe8d6906aefcb3a58c3bba6bfc95963

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ae0b836c03a7010527bb56384a4e3718e0958e32bea64459879aacdcb65c4945
MD5 91b0f61bb777bf9e33adeffa70126a79
BLAKE2b-256 083f8f8fb81fd96ae448880d5f505854dadbb0261fc9dae2f187a219f4bac29d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 f3495175e6d85a01d3da409a079461a5a3c15b70237cc82550ad8c1f091002c8
MD5 bd47d05c2566687ce899af2d55925f8b
BLAKE2b-256 9bd163cdcb22e010e4f236187b598a37501490b145a21045efe7bd6f360f61cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0162b149a94f6007768820bcdf4ccb7e90a21655aac829ace49f4682d0565fdb
MD5 aa5d71a612575ac160c03bd5401385e1
BLAKE2b-256 b03030120ef8fbfea2baf5772e63ad99d48d67b4f3a7105adfe9a1e652cb8e8f

See more details on using hashes here.

File details

Details for the file ruff-0.0.281-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.281-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c086bf3968d5cb2b4f31a586fc73bc42cb688c32f4c992ff161d4ce19f551cf2
MD5 9a7aca7bac3ac14b2c12c4dc6aa31d2c
BLAKE2b-256 4feae46ca2b62f6c018e0baac4858db8219a72940f67bb3fe10fac98a807ccbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.281-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 418fbddfd3dba4d7b11e4e016eacc40d321ff0b7d3637c7ba9ad3ee0474c9a35
MD5 db38fde38e0de412768e734601be475c
BLAKE2b-256 f7946cc45d8d608eb77d899875b534e551f8555327adaa5cde773c5fa4a014f4

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