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.276
  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 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/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.276.tar.gz (1.1 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.276-py3-none-win_arm64.whl (5.2 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.0.276-py3-none-win_amd64.whl (5.4 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.276-py3-none-musllinux_1_2_armv7l.whl (4.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.276-py3-none-musllinux_1_2_aarch64.whl (5.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.276-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.276-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.276-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (5.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.276-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

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

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.276-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.276-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.276-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.2 MB view details)

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

ruff-0.0.276-py3-none-macosx_10_7_x86_64.whl (5.3 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.0.276.tar.gz
  • Upload date:
  • Size: 1.1 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.276.tar.gz
Algorithm Hash digest
SHA256 d456c86eb6ce9225507f24fcc7bf72fa031bb7cc750023310e62889bf4ad4b6a
MD5 41237e87afbe5c19a23a9c94dd0e8d24
BLAKE2b-256 f79be8c42f8e0bb21a2d82b8f414c55fbf498cdfe72922bf73c973267477fd46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.276-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.2 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.276-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 a6bd5b53ac689a43c7afc45bd574a7b3efe0ceb192e26e95a055c770ef2045b9
MD5 c6c294d008a68dfaa35a6e277a807b2e
BLAKE2b-256 57d705c02355d86749a60d4ef48076d8bc44caaa986e15f9d9ab7e5f28382f4c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.276-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.4 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.276-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 02deadc0f6abead6cc2d38ddd7100a52aba27a0d90315facaa44b8b4acdba162
MD5 f8b011f181bd52ea48ba416926de03df
BLAKE2b-256 4316e3e6512ae66519d62439509e8f2007568e94fad8b88d99e2de3e4cbeda12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.276-py3-none-win32.whl
  • Upload date:
  • Size: 5.1 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.276-py3-none-win32.whl
Algorithm Hash digest
SHA256 1b34a3673b2e5d97df8f7f04090c0b74e9ae6d3d172921d0e0781192954afddf
MD5 b6115c114c46489d846b6166adb588ec
BLAKE2b-256 b683b23e081f0151238ffcb3c68c87678c807e76cf5ef4efe60c683f137edda2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 100ad9055d50977c2b4ab3de0db62d6e525bcd4aafbb660a842733bdbf650be9
MD5 ca35733881c7498a56685065abb72879
BLAKE2b-256 fb4bb200d0bdaa7a30fae00ec8c6152389709abe2f9cf574b2af8917e4df1f90

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.276-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 5.2 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.276-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 735d724031212c2ab63fafdea49d4581ae866a1180d06c29b0b5481228ca6bb9
MD5 e4315c8d1b864d4c1c9408a7f3e7973c
BLAKE2b-256 0a3a1858fee2531ddeae4fc3170fde322746eed86c1173216ed1fb03874e7b08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 6ed8fc729b3e7b9f20a4e2aa6f24c798b06912f8a94cb3e8fd590eba055780df
MD5 35938aa5cb114567b5aeccd88d0cfbb4
BLAKE2b-256 c31b4c42b15326d1488de6560606370977d4a0672627b46bdf4090ca614ce4c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 12be4f007114cf5ed1242e522762651539521ec32ae0210cc4b8dfe434a872f0
MD5 d1678cd2479cec0d72eeb7e528aacc23
BLAKE2b-256 0e1aa0096a84e15fe142297522fb787bf93201cdc8eb6faa762eb9976f3c7a9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5980960a748ada3ddfe4ea7ff3a01b9113c456a14cb1a39b4c30783012d4cba6
MD5 3461014c510aba13d8c9ef295a1019e7
BLAKE2b-256 2a3196888bb7b755a2825347ffba6f787a2526a5aa4f2757dcec7f6d49b9fb10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 57c49b525d8ca3838d8b614f42e342077bed95aedd9fe6e6ec419f39320c214e
MD5 10c65fcc95c6e388f4b6a27014753165
BLAKE2b-256 cb4965676eb84163e3c723a87cc0a0cfea48ee18508ba0ae9af1e6d9c798202e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2edcd6948a21fa7fb4594094da37a1aa1d205b7abaa718bd27d48ba1d7977348
MD5 b5994ae513b54b7afcca937acfd2a8f6
BLAKE2b-256 dd8eff5c37217bd73f2d92bd224396cd47ec0460c9616587f003d731bf875a1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 d070a64de4affd17e006d6986ef25601dbbc6b373844ece5396c33900f8b8563
MD5 6251e51e7310ddfd0c82791b24458c22
BLAKE2b-256 2798def68af3fe67f7d8a3c359ea4a1ae0ab0c815a381677e9ead65510d50a0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4ac65df96be3e2f4b10bc97bbb624152281611b06ef1068d5bb064b7ad35d800
MD5 73376596df96429aa3e3cc188ce8c891
BLAKE2b-256 d9fd4b308e03e745261127470ff4c45bf6626869eaa9c80c04d1907f0997c961

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 13e5983836ae383c04de213954da731f14ea884aaf74467abc47e1d79d8cf1b7
MD5 83acd01690fc42db418c4b38301fcbef
BLAKE2b-256 b2327d01f556748889dc201cd79bfef1dee483d52bda1cbf88089ec7d08bb7c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fc7dc557cc3fa2a03a88e99425ceee91429cc7432e5a41087850c1629294faed
MD5 93676ccaa4eb25fc78f555c1ca394d25
BLAKE2b-256 84d7f5a2f027b01b3066f6d2ebddbb23c73413904cc70055add18eb412f29e61

See more details on using hashes here.

File details

Details for the file ruff-0.0.276-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.276-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 5e9cd7238d34f24d7ccfadcce4dc6807b8c5a390f547dd7236d06488d9d6f40f
MD5 9373198e46ca91cb0f154d7c7574369a
BLAKE2b-256 0805d63b242a569bbcc6e46a59b4029026a21705d07f58b455518d0acbc52227

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.276-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c150912b8ebde843c10b33db90705d4fee48db6f05441e5d143be9f4c2f35df5
MD5 78636e90836b63f4b2607aa5069af94a
BLAKE2b-256 b6c073e9fbb3bf5da85e334a3c5217a64b6b48310ccc5640584ce66b5cc4bfac

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