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.13 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 800 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.4.10
  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@v4
      - 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 the following ruff.toml file:

# 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"

[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]+?))$"

[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"

Note that, in a pyproject.toml, each section header should be prefixed with tool.ruff. For example, [lint] should be replaced with [tool.ruff.lint].

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

ruff check --select F401 --select F403 --quiet

The remaining configuration options can be provided through a catch-all --config argument:

ruff check --config "lint.per-file-ignores = {'some_file.py' = ['F841']}"

To opt in to the latest lint rules, formatter style changes, interface updates, and more, enable preview mode by setting preview = true in your configuration file or passing --preview on the command line. Preview mode enables a collection of unstable features that may change prior to stabilization.

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 800 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 your 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

This repository is licensed under the MIT License

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.4.10.tar.gz (2.6 MB view details)

Uploaded Source

Built Distributions

ruff-0.4.10-py3-none-win_arm64.whl (7.9 MB view details)

Uploaded Python 3 Windows ARM64

ruff-0.4.10-py3-none-win_amd64.whl (8.5 MB view details)

Uploaded Python 3 Windows x86-64

ruff-0.4.10-py3-none-win32.whl (7.7 MB view details)

Uploaded Python 3 Windows x86

ruff-0.4.10-py3-none-musllinux_1_2_x86_64.whl (10.1 MB view details)

Uploaded Python 3 musllinux: musl 1.2+ x86-64

ruff-0.4.10-py3-none-musllinux_1_2_i686.whl (9.6 MB view details)

Uploaded Python 3 musllinux: musl 1.2+ i686

ruff-0.4.10-py3-none-musllinux_1_2_armv7l.whl (9.3 MB view details)

Uploaded Python 3 musllinux: musl 1.2+ ARMv7l

ruff-0.4.10-py3-none-musllinux_1_2_aarch64.whl (9.8 MB view details)

Uploaded Python 3 musllinux: musl 1.2+ ARM64

ruff-0.4.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ x86-64

ruff-0.4.10-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (11.2 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ s390x

ruff-0.4.10-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (10.3 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ppc64le

ruff-0.4.10-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (10.7 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ppc64

ruff-0.4.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (10.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ i686

ruff-0.4.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (9.2 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

ruff-0.4.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.9 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

ruff-0.4.10-py3-none-macosx_11_0_arm64.whl (8.1 MB view details)

Uploaded Python 3 macOS 11.0+ ARM64

ruff-0.4.10-py3-none-macosx_10_12_x86_64.whl (8.5 MB view details)

Uploaded Python 3 macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.4.10.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for ruff-0.4.10.tar.gz
Algorithm Hash digest
SHA256 3aa4f2bc388a30d346c56524f7cacca85945ba124945fe489952aadb6b5cd804
MD5 69de10b8ca75b81cb55bf46a0f92432e
BLAKE2b-256 ea04b660bc832ebfa40e1788edf6934388340751cbc6f733d1f807edca9d96e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.4.10-py3-none-win_arm64.whl
  • Upload date:
  • Size: 7.9 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for ruff-0.4.10-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 dd1fcee327c20addac7916ca4e2653fbbf2e8388d8a6477ce5b4e986b68ae6c0
MD5 0bc31a1d412b8143b4d644238f58538e
BLAKE2b-256 dc785109b7db3b44a64157b025e45eec6591e4beb53732104637d8e0ee0c5570

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.4.10-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 67f67cef43c55ffc8cc59e8e0b97e9e60b4837c8f21e8ab5ffd5d66e196e25f7
MD5 e8fe6fb96f019b1fa5c1a8273a0b342e
BLAKE2b-256 d84e6fd32ebd0a09f25ed9911b77c5273b7a6b3b50a78d6ed0508d66a24398b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.4.10-py3-none-win32.whl
  • Upload date:
  • Size: 7.7 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for ruff-0.4.10-py3-none-win32.whl
Algorithm Hash digest
SHA256 ffe3cd2f89cb54561c62e5fa20e8f182c0a444934bf430515a4b422f1ab7b7ca
MD5 edf5177155d09cd3764ee119633cb96c
BLAKE2b-256 e8943bb62a0086e9c61d0506e546e7cf68456fd93bf569a8adfa5e324812970d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 338a64ef0748f8c3a80d7f05785930f7965d71ca260904a9321d13be24b79695
MD5 9f93294df27cd8908088c505ba6d1d5a
BLAKE2b-256 d39e11ae4e8587efe40aa083835665d0818626f8f4a10aa4ebc097cdbfae7624

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 3cea07079962b2941244191569cf3a05541477286f5cafea638cd3aa94b56815
MD5 2c156d3947f30e0ab5793c371d8da099
BLAKE2b-256 f009f3c6560f9d81a4c5d800996090c9cc54d794ea14ab8f8af46b7483005963

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 acfaaab59543382085f9eb51f8e87bac26bf96b164839955f244d07125a982ef
MD5 17646b93e4556986958221e2e1dd88a9
BLAKE2b-256 cf13bc788b2e21d3e4db74d1375da22f50f944bc1fef064c4749f307b0c8794f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 67fe086b433b965c22de0b4259ddfe6fa541c95bf418499bedb9ad5fb8d1c631
MD5 768b2211e97a2f7dd40682407503ce6d
BLAKE2b-256 d0e6734aed23112de8df5a2f3bc02e9e45cd3910fe83b0d2bb2456e200c52d98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f54c481b39a762d48f64d97351048e842861c6662d63ec599f67d515cb417f6
MD5 c24dcecb51bf169afe55608fa2022b11
BLAKE2b-256 11c33f89b1e967a869642bd9198f27e2b89b8300862555d3e1e39b4ccaf92e8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 9e9b6fb3a37b772628415b00c4fc892f97954275394ed611056a4b8a2631365e
MD5 af3c7bea03d137285d6b2b78a61aab51
BLAKE2b-256 48dc2c057e7717a3eaaa89ea848a26ef085930a2509f9b66ceae55319668c03d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 330421543bd3222cdfec481e8ff3460e8702ed1e58b494cf9d9e4bf90db52b9d
MD5 91572b3a0eaff7a8fff5536a0a801479
BLAKE2b-256 b8c15373bc5a4c3782c0a368ce5ca4ec3a689574daf71f68f55720a6a64321d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 d8f71885bce242da344989cae08e263de29752f094233f932d4f5cfb4ef36a81
MD5 7dd7f3886d772fcc7f687ad692fca4ed
BLAKE2b-256 eca41310b3d003cb67f3c86cb8cc5c5e475dab152b1eef88558abd11e55daaad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 18238c80ee3d9100d3535d8eb15a59c4a0753b45cc55f8bf38f38d6a597b9739
MD5 ac510930b2c2f636e2de042aa21f0071
BLAKE2b-256 e79dbad51d81c918e1ce1648b24480a63f5605662efe69b55fad05825b5711ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 c75c53bb79d71310dc79fb69eb4902fba804a81f374bc86a9b117a8d077a1784
MD5 eb7e219a36d35ae5be8857d06be23dbb
BLAKE2b-256 c738070baf0393ba0da9d85409bdd63874776926acfc372e8e9f0ed21957aeee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b1dd1681dfa90a41b8376a61af05cc4dc5ff32c8f14f5fe20dba9ff5deb80cd6
MD5 c5daa0cee64b01f3e35e933c62540722
BLAKE2b-256 786f37af054d3ced5a6196201f6c248eeaec6b3b844136cf3da510d591dbfd89

See more details on using hashes here.

File details

Details for the file ruff-0.4.10-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a79489607d1495685cdd911a323a35871abfb7a95d4f98fc6f85e799227ac46e
MD5 6ef0efd5404692d8e90bab7b1cd843c7
BLAKE2b-256 465e4ac799ffec39ef5012052c1f144a0f7a63a0322ebd328b802d64beb3d091

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.4.10-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c2c4d0859305ac5a16310eec40e4e9a9dec5dcdfbe92697acd99624e8638dac
MD5 96262371ff6ab8900d18695b0065463d
BLAKE2b-256 530d134fdd72f566d37b0c59b6e55f60993c705f93a0fe3c1faa6f8a269057c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page