Skip to main content

An extremely fast Python linter and code formatter, written in Rust.

Project description

Ruff

Ruff image image image Actions status

Discord | Docs | Playground

An extremely fast Python linter and code formatter, written in Rust.

Shows a bar chart with benchmark results.

Linting the CPython codebase from scratch.

  • ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)
  • 🐍 Installable via pip
  • 🛠️ pyproject.toml support
  • 🤝 Python 3.12 compatibility
  • ⚖️ Drop-in parity with Flake8, isort, and Black
  • 📦 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, with native re-implementations of popular 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), Black, isort, pydocstyle, pyupgrade, autoflake, and more, 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 as a linter, 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 check @arguments.txt           # Lint using an input file, treating its contents as newline-delimited command-line arguments.

Or, to run Ruff as a formatter:

ruff format .                        # Format all files in the current directory (and any subdirectories).
ruff format path/to/code/            # Format all files in `/path/to/code` (and any subdirectories).
ruff format path/to/code/*.py        # Format all `.py` files in `/path/to/code`.
ruff format path/to/code/to/file.py  # Format `file.py`.
ruff format @arguments.txt           # Format using an input file, treating its contents as newline-delimited command-line arguments.

Ruff can also be used as a pre-commit hook via ruff-pre-commit:

- repo: https://github.com/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.1.13
  hooks:
    # Run the linter.
    - id: ruff
      args: [ --fix ]
    # Run the formatter.
    - id: ruff-format

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, Ruff's default configuration is equivalent to:

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".ipynb_checkpoints",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pyenv",
    ".pytest_cache",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    ".vscode",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "venv",
]

# Same as Black.
line-length = 88
indent-width = 4

# Assume Python 3.8
target-version = "py38"

[tool.ruff.lint]
# 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 = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

Some configuration options can be provided via the command-line, such as those related to rule enablement and disablement, file discovery, and logging level:

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 and ruff help format for more on the linting and formatting commands, respectively.

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 ruff format or 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 formatter 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.13.tar.gz (1.9 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.13-py3-none-win_arm64.whl (7.0 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.1.13-py3-none-win_amd64.whl (7.2 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.1.13-py3-none-win32.whl (6.6 MB view details)

Uploaded Python 3Windows x86

ruff-0.1.13-py3-none-musllinux_1_2_x86_64.whl (7.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.1.13-py3-none-musllinux_1_2_i686.whl (7.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.1.13-py3-none-musllinux_1_2_armv7l.whl (6.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.1.13-py3-none-musllinux_1_2_aarch64.whl (7.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.1.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.1.13-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (8.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.1.13-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (7.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.1.13-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (8.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.1.13-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (7.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.1.13-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.1.13-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.1.13-py3-none-macosx_10_12_x86_64.whl (7.3 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

ruff-0.1.13-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (14.2 MB view details)

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

File details

Details for the file ruff-0.1.13.tar.gz.

File metadata

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

File hashes

Hashes for ruff-0.1.13.tar.gz
Algorithm Hash digest
SHA256 e261f1baed6291f434ffb1d5c6bd8051d1c2a26958072d38dfbec39b3dda7352
MD5 61463f8d5dda339dddfb9fec8c732e87
BLAKE2b-256 b2abe178659aa6ab71b230f1a9d134b94b137e57db5512822150afb6dea1b557

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.13-py3-none-win_arm64.whl
  • Upload date:
  • Size: 7.0 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.13-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 6bbbc3042075871ec17f28864808540a26f0f79a4478c357d3e3d2284e832998
MD5 f5520c530953d73f16e1f054640c9aa1
BLAKE2b-256 9a546ef6d55555bfffecb1870a46fa62c74ee900e22e505b24a8a08f7a5b812b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.13-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f988746e3c3982bea7f824c8fa318ce7f538c4dfefec99cd09c8770bd33e6539
MD5 4806fb270de3864407b050471f302386
BLAKE2b-256 a393c04251f638553f023ea2ee7384efa65a0a9080080a820beb6b7a7e66599e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.13-py3-none-win32.whl
Algorithm Hash digest
SHA256 a623349a505ff768dad6bd57087e2461be8db58305ebd5577bd0e98631f9ae69
MD5 91b8a2c20bfe6ff7aaeef19bbfa054b0
BLAKE2b-256 df2e283cd50b9605fe765b77df22fd3a0be19689b00030e7609338ab50f8b603

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7a36fa90eb12208272a858475ec43ac811ac37e91ef868759770b71bdabe27b6
MD5 d698cc590da470d198b6ac506f539aed
BLAKE2b-256 8c18cf5732c19de9e87c7e6bf2c70db2e3c39cd022b2c3614e8df432cd499a81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.13-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: Python 3, musllinux: musl 1.2+ i686
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for ruff-0.1.13-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f57de973de4edef3ad3044d6a50c02ad9fc2dff0d88587f25f1a48e3f72edf5e
MD5 3b8053a9d6ff62169b7ff3528c7ae110
BLAKE2b-256 bb33a63195d2e4972fdeb7e5576b795bf0251a23d281bbd12db2686e171bfff7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 dcaab50e278ff497ee4d1fe69b29ca0a9a47cd954bb17963628fa417933c6eb1
MD5 270e50f152e38d33d597caba7dba5f24
BLAKE2b-256 73549476fa803f4d4ca1f758128025a4bfb9ed9ff3223044fcfab8adb3d2f345

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ee3febce7863e231a467f90e681d3d89210b900d49ce88723ce052c8761be8c7
MD5 8673c0b4814cd3398adf3448aac40f3a
BLAKE2b-256 e89b57ce6dfbcacd82d66ded19a80d2b595f9a75df1a185a169cf97ec109330d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a1600942485c6e66119da294c6294856b5c86fd6df591ce293e4a4cc8e72989
MD5 6f558525f7ca057edd2193a1664139b3
BLAKE2b-256 e4a4afec3423ecb1dfb134f95060c41fd3c9f30d122234660fd20652027a9fa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 e6894b00495e00c27b6ba61af1fc666f17de6140345e5ef27dd6e08fb987259d
MD5 3b52631663e77c53f4edc80a4e4b1e6e
BLAKE2b-256 263b99d3a67e377e86c48660a73416711d0f1390e47444d54cc103db3c8de409

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2f59bcf5217c661254bd6bc42d65a6fd1a8b80c48763cb5c2293295babd945dd
MD5 aad0f3d9f0fd5fcb8fa992deceb4736e
BLAKE2b-256 84df1e6f44ec3ac0dd0ab40788387b3e230b9e0450c0ca6bf29b0580e2f2d806

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 5f0312ba1061e9b8c724e9a702d3c8621e3c6e6c2c9bd862550ab2951ac75c16
MD5 023a2b57f9defe28811f08102854cf10
BLAKE2b-256 c005150fda0258e363eb9a3473216f05f2af6855e1164f7782bac9da46526128

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 226b517f42d59a543d6383cfe03cccf0091e3e0ed1b856c6824be03d2a75d3b6
MD5 f278b7fb1391b6007dbb45f23f2d97a4
BLAKE2b-256 cec80a8e26b64a5bbf6ae4d297b4b6b97949614ce799ea28f4621ccd05c266cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 9ebb40442f7b531e136d334ef0851412410061e65d61ca8ce90d894a094feb22
MD5 9db651ba2d6cfd886f857378bf1f7515
BLAKE2b-256 ef62ba7510290912b600b919a8a476505270064467474631da05890623d183b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b13ba5d7156daaf3fd08b6b993360a96060500aca7e307d95ecbc5bb47a69296
MD5 346327891116345faa704ef89d5bd5bd
BLAKE2b-256 141185823f21d1dd7beec2a684593bc4e771f677c5baec8d8c4fbb318110fdb2

See more details on using hashes here.

File details

Details for the file ruff-0.1.13-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9fb6b3b86450d4ec6a6732f9f60c4406061b6851c4b29f944f8c9d91c3611c7a
MD5 a276c9c94843a26ccd8f1601d2674fb4
BLAKE2b-256 8deb434446d79e265faf886a0bb6f3578552571861ddefd0f72585c3c8f80850

See more details on using hashes here.

File details

Details for the file ruff-0.1.13-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for ruff-0.1.13-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e3fd36e0d48aeac672aa850045e784673449ce619afc12823ea7868fcc41d8ba
MD5 4b90237eb042ee82dc7e69267a6d5cfe
BLAKE2b-256 3623f440bd8ca4b3a3c315bf3e840145ec813547ef754a14f905d0b9c2a0caaf

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