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.279
  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/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.279.tar.gz (1.2 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.279-py3-none-win_arm64.whl (5.4 MB view details)

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.279-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.279-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.279-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.5 MB view details)

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

ruff-0.0.279-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.279.tar.gz.

File metadata

  • Download URL: ruff-0.0.279.tar.gz
  • Upload date:
  • Size: 1.2 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.279.tar.gz
Algorithm Hash digest
SHA256 ad100904a9c3ffe550274d6c891373d70f570c284193129cdcd4188797cadb97
MD5 44b15dd5005091259909b29745f2e914
BLAKE2b-256 29fa5d7335fec3e568052797ec03a3e023ab672060b97137e1c18cb40c72970b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.279-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.279-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 b6a0a30bd9ec73cd743252a06535ffa17b033d3146d2c32c95736a6d73ea2f49
MD5 c1eeb3e901360ced1e29fa57744ec114
BLAKE2b-256 3946ae2d99af1057fdca9f38d94ce38fd1374dde5405d037db9d830045f2df55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.279-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.279-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 38c5e411b8817fa13d7e650499e191d32fd01cd3f29de8eee4bd87a70d5acc1c
MD5 fa9b0a04dec56983b316db77d8a7e19a
BLAKE2b-256 f6e90ed50cdf3f01fee9b2c0a9afc21f817bc41a44bf799aa54d491e8886b2ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.279-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.279-py3-none-win32.whl
Algorithm Hash digest
SHA256 f49fed164034833d709d4539f54c0d1f2c9ac90b5afea5d67ad6ad7fac917f07
MD5 2ca5644739b5e700839637699e5f60f0
BLAKE2b-256 71a78c7985f3e5a923eaf91666729cec6f4925d46c2232826c83baf2ec241de4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2235250e03760886a3900dd1de2d30cb8a0ce4d7a65d622ef0200b77a2161fdb
MD5 c89c388f6d226bc27b83414530c18fd7
BLAKE2b-256 58048c9974439df59d6a349fbcbd517c264963774672fc1c034aeef69a388afc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.279-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.279-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f1976fbfaaaa513e251b9aa8bb5435feeae1ebc7670b52d74a63eee2eec9a2b4
MD5 45b13ba75b1fc0ad9c3e9013b90ef879
BLAKE2b-256 7b4cb3bbd146520ce2ba3590d1272a993b969473f3d64b23c50932d755129776

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 357b3ecf508bddcc0c9e8f271434b4ae0594cb0a022b0db444ad567079f8490d
MD5 a15b99ea4d3aba3c3a363a8fdb80ae08
BLAKE2b-256 8cf613d6347a340d5f76c8b435455289b687141eaeb941a4eb3b241a1dd2ee83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7fa27f3d2c006d5767744a0133b5a27e7db4965695c612dbfc528fd4f418f8aa
MD5 0f0a7fb4fd7f19f1a6fd108454c48f15
BLAKE2b-256 5af82a10d3d8b2e3865e7dcdedad4f549329f19b334d34baf6e90b9ee08083cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3d307ba5d5061e75215ef0f27af1a22eca64a3576673ffb42fca3f8b6b60a26
MD5 17bf55ef27d25184b5f48ab2735669e1
BLAKE2b-256 a2154739a8db831837b2d3b3c9140f28834a3bcebbb35adef3f49cb0e39042b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 5563fa6975f18c771ae928e7c0c15056b9d5603dc1c061b5aec487aa8c8a198d
MD5 239c60fa0ecc54483d035fdca78b041d
BLAKE2b-256 691c817edeb46ce8181760bb4494ea66cb7c195a73db035182a60a209e32a3d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 66cd498eb5b7f03ff86fe62a5d5a76aea9b8772cb2f54282ffc330089506806d
MD5 f54ce91cd0d1445baf2851f26c1b6c4d
BLAKE2b-256 583e0549019de668b880fc7c4bb54bda71885e6ade41ebabd6fd95c237db1a5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 271af3464cad078f0cc9f1342a90346ea99bf048f7fdacd04333e788d7bc754e
MD5 2c60a0e674450518449d8899546f453e
BLAKE2b-256 2afd28f23b81c19e6da7280acc69d986c9aee6e59af5967bde7045cf9c5988e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d2d3d8dacf674298d71ebc6c6a9e636eb506e7b739c12133d2bffe40143092f7
MD5 bfc396ec7f1374cb08d3e9a10e840e54
BLAKE2b-256 93eb8894c2e9c8f5f47410338794d7b4cab1f91006578e661c311b840c68a1f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1ec3edc3c1caad4d8aa7e54b26118b676eb596e68b3549ed2165964b8b288c8c
MD5 74622b3fc85c97218df3abbcf223bbdf
BLAKE2b-256 bb376e38976f1cddfd68930b1f38cbfe45f1f509257abf21c0a8ec74f1134e33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f4322639cfb87493801fb38fa669fba049df08294d6453ab340b54c333cde47d
MD5 61c22cdb5129fd0a8f389145611a8b88
BLAKE2b-256 e4d7a1a46410235937a1b4b58d53cd800a63877f6a62f6f045647989950d710d

See more details on using hashes here.

File details

Details for the file ruff-0.0.279-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.279-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 26c60bd783bf4ccc38279744cd260843aa7b81baf2c7e4f2fb8256b9c13fc704
MD5 b74a8b053e179842b613bfb7f1775f44
BLAKE2b-256 8e019a89e95611c5d45ca39c5a0c506ad0b862d0422986a4ac52d145fba738b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.279-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 16655197ff7c4144cdf0b340c482c46831dcb76ddb01674114781ac0073338cc
MD5 b6bf24e57d5d7d1dd3c4782b08967720
BLAKE2b-256 828692a59e315ca4cc244c2ed370af43d2a4e15ce0f5c1a0c6a799e4e69c166c

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