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

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

ruff-0.0.278-py3-none-musllinux_1_2_x86_64.whl (5.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.278-py3-none-musllinux_1_2_armv7l.whl (4.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.278-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.278-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.278-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.278-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.278-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.278.tar.gz.

File metadata

  • Download URL: ruff-0.0.278.tar.gz
  • Upload date:
  • Size: 1.1 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.278.tar.gz
Algorithm Hash digest
SHA256 1a9f1d925204cfba81b18368b7ac943befcfccc3a41e170c91353b674c6b7a66
MD5 b94d99e697f6ab51df79d77c1eccd4df
BLAKE2b-256 62a7d9676918ca1bb168f03829b0e281588ca0b48d7cfb6f8c984eaaa1a6e739

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.278-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.278-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 737a0cfb6c36aaa92d97a46957dfd5e55329299074ad06ed12663b98e0c6fc82
MD5 d63fb434279e6ba25c53417c59982ae5
BLAKE2b-256 08a02bb0323db564c4e3c4ba8ff7daf2ffcebda709667d674e24dc3c20836a51

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.278-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.278-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e131595ab7f4ce61a1650463bd2fe304b49e7d0deb0dfa664b92817c97cdba5f
MD5 444eba94b4e946c227a2b52388377a85
BLAKE2b-256 8a72624d91c480888b4672bb2e7e78e053da8bdf3a2f02e96f09ae8dabf1a0e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.278-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.278-py3-none-win32.whl
Algorithm Hash digest
SHA256 70d39f5599d8449082ab8ce542fa98e16413145eb411dd1dc16575b44565d52d
MD5 ef80e5bb839870c4f71dda9d7c2f5ce5
BLAKE2b-256 4284023db1b2e624225a438882b575fbf1ff2952d1a1e91f00b51f79af715ff1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1cae4c07d334eb588f171f1363fa89a8911047eb93184276be11a24dbbc996c7
MD5 18726849ff39b456c656304db0e59322
BLAKE2b-256 8758abf00b31e16cee595b336ef0051c1c5ef1ea1894d508124904b04bec6f58

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.278-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.278-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 3ce0d620e257b4cad16e2f0c103b2f43a07981668a3763380542e8a131d11537
MD5 4a3a5d4d329b8289d59932c7dad08998
BLAKE2b-256 48581e8727ef4e37e2adcfdceb934efb325478ed4b7808aa518a266fd757797a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 1078125123a3c68e92463afacedb7e41b15ccafc09e510c6c755a23087afc8de
MD5 797311a84672b7b61e53ba919710c924
BLAKE2b-256 b51bcb5e0bc6b0ac534102f5d78204e19f5d4e4d914f4b8312b083eacba712ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a48621f5f372d5019662db5b3dbfc5f1450f927683d75f1153fe0ebf20eb9698
MD5 98febb0b68b3ba69b0e4c713b27f2299
BLAKE2b-256 2b043bb5a0769a71eb7c54e47e5142391747b43b8ca80b5c4119120acee3798c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c25b96602695a147d62a572865b753ef56aff1524abab13b9436724df30f9bd7
MD5 4538c7bcbdc00589a9f006e1c3d3cc00
BLAKE2b-256 814107bed06b79495220c1d30e2acc3a0f30fd89dcc439a88978d7ec7f866886

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 ec8b0469b54315803aaf1fbf9a37162a3849424cab6182496f972ad56e0ea702
MD5 ecbc6c8f834170b4866c14f6c312bd5c
BLAKE2b-256 3dc4dbc0a3c770d6c817a6827de6201a92c22218dbf244276c6954c4de2ad949

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 666e739fb2685277b879d493848afe6933e3be30d40f41fe0e571ad479d57d77
MD5 5f24664f0b3c35f05d9c68a09a84477b
BLAKE2b-256 8b9be4701e943475677f779dcd137fbc6d44a548db5ec0a7f7fc02b20772c6ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 d11149c7b186f224f2055e437a030cd83b164a43cc0211314c33ad1553ed9c4c
MD5 095ba6b023ee1775f14ad73cded77994
BLAKE2b-256 1f05bd467a2a52ffda5f91fa4b005cf00f6ffb894c4765cacddf28d086253aee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8cb380d2d6fdb60656a0b5fa78305535db513fc72ce11f4532cc1641204ef380
MD5 8fb2c84da25312912a53eb1e6111d10c
BLAKE2b-256 3a90d62c346f4b1dd0b0cf5d98938eb0f1c0269c04fafc9e886977415dccce3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 7545bb037823cd63dca19280f75a523a68bd3e78e003de74609320d6822b5a52
MD5 2c9e940baac7b549d13a0da77eff4b03
BLAKE2b-256 c0a5134a78af200780f29d0c4bf0769b49db9effa8b4839dd46bf261676427f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2c62a0bde4d20d087cabce2fa8b012d74c2e985da86d00fb3359880469b90e31
MD5 d9fda6e8cd1bf504c08dd2a12370cd6f
BLAKE2b-256 b9185edb529874143e84bb70693353cd0667c0dd729c57cbff250a1989c18726

See more details on using hashes here.

File details

Details for the file ruff-0.0.278-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.278-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 38ca1c0c8c1221fe64c0a66784c91501d09a8ed02a4dbfdc117c0ce32a81eefc
MD5 5af4627968ff13ba3c02d5619b8aaa2a
BLAKE2b-256 b66703d32d121f31037b47dc4edc3551809112f1112079b59bcf0d2b23bd7b73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.278-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1a90ebd8f2a554db1ee8d12b2f3aa575acbd310a02cd1a9295b3511a4874cf98
MD5 38052b0d9f3c2341ae8c2210e7154ce5
BLAKE2b-256 fd30ab354c4b68091373c3a9ff8fb8a51ce19c78576981e43cc1dcd4bf5b34b1

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