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.264'
  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",
    ".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:

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.264.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.264-py3-none-win_arm64.whl (5.3 MB view details)

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

ruff-0.0.264-py3-none-win32.whl (5.1 MB view details)

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.264-py3-none-musllinux_1_2_i686.whl (5.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.264-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.264-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.264-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.264-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.264-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.264.tar.gz.

File metadata

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

File hashes

Hashes for ruff-0.0.264.tar.gz
Algorithm Hash digest
SHA256 8fcd4b693ca1374eb7a5796581c90689f884f98f388740d94f0702fd30f8f78f
MD5 3cd6f11f949c1c69d06840143e4a26ab
BLAKE2b-256 c6063ed1d46e1e2a71d5b88b0087a994642730e5c1396425dd31d017463e0614

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.264-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.264-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 3e2c38449548e122f2612843a7c04e22b4fd491656955c57b8cb05df11639ad6
MD5 fbd896a31c0bb07fa2f7be7dcb10325d
BLAKE2b-256 6a189809f9c1008a9f0cf1cbfc400b46649f1631eebe4dc6f9421f7178c361f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.264-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.5 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.264-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 068a82a29d80848a56e3d9d4308e6e0ca8b2ecdaf5ac342a292545a59b7f2c21
MD5 7c771a2641e13a75527599df678c1601
BLAKE2b-256 c2a97c1b194946f1460ffbf26d9d25649c6ec4119982552936b3ce4425b7cae7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.264-py3-none-win32.whl
  • Upload date:
  • Size: 5.1 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.264-py3-none-win32.whl
Algorithm Hash digest
SHA256 5a8658ebcc37d62f72840cbdf564171c1a2b6831db482b4d917962541a2f4a44
MD5 b0bc9c3519f7b67d21248645275076f6
BLAKE2b-256 1e0e375fde351cb0531470ad6b437cb1bbb6ce83cb0f6e01d0fd68680e3cfeff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 67326fdc9ac0a1b13e229c6e24e8d115863c52cd710faaaaa588851535281d6c
MD5 733296d6d8da202b5dd1a1e6cb2dd750
BLAKE2b-256 b295bb0befe3eb5fc7ae4bfde2f4162323bf55136a106fd0685378c35a89e1bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 484e395d1984ab9e1e66bd42e7a5192decfee86998d07d36ee50b2fadccc8734
MD5 185045b8222b97168e025d1c030061c6
BLAKE2b-256 64a90ab814985bc90c19e7ac8ba53406c8f2f535739fff3a749e83a0573420ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 05ee163a046fc593d150179d23f4af447fb82f3e59cd34e031ea0868c65bb8e8
MD5 afa5aa3a06bedc07cf673098a5b00e23
BLAKE2b-256 fb602f4f5170c58d70e4600d71c91e76b83a25ec31dfd2eb939e0805c1bbe6d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cd4f60ffc3eb15802c554a9c8581bf2117c4d3d06fbc57e0ba58f04cb1aaa47f
MD5 9e14a6bc40a09a01ec34522483e721bc
BLAKE2b-256 3184b47957fa69018359dfbc350e28404a78f20a6cf213b580eff737784e3389

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71fd865ebacc1083259b3fb7e3eb45235a86e62e21830b8a6b067be0ec54aa2e
MD5 0dad1468a5379b9e875e77f4de626075
BLAKE2b-256 37f1c4023c9dc501d7e49fe939fd86a287c02cf044be6f6cece359218c2ea025

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 04ec5d75e4bca754cedd20d53e2ba4920d6259e7579abfb2e8e30c3c80e41b17
MD5 6c7a9d7b867b3436731c1eb439580068
BLAKE2b-256 57ebec0dd02cfd07b7f725d5ba18edcbe1f1228b89d650eb72f50049c75f1df2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 91c6eb4f979b661a2dd850d9ac803842bb7b66d4926de84f09c787af82590f73
MD5 61ee096d317477e248dd0845986b1c8e
BLAKE2b-256 376f4aeda64a401beecf560381961efd8a01d6d53d1e095b084b77f31e410dca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 d628de91e2be7a83128526636097d2dd890669a06143f826f6c591d79aeefbc4
MD5 a0d6fd3670945ef7c973d958e0a2607c
BLAKE2b-256 23dc51ee0cd6d2c3c8e0ddc6531c7a8909c5df5f5f21d091854e9ff4293a7466

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 18a29ed37bf8cfe6dce8a2db56c313a64c0804095108753621f3c3321e0c9c5f
MD5 83c0303ab8d7b21665a1c5cbe1bf184f
BLAKE2b-256 8ae03cc67b6f9b9f20c04f1237a6192b19343309d3c2605930ea2472eb2f81fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 323ae6c1702b26c96d0fbf939c5959c37e79021f86b70f63634df918bc77f36e
MD5 9c77f8438f9e11004866dae2305fc5f4
BLAKE2b-256 78406a33d40d0bd48adce97775ed68b06922c95dba8076bb6db7ab320f6b9002

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4564e0f245eb515c6ed63988c21e9c40bcfd485cd1ec63bdd790f9a81d301f15
MD5 31016bf702f622c412ada6aa43880301
BLAKE2b-256 681df6fbf3b023b0c86c372ebe31907e18a3fc22ee3f6e00ea534e530aa48466

See more details on using hashes here.

File details

Details for the file ruff-0.0.264-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.264-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d97ba8db0fb601ffe9ee996ebb97c698e427a2fd4514fefbe7b803111354f783
MD5 32736286b3092e34dcc40921f8fae3d8
BLAKE2b-256 a3822cb89c8afffb03201cbdd19529ed5b3338705d5c6fb2b76830d3d1955f17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.264-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ec2fa192c035b8b68cc2b91049c561cd69543e2b8c4d157d9aa7727320bedcca
MD5 d5f01ce90d6ed2d478d2b2a5fceccce4
BLAKE2b-256 beb3bcf54b0ddf6e0e75ebe7fbe3bb1c7786647f1aac3ed60e128863129b3b4a

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