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.12 compatibility
  • 📦 Built-in caching, to avoid re-analyzing unchanged files
  • 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports)
  • 📏 Over 700 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.1.1
  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 Pyflakes (`F`) and a subset of the pycodestyle (`E`)  codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# Allow fix 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 700 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 F rules, along with a subset of the E rules, omitting any stylistic rules that overlap with the use of a formatter, 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.1.1.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.1.1-py3-none-win_arm64.whl (5.9 MB view details)

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

ruff-0.1.1-py3-none-win32.whl (5.8 MB view details)

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.1.1-py3-none-musllinux_1_2_armv7l.whl (5.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.1.1-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.1.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.1.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.1.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.1.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.1.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.1.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (11.6 MB view details)

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

ruff-0.1.1-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.1.1.tar.gz.

File metadata

  • Download URL: ruff-0.1.1.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c90461ae4abec261609e5ea436de4a4b5f2822921cf04c16d2cc9327182dbbcc
MD5 00fb2716e7b37a937c5798d5a09ab46d
BLAKE2b-256 734bcf99e57ea6c43a58b0d61ea890e48a685d11141a5066328a097c57c4ce29

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-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.6

File hashes

Hashes for ruff-0.1.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 e140bd717c49164c8feb4f65c644046fe929c46f42493672853e3213d7bdbce2
MD5 f55762aa075419af530392cc64b39ac4
BLAKE2b-256 cbac82bcc0c8bb073e27e8a7e85cfd36fee5d5ac1453e6594075af8cc7419171

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-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.6

File hashes

Hashes for ruff-0.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 3ff3006c97d9dc396b87fb46bb65818e614ad0181f059322df82bbfe6944e264
MD5 1509c4261001131366d30087534036eb
BLAKE2b-256 8403546714c367625ea98878d367b7c448acf1e62f3472ce0a3ef493f793d859

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-py3-none-win32.whl
  • Upload date:
  • Size: 5.8 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 ba3208543ab91d3e4032db2652dcb6c22a25787b85b8dc3aeff084afdc612e5c
MD5 54b71de1c9dd2ab97ddb0108ea550fbf
BLAKE2b-256 9a97043e26d9bc9470a47bf1ab044777b27a3bda65e3b15957eb5d5b2aa4d6f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-py3-none-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: Python 3, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3521bf910104bf781e6753282282acc145cbe3eff79a1ce6b920404cd756075a
MD5 657ce6a5b0525f9a11caaa04a30e4697
BLAKE2b-256 3b5530b7c9574a9a297c3552ed9589dc4f25b33fd611186ee46289209a6ba258

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-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.6

File hashes

Hashes for ruff-0.1.1-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 d3f9ac658ba29e07b95c80fa742b059a55aefffa8b1e078bc3c08768bdd4b11a
MD5 b48eac5ebfcfc052fbcbfde7b62130f3
BLAKE2b-256 5158072ecb4007db28207e0851ba2cf369c3594ea34c9e36c0972fb3c729330c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-py3-none-musllinux_1_2_armv7l.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: Python 3, musllinux: musl 1.2+ ARMv7l
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.1-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 8f5b24daddf35b6c207619301170cae5d2699955829cda77b6ce1e5fc69340df
MD5 ee1e81bbfd17a9ca69af1d61ac31d43e
BLAKE2b-256 e19f5683d370050cf8711b55cbb641ce6faa01ac974f15a779035b9848b4e57e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f4780e2bb52f3863a565ec3f699319d3493b83ff95ebbb4993e59c62aaf6e75e
MD5 cde0616093361c28a38b594f34624973
BLAKE2b-256 b75288ee6aa24ab165d2e2223f889f6deaf5da130f72b802d5ca2700d2dd9301

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cbbd8eead88ea83a250499074e2a8e9d80975f0b324b1e2e679e4594da318c25
MD5 3cce5fae46b5e62f550773fdb0fbca82
BLAKE2b-256 ce6640fca1c9fc95b4bbb5c144fba10791f88dfe266bb49972d4c077238a589d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 bc11955f6ce3398d2afe81ad7e49d0ebf0a581d8bcb27b8c300281737735e3a3
MD5 6b8c24d8c810c6f5354a83f724c724ab
BLAKE2b-256 c499e3a8095addade38a4e7e4cb6996589a3719ce441ab8fad5989b732738a6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2d68367d1379a6b47e61bc9de144a47bcdb1aad7903bbf256e4c3d31f11a87ae
MD5 49c899e9fde165967889efd202edb414
BLAKE2b-256 d518e194039641d966a8e12726fc6d69cce945ffd3dabe9330ccb66f59e1e93a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 6aa7e63c3852cf8fe62698aef31e563e97143a4b801b57f920012d0e07049a8d
MD5 7f04a18818e0fc51b9d5b48be017eae4
BLAKE2b-256 587ae0adc4c6025a0b8946f3d740cd64efb68e3a2cabc096c399f297d4a6112a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c34ae501d0ec71acf19ee5d4d889e379863dcc4b796bf8ce2934a9357dc31db7
MD5 303b043167c72b4a18350fdc88dd96d4
BLAKE2b-256 1a7082d7ce4b51c869d35cba803f42e13faad464de5b55cdf39bc3d847ccf3d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 3305d1cb4eb8ff6d3e63a48d1659d20aab43b49fe987b3ca4900528342367145
MD5 75516130935f2a3bd1bf6345036c8b66
BLAKE2b-256 46387e19b77ddb4d86fa2f9235c249ab1654caa0f02c9235cff9d88c0dcfe44d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a909d3930afdbc2e9fd893b0034479e90e7981791879aab50ce3d9f55205bd6
MD5 41effef0e25bf5aa12acac1ed23bf8a3
BLAKE2b-256 b20bf9895d1d66fd51016e4afba1f8a8e9cc29369a3458fd424c84f2dca6c97f

See more details on using hashes here.

File details

Details for the file ruff-0.1.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ruff-0.1.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 620d4b34302538dbd8bbbe8fdb8e8f98d72d29bd47e972e2b59ce6c1e8862257
MD5 71851e8eae6497c5c6e28ce52e241eef
BLAKE2b-256 e9d93455496a84145334703cf2665c9823c0f55065e9dd126ba012660ad8e9b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.1-py3-none-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: Python 3, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.1-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b7cdc893aef23ccc14c54bd79a8109a82a2c527e11d030b62201d86f6c2b81c5
MD5 1e6f5b0914599ff4d32eb064a403b0b4
BLAKE2b-256 b8596cba8b54c761949a2087a45b6321962680d8520574a6561230e8b00886aa

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