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.10
  hooks:
    # Run the linter.
    - id: ruff
      args: [ --fix ]
    # Run the 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",
    ".ipynb_checkpoints",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pyenv",
    ".pytest_cache",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    ".vscode",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "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

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.10.tar.gz (1.9 MB view details)

Uploaded Source

Built Distributions

ruff-0.1.10-py3-none-win_arm64.whl (6.8 MB view details)

Uploaded Python 3Windows ARM64

ruff-0.1.10-py3-none-win_amd64.whl (7.2 MB view details)

Uploaded Python 3Windows x86-64

ruff-0.1.10-py3-none-win32.whl (6.6 MB view details)

Uploaded Python 3Windows x86

ruff-0.1.10-py3-none-musllinux_1_2_x86_64.whl (7.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ruff-0.1.10-py3-none-musllinux_1_2_i686.whl (7.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ruff-0.1.10-py3-none-musllinux_1_2_armv7l.whl (6.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ruff-0.1.10-py3-none-musllinux_1_2_aarch64.whl (6.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ruff-0.1.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ruff-0.1.10-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (8.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ruff-0.1.10-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (7.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ruff-0.1.10-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl (8.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64

ruff-0.1.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (7.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

ruff-0.1.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (6.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ruff-0.1.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ruff-0.1.10-py3-none-macosx_10_12_x86_64.whl (7.2 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

ruff-0.1.10-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (14.2 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.10.tar.gz
Algorithm Hash digest
SHA256 2d74594bbdc4abe6b523e1998183dcdea17e0d3f22082abde8074a8c9b1a94d9
MD5 4e3723a3ca79701a321f7c7715805f83
BLAKE2b-256 afb6d8d166066978ca5f376054bec8027a74e6603ffe18fa532cf23ba2ab92ba

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.10-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 6671c90894e9ba2c85372557a588baa44f1abe9ffc95791c0c3071cb904dab43
MD5 b7c8d770e455046b773a7a09791c7cc0
BLAKE2b-256 9a56c902ba190c574e8b6dedfa1a003afa66de1025622f0b6c04d88646f2347e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.10-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 0db9995e8973f964ca5d2199775e81b05cc5d78b957d30866b715fc4318ff0df
MD5 08a77c210f918e8f5525a8e525c2ad60
BLAKE2b-256 9ebfc0b846389a2fd155fa46e771c9460a66ea38cd9152c119d7f7b6e2adb733

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.10-py3-none-win32.whl
Algorithm Hash digest
SHA256 7c3bdea51a4e778f37c40fec4a92a442e928b3126314617ccdc6a69dc48c8e46
MD5 f188b8f70c1034797507393e22164110
BLAKE2b-256 14158de8c59a2ea4bcb5b4868e5b79c1094fdbd5e0fa0f6bd7c1533b0b385a39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 97b1896b6c33f9abb8284bebc92d117a3db98cb4f939e18ae6ead1fc126f213a
MD5 4c8ced9eff84ca81c2744c40b64c66c7
BLAKE2b-256 42b6e34cc9c856c1c3886ae87602e28c7bd9740ac13df0ff8ece856caa9114f0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ruff-0.1.10-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ccc60939eee82a698eed442f7b4d59c7f0702ee240e3d6c67c4f434c96329585
MD5 e15195f9a86226a9f2b2d90349c771ec
BLAKE2b-256 6a1f87d54d463977b292253d0dad10600c41926ee988a8a0a8644164f93950af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 d440ad091cd43b9b8adfb3802844b4691b5c9c3a29febfc17e7b779105ccdd91
MD5 464232d15a19698b2e55842ed05bed9e
BLAKE2b-256 30735697f26f58aab3ba77a970a7857a10e52c5dd8bd9304712408218ed38a7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 94fc0f7a95558d3306df745648d64b27807a0fc2032893a8d87d52ce3954bf0b
MD5 1d721441df9c8690e4ac8b4ea1ca0382
BLAKE2b-256 fd5073b484ddde97f9e6eeeb41606dd6918462915ab686c41369cc481733a61f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0562f9846b8330ef99b07127b9223943d12135b143f1695659bbaa6b8ad2180c
MD5 dbe0453da74e216639f31fdd0823f21d
BLAKE2b-256 7e611f8d57c82f5e25af49f8a23bf7052e2c4c50c4799147420202b6e8e486e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 8d8e685efed68405cc0b07d789abd5b02a7ccbf6f1998a3a55655aeaeb0f9cf4
MD5 1af7a9cda486b9ecec6e15ce855f6331
BLAKE2b-256 656f0892e6824866785746f20c8f7aaa70fc5cb1a89ce7eb2b6de92ccfb9dee6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 ab13793b9c423873e72de99d985780cd9dbe91e9cf742b3c40b40c3470bcf4b7
MD5 03f139a8a8c692e64433183bc3580924
BLAKE2b-256 a66addfa966458ee791451ff3a9c6160794ed86fa145f976a0c6aacfccd9fda0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl
Algorithm Hash digest
SHA256 0820929df7f0a1ace749ebaedc412659f558bc31fa0f187e48a2d566535477e0
MD5 1a91d4bf8703e4e9b0b86c3ac753fb19
BLAKE2b-256 c82e362ad6d1a75deb61ed40d383ce99740888e3780aafb4f0a09607c740dfd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f786571ac9d2f3db0393ee453d5d586de4ee5e911c53c7514032c45fd5e50d1d
MD5 fa0d2afb06cd1266b1a999f664ddcf0c
BLAKE2b-256 752437652bfe9263fa9b800a7d626740a497e78eb59bcf1ea27de612d36e9a20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 61609eacb860ae3c2fe603c85c0cbbf2f5f5da5865271441fd672cba5d995880
MD5 94dc160b2a4cb48313ef6f020bceec84
BLAKE2b-256 6988263f953ab02250bed45624cd2eb2a2bc1c72caa918de3edf8ab250878fc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 71994cf0b98856f956ff9fbf32e06e642e3de91ce324504b7a5bd381e1944efa
MD5 c2280f8c7d92fc2f284206aef558ad8d
BLAKE2b-256 560e1d7a48ef82a278d6be9c564bd812cd524487365e59c8a439d1b166beb279

See more details on using hashes here.

File details

Details for the file ruff-0.1.10-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c0ccbbb363aaf4e8cbdee1f928f0fdaed0ccac2a4f2e472bb7af17f071480437
MD5 0cc14e51703dac2c150c459b0e1af597
BLAKE2b-256 0b06cfc308652893ab7d97c1df89d4948b77351d757e6d591c47c322c9a13067

See more details on using hashes here.

File details

Details for the file ruff-0.1.10-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for ruff-0.1.10-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ee49ed7f7fc9daeb0e10bca3e9801efdda60bbf425f7856f2ac2f7207168d569
MD5 928523f6ddd6071ede512d447e25a84a
BLAKE2b-256 a1a71fd5917115f0e48e145e5d52d46d33057fd1271dc147cc6b7e3bc0236f32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page