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/charliermarsh/ruff-pre-commit
  # Ruff version.
  rev: 'v0.0.269'
  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/charliermarsh/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/charliermarsh/ruff
    :alt: Ruff

...or, as HTML:

<a href="https://github.com/charliermarsh/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.269.tar.gz (680.9 kB 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.269-py3-none-win_arm64.whl (5.3 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.269-py3-none-win_amd64.whl (5.4 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

ruff-0.0.269-py3-none-musllinux_1_2_x86_64.whl (5.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.269-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.269-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.269-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.269-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.1 MB view details)

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

ruff-0.0.269-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.269.tar.gz.

File metadata

  • Download URL: ruff-0.0.269.tar.gz
  • Upload date:
  • Size: 680.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.269.tar.gz
Algorithm Hash digest
SHA256 11ddcfbab32cf5c420ea9dd5531170ace5a3e59c16d9251c7bd2581f7b16f602
MD5 914225233a2c98a042dc5f99a6500977
BLAKE2b-256 4a0477ad67155861ccf0deead144e4ba766b54c669c37aafc25d092a1a4f0af7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.269-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.269-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 bbeb857b1e508a4487bdb02ca1e6d41dd8d5ac5335a5246e25de8a3dff38c1ff
MD5 8daddabd401eca27cf604e39dd71d408
BLAKE2b-256 30ffe1e0ec0e4e31b3f163ef3e80456150a41a3b910cac04472a13248b812ce6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.269-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.269-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f3b59ccff57b21ef0967ea8021fd187ec14c528ec65507d8bcbe035912050776
MD5 4841c4aaf7efa08da0973c21e178bc08
BLAKE2b-256 9c381ce6bc423e9e86ed21e4cae62a0f67f08ddc8bfdadcd2c340e427fd3e9a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.269-py3-none-win32.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.269-py3-none-win32.whl
Algorithm Hash digest
SHA256 03ff42bc91ceca58e0f0f072cb3f9286a9208f609812753474e799a997cdad1a
MD5 fa25bddcfdd94a5716828a4d28fe120b
BLAKE2b-256 b99f692b03ed8f2065e4fd628d5f55ba68fe941cd23bd6f9afa4eddcba27316b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5a20658f0b97d207c7841c13d528f36d666bf445b00b01139f28a8ccb80093bb
MD5 55d7f413efede524406f9198104e02c8
BLAKE2b-256 3c4288f5242e41988bb83a37a04f16f3523c4b65b2133fa5e9d05ef276dd0b70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.269-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? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.269-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 9ca0a1ddb1d835b5f742db9711c6cf59f213a1ad0088cb1e924a005fd399e7d8
MD5 d485f6b120692f5ed75cc43138e0ed06
BLAKE2b-256 bf0b6415002df30de68a541f0fce1adb77d8160b5afb36edeea2e0c3fbf28192

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 374b161753a247904aec7a32d45e165302b76b6e83d22d099bf3ff7c232c888f
MD5 b0a2e0d755a329a9b626e93b315f1cf3
BLAKE2b-256 95190c3372acb612100e7417e394b85d98e3a73d80c6cc5a86d0253a40bc68ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cec2f4b84a14b87f1b121488649eb5b4eaa06467a2387373f750da74bdcb5679
MD5 8310cf18cf1f7f4eeadd66abf8e64110
BLAKE2b-256 26643e1fc0ccf7d59d7c45ec643541642cd3bcc95c36b5c2e01f9f9f908650c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a374434e588e06550df0f8dcb74777290f285678de991fda4e1063c367ab2eb2
MD5 ab79e57e3670236235bb0ec9dae84156
BLAKE2b-256 5b9367a13d30ae7d709774ab14b12ba6e90d3d8116a19afae1f0a5a818513ea1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 e131b4dbe798c391090c6407641d6ab12c0fa1bb952379dde45e5000e208dabb
MD5 2b59154fa3de965eb9dca2b338d8a845
BLAKE2b-256 f81790e1cb087a20e136da10b0187cf1bf25ac80da1c5fcb0256b683e6eee047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 3f5dc7aac52c58e82510217e3c7efd80765c134c097c2815d59e40face0d1fe6
MD5 d9e0afa290c88fb1a682da635ca3cdb3
BLAKE2b-256 2a22514380df775cac977caaa1394e2955c600e6f3895c0713e5f5aa99735d02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 f062059b8289a4fab7f6064601b811d447c2f9d3d432a17f689efe4d68988450
MD5 8e59a8d641fa8781a389c0dd5a73bd98
BLAKE2b-256 0265c49103428b27ef3831f6f8023a062de07d7a88d4d9d9f22cbf4941331b4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1f19f59ca3c28742955241fb452f3346241ddbd34e72ac5cb3d84fadebcf6bc8
MD5 736f504093a04a337fa528630485b639
BLAKE2b-256 18f128f24e47a8dfb72762056713fd66c2f6fd543d0f6d3858291cb3d4993c2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 bd81b8e681b9eaa6cf15484f3985bd8bd97c3d114e95bff3e8ea283bf8865062
MD5 fc156bb47fbf65272ee2aa0f8cf771d5
BLAKE2b-256 a9a4b555c6fb6880c64cd88e42e44c235770abf6263457ab493dac4ad123c427

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6da8ee25ef2f0cc6cc8e6e20942c1d44d25a36dce35070d7184655bc14f63f63
MD5 a740f51669c68d7c2f8130fa81e5538d
BLAKE2b-256 1d9760d69db70fa1e7e29a553fc6719ef6b750da0d570285f4c890ba686655f8

See more details on using hashes here.

File details

Details for the file ruff-0.0.269-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.269-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 56347da63757a56cbce7d4b3d6044ca4f1941cd1bbff3714f7554360c3361f83
MD5 db930583618a51f68b9af8cdf444d365
BLAKE2b-256 f60ceced078f3e0a4461b10dbf163160bd7a860378303a07253cbe8d1541fff4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.269-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 3569bcdee679045c09c0161fabc057599759c49219a08d9a4aad2cc3982ccba3
MD5 215656de53727c154ee6d6b07feb21b8
BLAKE2b-256 d47c1b8378f80962ff7d129a39785964710f92ebd9fa91e2444f00635ba3f510

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