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/astral-sh/ruff-pre-commit
  # Ruff version.
  rev: v0.0.275
  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/astral-sh/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/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/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.275.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.275-py3-none-win_arm64.whl (5.1 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.275-py3-none-win_amd64.whl (5.3 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.275-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.275-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.275-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.275-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.275.tar.gz.

File metadata

  • Download URL: ruff-0.0.275.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.275.tar.gz
Algorithm Hash digest
SHA256 a63a0b645da699ae5c758fce19188e901b3033ec54d862d93fcd042addf7f38d
MD5 1bec12a9632fe6228d45d908c052985f
BLAKE2b-256 2ae3d50caf74e65fbf46ff446929c17fb4d9da3c747817548af81a858f29edca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.275-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.275-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 a19ce3bea71023eee5f0f089dde4a4272d088d5ac0b675867e074983238ccc65
MD5 c505054b6f3649d3d72a5232e3fc67fc
BLAKE2b-256 affb2c9d1af4e54d77a9b510ec48fd13f0c40cc7c3b43d7ca261e0a2ac4c0b91

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.275-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 d9b264d78621bf7b698b6755d4913ab52c19bd28bee1a16001f954d64c1a1220
MD5 1deeafd9963c4e66869670a2dda830b5
BLAKE2b-256 cf6e6d5af3c16541ad4342d81e3e38eecb0593aa9da314686144796d2c0a1a48

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.275-py3-none-win32.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.275-py3-none-win32.whl
Algorithm Hash digest
SHA256 6afb1c4422f24f361e877937e2a44b3f8176774a476f5e33845ebfe887dd5ec2
MD5 ca36cd119e60928cc8d33900173bdb48
BLAKE2b-256 8730369db86b101f917ef32e5fedc2a3528ddfd9c258a903a072960e3a00c261

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 508b13f7ca37274cceaba4fb3ea5da6ca192356323d92acf39462337c33ad14e
MD5 86cf152bc3aac907e2722c1593bc9b17
BLAKE2b-256 f5f626955e33a3aad236b7e2774c13be1fe505f31bfc6071254fe0d22044cf26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.275-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? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for ruff-0.0.275-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ec43658c64bfda44fd84bbea9da8c7a3b34f65448192d1c4dd63e9f4e7abfdd4
MD5 89bbae255e8efbf7584e1e6896a03499
BLAKE2b-256 2b9b3ca65497a21371c276898a0e2e26c2fd1673bf59476bb1c9bea23983ff6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 8347fc16aa185aae275906c4ac5b770e00c896b6a0acd5ba521f158801911998
MD5 4bf259e0f399476f0532cd22bc608b26
BLAKE2b-256 21cf1b0a4d7f7700c6195f4a54406eb98b7a2f6b56c66a6f9ceeb5da345390bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c8ace4d40a57b5ea3c16555f25a6b16bc5d8b2779ae1912ce2633543d4e9b1da
MD5 fc7eabd3cd1e7fc57e5539bc878bc532
BLAKE2b-256 042741dc218102670ea7849dadf3bb0e7861105caac2e498171e1890dbfbf7b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5859ee543b01b7eb67835dfd505faa8bb7cc1550f0295c92c1401b45b42be399
MD5 d2028f6e3add7a3574cb95fd823ea585
BLAKE2b-256 e477f81ec6f3100f6d14638194e877a8928faa70a60b1d176f557642ee2c410d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 80043726662144876a381efaab88841c88e8df8baa69559f96b22d4fa216bef1
MD5 4968b595fdca624613f06ffdf8530931
BLAKE2b-256 3c7dce7293a3354d19a438cda962f88025a08bed108d3692b1a9631e035e46c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2c09662112cfa22d7467a19252a546291fd0eae4f423e52b75a7a2000a1894db
MD5 ce212a647d46588c415b7ffcf16f94ec
BLAKE2b-256 55cbaa2ca6cd503b5bb179e6d5f0e8d567fea63e09468c249ef42e8ffb1ecb40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 22efd9f41af27ef8fb9779462c46c35c89134d33e326c889971e10b2eaf50c63
MD5 9f4be86cc3f915f7f748485dcebed4fd
BLAKE2b-256 3612825b1cdbe5044b4ab92e5e25f60650a7bc726a8acc5df1a3d13b9c443d8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0dbdea02942131dbc15dd45f431d152224f15e1dd1859fcd0c0487b658f60f1a
MD5 1393ed29acbf7e4d9a298fd0e04d213b
BLAKE2b-256 3888fb7fe795721d7af456789db6d2a4eb53b70d59213c3df1cfbafd265199a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0c4e6468da26f77b90cae35319d310999f471a8c352998e9b39937a23750149e
MD5 6b9878514f0b94b831abca34ff864826
BLAKE2b-256 43f1bf25f0b5f426b25006241985d0c407a156f3e56d876a2eed1be076107c21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5206fc1cd8c1c1deadd2e6360c0dbcd690f1c845da588ca9d32e4a764a402c60
MD5 4d7da048ac68555c3cc61dc9bab650b8
BLAKE2b-256 d73368753ff8b0981edd0978daaf0bff874b8c369e26bf2da06512a17ab9a581

See more details on using hashes here.

File details

Details for the file ruff-0.0.275-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.275-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1cc599022fe5ffb143a965b8d659eb64161ab8ab4433d208777eab018a1aab67
MD5 f693050bfd2f777079b8cd16535f3ffe
BLAKE2b-256 3dd634859533f225fe0a312d7565782c52773f0ac4d721c3519abde2c9250b8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.275-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 5e6554a072e7ce81eb6f0bec1cebd3dcb0e358652c0f4900d7d630d61691e914
MD5 2ac989a97f1cf6e7594e9f3c1148450b
BLAKE2b-256 0eae9960d8cc311eafb6e0d7ac7b775ee739d1f1361d3e5fea1ba49e61e7e424

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