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.4
  hooks:
    # Run the Ruff linter.
    - id: ruff
    # Run the Ruff 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",
    ".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
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

This version

0.1.4

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.4.tar.gz (1.7 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.4-py3-none-win_arm64.whl (5.9 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.1.4-py3-none-win_amd64.whl (6.2 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.1.4-py3-none-win32.whl (5.8 MB view details)

Uploaded Python 3Windows x86

ruff-0.1.4-py3-none-musllinux_1_2_x86_64.whl (6.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.1.4-py3-none-musllinux_1_2_i686.whl (5.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.1.4-py3-none-musllinux_1_2_armv7l.whl (5.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.1.4-py3-none-musllinux_1_2_aarch64.whl (5.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.1.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (6.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (6.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.1.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (11.6 MB view details)

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

ruff-0.1.4-py3-none-macosx_10_7_x86_64.whl (6.0 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.4.tar.gz
Algorithm Hash digest
SHA256 21520ecca4cc555162068d87c747b8f95e1e95f8ecfcbbe59e8dd00710586315
MD5 5eb0f6198cd2d03d21cbe0ac5dc87bef
BLAKE2b-256 c27230b2da619c1ace5a8f3d98a640089ee8f6107e4b4b91a3dea95a18a3bcf7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.4-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 d98ae9ebf56444e18a3e3652b3383204748f73e247dea6caaf8b52d37e6b32da
MD5 e308c6032f8871f12c8a2fa1c3944fef
BLAKE2b-256 5bde526ff258f3c3376f9db83ffe75a96e0c04ff057744655de7f86ef1d1a875

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1dfd6bf8f6ad0a4ac99333f437e0ec168989adc5d837ecd38ddb2cc4a2e3db8a
MD5 3601ea8e7ab475ab5a40d3b72a79d8dd
BLAKE2b-256 a663fb646f0594c5570523aad588b881044376afe05f1a92b9c6b79ab8a221d1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.4-py3-none-win32.whl
Algorithm Hash digest
SHA256 99908ca2b3b85bffe7e1414275d004917d1e0dfc99d497ccd2ecd19ad115fd0d
MD5 b674e7a320aaccade6273c32b473922a
BLAKE2b-256 2eec09947e9c99478006134151137bd906e67e0ac4227a3b9fda7b752b92da47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.4-py3-none-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: Python 3, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.4-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 645591a613a42cb7e5c2b667cbefd3877b21e0252b59272ba7212c3d35a5819f
MD5 3afd06b18ff3f09bb43599ab6cdb39bd
BLAKE2b-256 8193b2ff060d0f83b4a7ad8ae9e0f36370f9eef8a1bcccdabeea869a3a335650

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.4-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 01206e361021426e3c1b7fba06ddcb20dbc5037d64f6841e5f2b21084dc51800
MD5 92e1e8504b8d63ebe0ab6450bfcb5cd8
BLAKE2b-256 c1f8212e8b5c9bb363b33f2e7e282ff49f75257d4a47b81ae3918ac5be6b5ef3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.4-py3-none-musllinux_1_2_armv7l.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: Python 3, musllinux: musl 1.2+ ARMv7l
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.4-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 e8791482d508bd0b36c76481ad3117987301b86072158bdb69d796503e1c84a8
MD5 6042bf63188746e93bddd2e1d421ab4c
BLAKE2b-256 54681ec92399c0444163743931f409fdee772c8ba3f6a601a9594f7fd70e4121

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fdfd453fc91d9d86d6aaa33b1bafa69d114cf7421057868f0b79104079d3e66e
MD5 c99356140eb8a78f793882fbcf9bf20d
BLAKE2b-256 043edf4c5cec0b2e0ddf536e04d25af72099beff337c5f70b5bf18e484fa0c6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58826efb8b3efbb59bb306f4b19640b7e366967a31c049d49311d9eb3a4c60cb
MD5 3cea71757c70aaad2ff36b8441d991fe
BLAKE2b-256 88b21336e13be28fb759aa1079f466e45369ddf075255d3fdb92e6a5fea452e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 9862811b403063765b03e716dac0fda8fdbe78b675cd947ed5873506448acea4
MD5 2d0eb4b5da39df861949f2af8bf977b3
BLAKE2b-256 03126e3f796a574099921d2d0962a2c5b24b17ca6cf6c58075985a5d8e16dcbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 6bc02a480d4bfffd163a723698da15d1a9aec2fced4c06f2a753f87f4ce6969c
MD5 8128e7ecf82473eaed3b7763c65cb16e
BLAKE2b-256 61d7e52b9fa935aad9df5abf11df67c7d53385d7b77f6731a240a160efbc4f56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 80fea754eaae06335784b8ea053d6eb8e9aac75359ebddd6fee0858e87c8d510
MD5 263efd981dc1d5ee2a9d61eac01ac85c
BLAKE2b-256 7f7ee9b8fc2927eb25bc37f1be98691f4a493d467ac6e8189eb209407edc741e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 78e8db8ab6f100f02e28b3d713270c857d370b8d61871d5c7d1702ae411df683
MD5 b13a7be2da45e25e7abe08eb7972f3e6
BLAKE2b-256 73d61a5e3a846f6b24137c98a76897c68f2d938edc996ab420635e149d84d75b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a9a1301dc43cbf633fb603242bccd0aaa34834750a14a4c1817e2e5c8d60de17
MD5 c3d36754a549a53e61e53901dac5239c
BLAKE2b-256 16e05787e5865f9f05c72e67853feb899c2c45da47287a24c67c56a8f0888a1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b4eaca8c9cc39aa7f0f0d7b8fe24ecb51232d1bb620fc4441a61161be4a17539
MD5 9c1d5679c5a81664104fdcdb2cc8d623
BLAKE2b-256 fd056886a65d6f5241b3286c8b92fd92de8232c9e1a4404d56c06b434d181ac9

See more details on using hashes here.

File details

Details for the file ruff-0.1.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for ruff-0.1.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9fdd61883bb34317c788af87f4cd75dfee3a73f5ded714b77ba928e418d6e39e
MD5 7c7e5058416e815860e79a70af8cdb45
BLAKE2b-256 2712ae89a1015b2f2e41ea31598fa690f0f965b78ab4806c71828259671ea940

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.4-py3-none-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: Python 3, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ruff-0.1.4-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 864958706b669cce31d629902175138ad8a069d99ca53514611521f532d91495
MD5 87fd0a989f6beeb2fac0f017f29acad6
BLAKE2b-256 b3aa14a0097f4ffd9f2438ea9831f894828539113496aa01c71bcd6084691326

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