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.273
  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 the APIs and implementation details of Rome, Prettier, and Black.

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/charliermarsh/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/charliermarsh/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/charliermarsh/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.273.tar.gz (1.0 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.273-py3-none-win_arm64.whl (5.1 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.273-py3-none-win_amd64.whl (5.3 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.0.273-py3-none-win32.whl (5.0 MB view details)

Uploaded Python 3Windows x86

ruff-0.0.273-py3-none-musllinux_1_2_x86_64.whl (5.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.273-py3-none-musllinux_1_2_i686.whl (5.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.273-py3-none-musllinux_1_2_armv7l.whl (4.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.273-py3-none-musllinux_1_2_aarch64.whl (5.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.273-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.273-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.273-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (5.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.273-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (5.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.273-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.273-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.273-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.273-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.0 MB view details)

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

ruff-0.0.273-py3-none-macosx_10_7_x86_64.whl (5.2 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.0.273.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.273.tar.gz
Algorithm Hash digest
SHA256 2a9e3cf11374c112abbc3f77978505d9b4626bf31ce42b44fcf3b528b630c6d0
MD5 771954ed38778e22ae2b16088aea61db
BLAKE2b-256 d233f8395575aa8c6cbd68d790ddb4a5eb014b4336425c74f279711a12125093

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.273-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.273-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 925aa6fc25b1de90a064a767dc767b8ca462b8be996e4113cf2fcc1ba1c2f220
MD5 356b49ec0b1d94a16baab171a35537c5
BLAKE2b-256 cd3cd3c32ee781d9983d507d39d6e38954f9aa676887a6269cd9554caf6f2c8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.273-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.273-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c37edf65794efc724b0c3848bb50977aa0d985a26385550ce7aee0fd1b8a6892
MD5 baa7a0cf2ebe63ee868102aa4f123c01
BLAKE2b-256 43ff806dddcf8b368b02dcc237fbc8853abd3915baaa46da8c8c3e454607c586

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.273-py3-none-win32.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.273-py3-none-win32.whl
Algorithm Hash digest
SHA256 e71e8c2541946523cd457e23af0ebffe5f93020d1309e11bd4b62cda4b73bdb5
MD5 0d589798d56f381135f36f774ec41e62
BLAKE2b-256 2b56ba2b9066380924f67864cce0a474a7ca655b410094bb4da40de5d6fd9752

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 149e96eaab3d9406e27538078a65e7148e245c016b4b953d642cf21d804bf56c
MD5 a95baa6934764f9293f7b1d914c3b506
BLAKE2b-256 a33f88fb179a66c97c23711742f4be0d3aeed4d25f56b408ac5266c26b2737bd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.273-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3, musllinux: musl 1.2+ i686
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.273-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 1c6d86a4bda7beeca1f86d22766c6806a2baf7828b1bc8d85c48d90f6dd76af0
MD5 758cc75e920ac76bc5d87d606026b955
BLAKE2b-256 a7cce8f03c9b23c17f0befbb63f75a028024fd8e1e5f707f4c2ad85dc5f1e606

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 9c87520bd8803db8c52096edc727e582d08965d4faedda505d390c61bf96a8a3
MD5 e6eac37a9921308e088ea346c54b06d2
BLAKE2b-256 4bbc33cf6257057ffda7cad146a2944fcea8b6da7cecd750876105634adb486e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2d7ab824e5043360c3e4e04847e1af0d658f577c669ae0d8f6e3033f65e2dcdb
MD5 1881adac95264ecb2bbe6cd350be3d52
BLAKE2b-256 05ef491730131df31c8cdc49cd3489e3c3bd3b415ea168ec5d0f112348d48ec8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ad54d619cbbe3942fa9b42abbd723ef560230a9aa5a94d591d459d845a524b3e
MD5 00fca693f5aa18b18546c48b8ce3a66a
BLAKE2b-256 5b52d5cd22929164feb7100b42c21ba8575e6d0c6381ebf47b56cdac6882beb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 8338e8dd941c6a66a50139e1c258a93bb0d1dbc9b08615dac9852079d9f33160
MD5 880f6e15060d0a1326d52f4176576847
BLAKE2b-256 4b3b61a3a0b20e0a82473ecedc680689670b4cb2e547da126c7afcfcf4a2f678

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 7cda52bf892de95d889e37ddead87745128d0579cc706af8b146db120e2de7b4
MD5 7e714e9787aa416beec060384d680b29
BLAKE2b-256 3b7058c656d6f9315c2767d026a6e5e497cb11aab97001a9d709c312df808d13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 66a70d9bcdd17ad9517ef70eda5d60060d04c6ed7a670abc092a4e55798f5db5
MD5 ed7187b6928e3f7dcdacc48441889450
BLAKE2b-256 10dc2ca77323d0a96ccf8468d4d29a72a4b1f6933b63d0a4e15fc7e3047f51ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7d6b70c615b141f798437948b46f172592a32543e8f7dfadab30e22c492b8f17
MD5 043347738b86370667b25cad0de1dbb0
BLAKE2b-256 3b56e60f513d7b7e6112d15faa2a6d855c3c774a3fffd3b3191e18ac65b648e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 9d81b186ad1d06f890e1d122c2040af6467678ad2efb90a5e0cbf6283d392f18
MD5 28bfbc8710789eccd7d4dc73f274a7db
BLAKE2b-256 c01ac57c027df95351f69299713bebb7e19b2109233ac16326f486964a12b2ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 58c61bb4bacde2f812b957c8790ef36553bf8b39ecc3048d14f474183de61856
MD5 aec367d1eb428b299283156a20a8aaab
BLAKE2b-256 551d1fecdb8809e27489fa6b4f88a14e4e225c9e666f4a334bd7e830fc748c53

See more details on using hashes here.

File details

Details for the file ruff-0.0.273-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.273-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b3abd486149e34a7f5683154cac5e58ae7b39c28440945342d1854c72288b761
MD5 9271764bd27b469c9aa2b0ff7f1acb77
BLAKE2b-256 3f8c79b7e10389d339336690c2ce01c0b145e30e072d59f5acfd70f2a3f1fb27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.273-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 0f80fc4e26dc784d515298963a7a102a0d0a9997a0bda6bd3824f747528fa0c2
MD5 df15dd801fd368495c217978d6f1ee06
BLAKE2b-256 66fa1c6ef94c0db5dfe12693ae23169c4a62448e0839cf4dacb6e41b616b17a8

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