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.

Read the launch blog post or the most recent project update.

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/charliermarsh/ruff-pre-commit
  # Ruff version.
  rev: 'v0.0.261'
  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",
    ".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 in a number of major open-source projects, including:

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.261.tar.gz (854.8 kB 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.261-py3-none-win_arm64.whl (5.1 MB view details)

Uploaded Python 3Windows ARM64

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

Uploaded Python 3Windows x86-64

ruff-0.0.261-py3-none-win32.whl (4.9 MB view details)

Uploaded Python 3Windows x86

ruff-0.0.261-py3-none-musllinux_1_2_x86_64.whl (5.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.0.261-py3-none-musllinux_1_2_i686.whl (5.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.0.261-py3-none-musllinux_1_2_armv7l.whl (4.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.0.261-py3-none-musllinux_1_2_aarch64.whl (4.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.0.261-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.0.261-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.0.261-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (5.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.0.261-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (5.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.0.261-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (5.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.0.261-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (4.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.0.261-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.0.261-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (9.7 MB view details)

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

ruff-0.0.261-py3-none-macosx_10_7_x86_64.whl (5.1 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.0.261.tar.gz
  • Upload date:
  • Size: 854.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.261.tar.gz
Algorithm Hash digest
SHA256 c1c715b0d1e18f9c509d7c411ca61da3543a4aa459325b1b1e52b8301d65c6d2
MD5 91a3b4b080967808be2942f0063624af
BLAKE2b-256 6b4b307aecf586a0747d950cb5c3e77c90c7547335aa5e57c602e80b0a9f6c20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.261-py3-none-win_arm64.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.261-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 d2eddc60ae75fc87f8bb8fd6e8d5339cf884cd6de81e82a50287424309c187ba
MD5 f21a297f4a55076fd5413cff51d1706e
BLAKE2b-256 9caada57cbfc20c854d339a65c082b26c4ca9b4fbc7c6496934b46c68163a3d6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.0.261-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 0fbc689c23609edda36169c8708bb91bab111d8f44cb4a88330541757770ab30
MD5 073b41e548fe460e13b1d7ce171e039f
BLAKE2b-256 1ba4e89fbf5777404eb4b4532f5b06a709129eecdf6dcef0980688bec5f6b949

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.0.261-py3-none-win32.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for ruff-0.0.261-py3-none-win32.whl
Algorithm Hash digest
SHA256 daff64b4e86e42ce69e6367d63aab9562fc213cd4db0e146859df8abc283dba0
MD5 458906d1efb6f59f8a2522ac294cb241
BLAKE2b-256 d6a20d5b08e9f27d0aa5369446a6146b5b4fe4ce4625732f49858dbed8768316

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aaa4f52a6e513f8daa450dac4859e80390d947052f592f0d8e796baab24df2fc
MD5 e29f3dadb31660a8127604479edf10c6
BLAKE2b-256 422215a913ffaef2be5e26c9a57beea3cb2b3d10a10022e28355ffa0178f65b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 39abd02342cec0c131b2ddcaace08b2eae9700cab3ca7dba64ae5fd4f4881bd0
MD5 75b1a464f3b5a95485919475abd1915e
BLAKE2b-256 2e8b5f6b7a8d4cc8dac3dcd2573180a7dbca839a73055df2e067272c543d997f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 6c5f397ec0af42a434ad4b6f86565027406c5d0d0ebeea0d5b3f90c4bf55bc82
MD5 e94b72c3abc661ad4853eeafa404a067
BLAKE2b-256 636fd2e08cf5b0217a8b2ba7e123c30f799c5c201a176a3bc0a74cce846ce143

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4bcec45abdf65c1328a269cf6cc193f7ff85b777fa2865c64cf2c96b80148a2c
MD5 be1698fb4abd391f36bd807d45127519
BLAKE2b-256 144096c3a8831a5fbac714ead0064ad6681526385908f2dd06f83391d6c7e08a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d95596e2f4cafead19a6d1ec0b86f8fda45ba66fe934de3956d71146a87959b3
MD5 1cc6be2401d8927b4450b646f2301854
BLAKE2b-256 6b823523ff1f158883782e7df9e46575146ba202144af9cbb83a296af19e97b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 d1293acc64eba16a11109678dc4743df08c207ed2edbeaf38b3e10eb2597321b
MD5 b70a4edae582e6b8cd92fe8b3de50b6d
BLAKE2b-256 2eeb8dfafe1ee789a495d85d679f5f788f275d9ea4f84add1668a05a749aadc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 f268d52a71bf410aa45c232870c17049df322a7d20e871cfe622c9fc784aab7b
MD5 d20bbf64a7a57dc376e9e515d88a2131
BLAKE2b-256 4f52530a6cff10ab024ed4d11b42ad1551961269d786787385a839ce65bbbb81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 8fa98e747e0fe185d65a40b0ea13f55c492f3b5f9a032a1097e82edaddb9e52e
MD5 8adef8ba3a72be1b38c6cf97284d25b3
BLAKE2b-256 752c3ecfee398c2608fb752caa19febab02381a4e55d7a18cae052df19cdc161

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 cc970f6ece0b4950e419f0252895ee42e9e8e5689c6494d18f5dc2c6ebb7f798
MD5 77a8a67f7e1d1b515fbe7e5e1b848ebd
BLAKE2b-256 0d92a8ca1c04dc47e7ac2667e445654590d689105fc106026df55cbcfcac0693

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 581e64fa1518df495ca890a605ee65065101a86db56b6858f848bade69fc6489
MD5 cdf17b739ae51a15adbe1500a3443a1a
BLAKE2b-256 41133bf7e11662facd924f63944417f315d9f9dd49a0b5c96b6193d7c01f3552

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8dbd0cee5a81b0785dc0feeb2640c1e31abe93f0d77c5233507ac59731a626f1
MD5 0271d1f641375c5fd046cbdf3453953f
BLAKE2b-256 977f141919718fcacfec51ec23e6cb5c73bddf51be58f9549830951384470eb8

See more details on using hashes here.

File details

Details for the file ruff-0.0.261-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.261-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2dba68a9e558ab33e6dd5d280af798a2d9d3c80c913ad9c8b8e97d7b287f1cc9
MD5 8e63294366658512c93d8842820b3b51
BLAKE2b-256 e3e9717b326c9cfcf95461ea2b52a740de10da9abb0c8209a6fd29f1c946447c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.0.261-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 6624a966c4a21110cee6780333e2216522a831364896f3d98f13120936eff40a
MD5 312af2377022484075d7622832b553ad
BLAKE2b-256 dc3a209f1e016e6ed885e788b6021508aa257bd202ccbc72fae0a0f309e9e719

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