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.12 compatibility
  • 📦 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
  • ⚖️ 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.1.0
  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 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 = ["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.8
target-version = "py38"

[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 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 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 a formatter, 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/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

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.0.tar.gz (1.6 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.0-py3-none-win_arm64.whl (6.2 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.1.0-py3-none-win_amd64.whl (6.5 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.1.0-py3-none-win32.whl (6.1 MB view details)

Uploaded Python 3Windows x86

ruff-0.1.0-py3-none-musllinux_1_2_x86_64.whl (6.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.1.0-py3-none-musllinux_1_2_i686.whl (6.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.1.0-py3-none-musllinux_1_2_armv7l.whl (5.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.1.0-py3-none-musllinux_1_2_aarch64.whl (6.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (8.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.1.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (7.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (6.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (5.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.1.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (12.1 MB view details)

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

ruff-0.1.0-py3-none-macosx_10_7_x86_64.whl (6.3 MB view details)

Uploaded Python 3macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: ruff-0.1.0.tar.gz
  • Upload date:
  • Size: 1.6 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.0.tar.gz
Algorithm Hash digest
SHA256 ad6b13824714b19c5f8225871cf532afb994470eecb74631cd3500fe817e6b3f
MD5 b469451dcfafe40674e872b90354050d
BLAKE2b-256 ed63dcb12b0a11eae757e510fa82a6d50899c032d78cfadcbfa3adce1966a1cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 6.2 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.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 45abdbdab22509a2c6052ecf7050b3f5c7d6b7898dc07e82869401b531d46da4
MD5 e8e65deca3cbffe73498b23dfec37daf
BLAKE2b-256 8879aaf84a13905f98072c06826f85e0dbf9e8d8b7c811722cba1893d98edcfa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 6.5 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.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a76ba81860f7ee1f2d5651983f87beb835def94425022dc5f0803108f1b8bfa2
MD5 8a2869d16120fa6b7c3f3f68469262be
BLAKE2b-256 becdda574980bf389f632a9da89aaa5baa5199a1b8860a1cf70a5b2e9a14c083

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-win32.whl
  • Upload date:
  • Size: 6.1 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.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 480bd704e8af1afe3fd444cc52e3c900b936e6ca0baf4fb0281124330b6ceba2
MD5 5e521029b8961b307708029e2d51e600
BLAKE2b-256 cc127e37f538bf393a8df563d9b149631116a6a3d0ee3495e2ba224838dfbade

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 6.6 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.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b77f6cfa72c6eb19b5cac967cc49762ae14d036db033f7d97a72912770fd8e1c
MD5 e1baa8197855acd35a8323829f773497
BLAKE2b-256 8445fd7cad3391108f5e4189af607f20c82eb3be85c7243162252ffb97e1e42c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-musllinux_1_2_i686.whl
  • Upload date:
  • Size: 6.2 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.0-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ad2ccdb3bad5a61013c76a9c1240fdfadf2c7103a2aeebd7bcbbed61f363138f
MD5 84de91a3ceea4bd5cb53ae2d0b61a035
BLAKE2b-256 030ad5df874a40fa3eae09626e072f4b1580b51025b964f699170404277678ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-musllinux_1_2_armv7l.whl
  • Upload date:
  • Size: 5.9 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.0-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 d88adfd93849bc62449518228581d132e2023e30ebd2da097f73059900d8dce3
MD5 02b9e110bac96e7193acc32e77300058
BLAKE2b-256 fc36fd2d66b1e58a3dfb9211795ee060ecda9aa6e5ded5312e7a20f110f1bbd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7186ccf54707801d91e6314a016d1c7895e21d2e4cd614500d55870ed983aa9f
MD5 1e8f01c5512c59f9878a1986cb1442af
BLAKE2b-256 eddf285f1ab2028a29e402da421eeb6523d56153d3a5f9f9d4e4e5df4e0a9ab7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b04cd4298b43b16824d9a37800e4c145ba75c29c43ce0d74cad1d66d7ae0a4c5
MD5 3331a1ba3367356dacdc202e798b0552
BLAKE2b-256 ac220fc6119373ee9335a6ff41761eff4997e45c4773555100d150d4efba7395

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 fa7aeed7bc23861a2b38319b636737bf11cfa55d2109620b49cf995663d3e888
MD5 ec7a44c29b0800f4075f3f161803e489
BLAKE2b-256 c0648835980bfb0dddccb1e75d12b6372610ea39a594f5dc931e38d8fa15a381

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 ee8cd57f454cdd77bbcf1e11ff4e0046fb6547cac1922cc6e3583ce4b9c326d1
MD5 339049143c80913ba130df63eae33ff1
BLAKE2b-256 5bbf8795534dffc59cc18c7a363b9db48af23cd8338108f59abf5e72899cea1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 a5391b49b1669b540924640587d8d24128e45be17d1a916b1801d6645e831581
MD5 9e7b74cf9398aea616a01727eaba0386
BLAKE2b-256 ef18a9f77c44fe3f8c481e414307f8c891fd2c70fb52112d18734b1eec660e9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0d412678bf205787263bb702c984012a4f97e460944c072fd7cfa2bd084857c4
MD5 2885e2e059c7b437debfd0ea6a7de710
BLAKE2b-256 29aca730ea13a1b94a897f1eb843711176e076b1730f586beec5dd6761833d13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 299fff467a0f163baa282266b310589b21400de0a42d8f68553422fa6bf7ee01
MD5 eaedacaa5a54b99a3dbb55a781d4ff24
BLAKE2b-256 c93df25c2e2e08e94699999a1a79faaf8a1a5afd7bf75f9083fb72f28c953bae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 65f4b7fb539e5cf0f71e9bd74f8ddab74cabdd673c6fb7f17a4dcfd29f126255
MD5 43154fd15c622d789c56f4215dfa10b5
BLAKE2b-256 e2cd02ba37dc8f45a5a3c79969cddc869f4bf1fa0d1a97c234e04b99fb5990e9

See more details on using hashes here.

File details

Details for the file ruff-0.1.0-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.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 764f36d2982cc4a703e69fb73a280b7c539fd74b50c9ee531a4e3fe88152f521
MD5 09fa88fce00c0309fb05f57a8802fb59
BLAKE2b-256 554bac3b1c94eaa9039108bde3882bf3edb01c3ed98de5a3e95c10d3229a49ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruff-0.1.0-py3-none-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 6.3 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.0-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 87114e254dee35e069e1b922d85d4b21a5b61aec759849f393e1dbb308a00439
MD5 b99fe68f97b948b6d784b8ec961ee280
BLAKE2b-256 00450907965db0e7640d8695a8c22fd8beed865fb21553359fa03d9ca71560e1

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