2023-01-28 08:31:16 -05:00
<!-- Begin section: Overview -->
2022-10-15 16:37:52 -04:00
# Ruff
2022-08-09 13:21:53 -04:00
2023-07-25 18:25:46 -07:00
[](https://github.com/astral-sh/ruff)
2022-09-16 12:18:03 -06:00
[](https://pypi.python.org/pypi/ruff)
2024-04-25 22:14:21 -04:00
[](https://github.com/astral-sh/ruff/blob/main/LICENSE)
2022-09-16 12:18:03 -06:00
[](https://pypi.python.org/pypi/ruff)
2023-06-08 21:13:40 +05:30
[](https://github.com/astral-sh/ruff/actions)
2024-02-29 11:20:11 -05:00
[](https://discord.com/invite/astral-sh)
2022-08-09 22:16:50 -04:00
2024-02-29 11:20:11 -05:00
[**Docs** ](https://docs.astral.sh/ruff/ ) | [**Playground** ](https://play.ruff.rs/ )
2022-08-09 22:16:50 -04:00
2023-10-20 19:08:26 -04:00
An extremely fast Python linter and code formatter, written in Rust.
2023-01-30 19:00:57 -05:00
2022-08-28 15:49:43 -04:00
< p align = "center" >
2022-12-31 17:47:32 -05:00
< picture align = "center" >
2023-06-22 17:19:34 +02:00
< source media = "(prefers-color-scheme: dark)" srcset = "https://user-images.githubusercontent.com/1309177/232603514-c95e9b0f-6b31-43de-9a80-9e844173fd6a.svg" >
< source media = "(prefers-color-scheme: light)" srcset = "https://user-images.githubusercontent.com/1309177/232603516-4fb4892d-585c-4b20-b810-3db9161831e4.svg" >
< img alt = "Shows a bar chart with benchmark results." src = "https://user-images.githubusercontent.com/1309177/232603516-4fb4892d-585c-4b20-b810-3db9161831e4.svg" >
2022-12-31 17:47:32 -05:00
< / picture >
2022-08-28 15:49:43 -04:00
< / p >
< p align = "center" >
< i > Linting the CPython codebase from scratch.< / i >
< / p >
2023-10-20 19:08:26 -04:00
- ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)
2023-05-28 22:45:56 -04:00
- 🐍 Installable via `pip`
- 🛠️ `pyproject.toml` support
2024-06-14 01:53:03 +02:00
- 🤝 Python 3.13 compatibility
2024-08-05 11:05:23 +05:30
- ⚖️ Drop-in parity with [Flake8 ](https://docs.astral.sh/ruff/faq/#how-does-ruffs-linter-compare-to-flake8 ), isort, and [Black ](https://docs.astral.sh/ruff/faq/#how-does-ruffs-formatter-compare-to-black )
2023-05-28 22:45:56 -04:00
- 📦 Built-in caching, to avoid re-analyzing unchanged files
2023-09-28 12:53:05 +02:00
- 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports)
2024-03-20 22:39:37 -04:00
- 📏 Over [800 built-in rules ](https://docs.astral.sh/ruff/rules/ ), with native re-implementations
2023-10-20 19:08:26 -04:00
of popular Flake8 plugins, like flake8-bugbear
2025-05-26 16:50:09 +08:00
- ⌨️ First-party [editor integrations ](https://docs.astral.sh/ruff/editors ) for [VS Code ](https://github.com/astral-sh/ruff-vscode ) and [more ](https://docs.astral.sh/ruff/editors/setup )
2024-08-05 11:05:23 +05:30
- 🌎 Monorepo-friendly, with [hierarchical and cascading configuration ](https://docs.astral.sh/ruff/configuration/#config-file-discovery )
2022-10-14 17:21:34 -04:00
Ruff aims to be orders of magnitude faster than alternative tools while integrating more
2022-12-26 21:17:18 -05:00
functionality behind a single, common interface.
2023-02-01 19:10:41 -05:00
Ruff can be used to replace [Flake8 ](https://pypi.org/project/flake8/ ) (plus dozens of plugins),
2023-10-20 19:08:26 -04:00
[Black ](https://github.com/psf/black ), [isort ](https://pypi.org/project/isort/ ),
[pydocstyle ](https://pypi.org/project/pydocstyle/ ), [pyupgrade ](https://pypi.org/project/pyupgrade/ ),
[autoflake ](https://pypi.org/project/autoflake/ ), and more, all while executing tens or hundreds of
times faster than any individual tool.
2022-08-28 14:21:44 -04:00
2022-11-27 21:55:01 -05:00
Ruff is extremely actively developed and used in major open-source projects like:
2022-11-07 10:59:47 -05:00
2023-02-27 16:14:05 +01:00
- [Apache Airflow ](https://github.com/apache/airflow )
2024-04-24 18:39:39 -07:00
- [Apache Superset ](https://github.com/apache/superset )
2023-04-04 22:40:02 -04:00
- [FastAPI ](https://github.com/tiangolo/fastapi )
- [Hugging Face ](https://github.com/huggingface/transformers )
- [Pandas ](https://github.com/pandas-dev/pandas )
2023-02-27 16:14:05 +01:00
- [SciPy ](https://github.com/scipy/scipy )
2023-02-17 08:36:32 -05:00
2023-11-14 15:38:12 +01:00
...and [many more ](#whos-using-ruff ).
2022-11-05 16:03:10 -04:00
2023-04-19 15:28:45 -05:00
Ruff is backed by [Astral ](https://astral.sh ). Read the [launch post ](https://astral.sh/blog/announcing-astral-the-company-behind-ruff ),
or the original [project announcement ](https://notes.crmarsh.com/python-tooling-could-be-much-much-faster ).
2022-08-30 13:40:31 -04:00
2022-11-27 21:55:01 -05:00
## Testimonials
[**Sebastián Ramírez** ](https://twitter.com/tiangolo/status/1591912354882764802 ), creator
of [FastAPI ](https://github.com/tiangolo/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.
2023-01-16 14:44:52 -05:00
[**Nick Schrock** ](https://twitter.com/schrockn/status/1612615862904827904 ), founder of [Elementl ](https://www.elementl.com/ ),
co-creator of [GraphQL ](https://graphql.org/ ):
> 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
2023-02-02 22:29:07 +01:00
> cores on my M1. Running ruff against our _entire_ codebase takes .4 seconds.
2023-01-16 14:44:52 -05:00
2022-11-27 21:55:01 -05:00
[**Bryan Van de Ven** ](https://github.com/bokeh/bokeh/pull/12605 ), co-creator
of [Bokeh ](https://github.com/bokeh/bokeh/ ), original author
of [Conda ](https://docs.conda.io/en/latest/ ):
> 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.
2023-01-16 14:44:52 -05:00
[**Timothy Crosley** ](https://twitter.com/timothycrosley/status/1606420868514877440 ),
creator of [isort ](https://github.com/PyCQA/isort ):
2023-05-28 22:45:56 -04:00
> 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.
2023-01-16 14:44:52 -05:00
2023-06-08 21:13:40 +05:30
[**Tim Abbott** ](https://github.com/astral-sh/ruff/issues/465#issuecomment-1317400028 ), lead
2023-01-16 14:44:52 -05:00
developer of [Zulip ](https://github.com/zulip/zulip ):
2022-11-27 21:55:01 -05:00
> This is just ridiculously fast... `ruff` is amazing.
2023-01-28 08:31:16 -05:00
<!-- End section: Overview -->
2022-10-15 16:37:52 -04:00
## Table of Contents
2023-09-15 22:49:42 -04:00
For more, see the [documentation ](https://docs.astral.sh/ruff/ ).
2023-02-01 19:10:41 -05:00
2023-02-22 19:25:53 -05:00
1. [Getting Started ](#getting-started )
2023-02-27 16:14:05 +01:00
1. [Configuration ](#configuration )
1. [Rules ](#rules )
1. [Contributing ](#contributing )
1. [Support ](#support )
1. [Acknowledgements ](#acknowledgements )
1. [Who's Using Ruff? ](#whos-using-ruff )
1. [License ](#license )
2022-10-15 16:37:52 -04:00
2024-08-26 08:12:35 +01:00
## Getting Started<a id="getting-started"></a>
2022-08-28 14:21:44 -04:00
2023-09-15 22:49:42 -04:00
For more, see the [documentation ](https://docs.astral.sh/ruff/ ).
2023-02-01 19:10:41 -05:00
2022-08-28 14:21:44 -04:00
### Installation
2022-08-10 15:42:29 -04:00
2025-01-07 09:43:25 -05:00
Ruff is available as [`ruff` ](https://pypi.org/project/ruff/ ) on PyPI.
Invoke Ruff directly with [`uvx` ](https://docs.astral.sh/uv/ ):
```shell
uvx ruff check # Lint all files in the current directory.
uvx ruff format # Format all files in the current directory.
```
Or install Ruff with `uv` (recommended), `pip` , or `pipx` :
2024-07-04 14:11:54 +05:30
```shell
2024-12-09 15:25:18 +07:00
# With uv.
2025-01-07 09:43:25 -05:00
uv tool install ruff@latest # Install Ruff globally.
uv add --dev ruff # Or add Ruff to your project.
2024-12-09 15:25:18 +07:00
2024-07-04 14:11:54 +05:30
# With pip.
pip install ruff
# With pipx.
pipx install ruff
```
Starting with version `0.5.0` , Ruff can be installed with our standalone installers:
2022-08-10 15:42:29 -04:00
```shell
2024-07-03 14:39:58 -04:00
# On macOS and Linux.
curl -LsSf https://astral.sh/ruff/install.sh | sh
# On Windows.
powershell -c "irm https://astral.sh/ruff/install.ps1 | iex"
# For a specific version.
2025-10-02 14:14:05 -05:00
curl -LsSf https://astral.sh/ruff/0.13.3/install.sh | sh
powershell -c "irm https://astral.sh/ruff/0.13.3/install.ps1 | iex"
2024-07-03 14:39:58 -04:00
```
2023-02-22 19:25:53 -05:00
You can also install Ruff via [Homebrew ](https://formulae.brew.sh/formula/ruff ), [Conda ](https://anaconda.org/conda-forge/ruff ),
2023-09-15 22:49:42 -04:00
and with [a variety of other package managers ](https://docs.astral.sh/ruff/installation/ ).
2023-01-13 22:29:26 -05:00
2022-08-28 14:21:44 -04:00
### Usage
2022-08-10 15:42:29 -04:00
2023-10-20 19:08:26 -04:00
To run Ruff as a linter, try any of the following:
2022-08-10 15:42:29 -04:00
```shell
2024-03-14 00:10:48 +09:00
ruff check # Lint all files in the current directory (and any subdirectories).
2023-10-20 19:08:26 -04:00
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.
2022-08-10 15:42:29 -04:00
```
2023-10-20 19:08:26 -04:00
Or, to run Ruff as a formatter:
```shell
2024-03-14 00:10:48 +09:00
ruff format # Format all files in the current directory (and any subdirectories).
2023-10-20 19:08:26 -04:00
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 ](https://pre-commit.com/ ) hook via [`ruff-pre-commit` ](https://github.com/astral-sh/ruff-pre-commit ):
2022-09-02 03:01:28 +10:00
```yaml
2023-05-21 15:27:35 -04:00
- repo: https://github.com/astral-sh/ruff-pre-commit
2022-12-22 10:51:20 -05:00
# Ruff version.
2025-10-02 14:14:05 -05:00
rev: v0.13.3
2022-12-22 10:51:20 -05:00
hooks:
2023-11-07 10:40:13 -08:00
# Run the linter.
2025-06-17 20:12:11 +02:00
- id: ruff-check
2023-11-07 10:40:13 -08:00
args: [ --fix ]
# Run the formatter.
2023-10-20 19:08:26 -04:00
- id: ruff-format
2022-09-02 03:01:28 +10:00
```
2024-08-04 17:01:36 +07:00
Ruff can also be used as a [VS Code extension ](https://github.com/astral-sh/ruff-vscode ) or with [various other editors ](https://docs.astral.sh/ruff/editors/setup ).
2023-02-17 08:49:09 -05:00
2023-04-03 16:47:26 -07:00
Ruff can also be used as a [GitHub Action ](https://github.com/features/actions ) via
2024-09-29 19:49:24 -04:00
[`ruff-action` ](https://github.com/astral-sh/ruff-action ):
2023-04-03 16:47:26 -07:00
```yaml
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
2024-02-24 14:16:10 +01:00
- uses: actions/checkout@v4
2024-12-31 16:43:17 +01:00
- uses: astral-sh/ruff-action@v3
2023-04-03 16:47:26 -07:00
```
2024-08-26 08:12:35 +01:00
### Configuration<a id="configuration"></a>
2022-11-27 23:50:24 -05:00
2023-02-24 18:14:26 -05:00
Ruff can be configured through a `pyproject.toml` , `ruff.toml` , or `.ruff.toml` file (see:
2023-09-15 22:49:42 -04:00
[_Configuration_ ](https://docs.astral.sh/ruff/configuration/ ), or [_Settings_ ](https://docs.astral.sh/ruff/settings/ )
2023-02-24 18:14:26 -05:00
for a complete list of all configuration options).
2023-02-14 13:45:59 -05:00
2024-03-13 11:45:34 -07:00
If left unspecified, Ruff's default configuration is equivalent to the following `ruff.toml` file:
2022-08-28 14:21:44 -04:00
```toml
2022-11-03 09:28:48 -04:00
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
2023-05-07 04:40:38 +02:00
".git-rewrite",
2022-11-03 09:28:48 -04:00
".hg",
2023-12-18 11:37:25 -05:00
".ipynb_checkpoints",
2022-11-03 09:28:48 -04:00
".mypy_cache",
".nox",
".pants.d",
2023-12-18 11:37:25 -05:00
".pyenv",
".pytest_cache",
2023-02-16 20:38:08 +01:00
".pytype",
2022-11-03 09:28:48 -04:00
".ruff_cache",
".svn",
".tox",
".venv",
2023-12-18 11:37:25 -05:00
".vscode",
2022-11-03 09:28:48 -04:00
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
2023-12-18 11:37:25 -05:00
"site-packages",
2022-11-03 09:28:48 -04:00
"venv",
]
2023-01-26 13:23:21 -05:00
# Same as Black.
line-length = 88
2023-10-20 19:08:26 -04:00
indent-width = 4
2024-11-18 22:29:27 +09:00
# Assume Python 3.9
target-version = "py39"
2023-10-20 19:08:26 -04:00
2024-03-13 11:45:34 -07:00
[lint]
2025-05-14 10:20:19 +01:00
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
2023-10-20 19:08:26 -04:00
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
2023-01-26 13:23:21 -05:00
2022-11-03 09:28:48 -04:00
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
2024-03-13 11:45:34 -07:00
[format]
2023-10-20 19:08:26 -04:00
# 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.
2023-10-25 09:31:43 +03:00
skip-magic-trailing-comma = false
2022-11-21 13:19:18 -05:00
2023-10-20 19:08:26 -04:00
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
2022-11-03 09:28:48 -04:00
```
2024-03-13 11:45:34 -07:00
Note that, in a `pyproject.toml` , each section header should be prefixed with `tool.ruff` . For
example, `[lint]` should be replaced with `[tool.ruff.lint]` .
Some configuration options can be provided via dedicated command-line arguments, such as those
related to rule enablement and disablement, file discovery, and logging level:
```shell
ruff check --select F401 --select F403 --quiet
```
The remaining configuration options can be provided through a catch-all `--config` argument:
2022-08-28 14:32:35 -04:00
```shell
2024-03-13 11:45:34 -07:00
ruff check --config "lint.per-file-ignores = {'some_file.py' = ['F841']}"
2022-08-28 14:32:35 -04:00
```
2024-05-13 10:27:29 -04:00
To opt in to the latest lint rules, formatter style changes, interface updates, and more, enable
[preview mode ](https://docs.astral.sh/ruff/rules/ ) by setting `preview = true` in your configuration
file or passing `--preview` on the command line. Preview mode enables a collection of unstable
features that may change prior to stabilization.
2023-10-20 19:08:26 -04:00
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.
2023-01-28 08:31:16 -05:00
2024-08-26 08:12:35 +01:00
## Rules<a id="rules"></a>
2022-10-15 11:28:32 -04:00
2023-01-28 08:31:16 -05:00
<!-- Begin section: Rules -->
2024-03-20 22:39:37 -04:00
**Ruff supports over 800 lint rules**, many of which are inspired by popular tools like Flake8,
2023-02-22 19:25:53 -05:00
isort, pyupgrade, and others. Regardless of the rule's origin, Ruff re-implements every rule in
2023-02-17 08:07:37 -05:00
Rust as a first-party feature.
2022-11-05 16:18:27 -04:00
2023-10-19 12:26:59 -04:00
By default, Ruff enables Flake8's `F` rules, along with a subset of the `E` rules, omitting any
2023-10-20 19:08:26 -04:00
stylistic rules that overlap with the use of a formatter, like `ruff format` or
2023-02-22 19:25:53 -05:00
[Black ](https://github.com/psf/black ).
2022-10-15 11:28:32 -04:00
2023-02-28 15:31:27 -05:00
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.
2023-05-30 00:20:41 +02:00
<!-- End section: Rules -->
2023-03-17 23:33:37 -04:00
Beyond the defaults, Ruff re-implements some of the most popular Flake8 plugins and related code
quality tools, including:
- [autoflake ](https://pypi.org/project/autoflake/ )
- [eradicate ](https://pypi.org/project/eradicate/ )
- [flake8-2020 ](https://pypi.org/project/flake8-2020/ )
- [flake8-annotations ](https://pypi.org/project/flake8-annotations/ )
2023-05-15 15:15:28 +02:00
- [flake8-async ](https://pypi.org/project/flake8-async )
2023-06-08 21:13:40 +05:30
- [flake8-bandit ](https://pypi.org/project/flake8-bandit/ ) ([#1646 ](https://github.com/astral-sh/ruff/issues/1646 ))
2023-03-17 23:33:37 -04:00
- [flake8-blind-except ](https://pypi.org/project/flake8-blind-except/ )
- [flake8-boolean-trap ](https://pypi.org/project/flake8-boolean-trap/ )
- [flake8-bugbear ](https://pypi.org/project/flake8-bugbear/ )
- [flake8-builtins ](https://pypi.org/project/flake8-builtins/ )
- [flake8-commas ](https://pypi.org/project/flake8-commas/ )
- [flake8-comprehensions ](https://pypi.org/project/flake8-comprehensions/ )
2023-06-10 19:17:58 -07:00
- [flake8-copyright ](https://pypi.org/project/flake8-copyright/ )
2023-03-17 23:33:37 -04:00
- [flake8-datetimez ](https://pypi.org/project/flake8-datetimez/ )
- [flake8-debugger ](https://pypi.org/project/flake8-debugger/ )
2023-03-21 23:26:22 -04:00
- [flake8-django ](https://pypi.org/project/flake8-django/ )
2023-03-17 23:33:37 -04:00
- [flake8-docstrings ](https://pypi.org/project/flake8-docstrings/ )
- [flake8-eradicate ](https://pypi.org/project/flake8-eradicate/ )
- [flake8-errmsg ](https://pypi.org/project/flake8-errmsg/ )
- [flake8-executable ](https://pypi.org/project/flake8-executable/ )
2023-05-13 20:00:06 -07:00
- [flake8-future-annotations ](https://pypi.org/project/flake8-future-annotations/ )
2023-03-29 01:32:02 +02:00
- [flake8-gettext ](https://pypi.org/project/flake8-gettext/ )
2023-03-17 23:33:37 -04:00
- [flake8-implicit-str-concat ](https://pypi.org/project/flake8-implicit-str-concat/ )
- [flake8-import-conventions ](https://github.com/joaopalmeiro/flake8-import-conventions )
2023-09-15 03:41:32 +02:00
- [flake8-logging ](https://pypi.org/project/flake8-logging/ )
2023-03-17 23:33:37 -04:00
- [flake8-logging-format ](https://pypi.org/project/flake8-logging-format/ )
- [flake8-no-pep420 ](https://pypi.org/project/flake8-no-pep420 )
- [flake8-pie ](https://pypi.org/project/flake8-pie/ )
- [flake8-print ](https://pypi.org/project/flake8-print/ )
- [flake8-pyi ](https://pypi.org/project/flake8-pyi/ )
- [flake8-pytest-style ](https://pypi.org/project/flake8-pytest-style/ )
- [flake8-quotes ](https://pypi.org/project/flake8-quotes/ )
- [flake8-raise ](https://pypi.org/project/flake8-raise/ )
- [flake8-return ](https://pypi.org/project/flake8-return/ )
- [flake8-self ](https://pypi.org/project/flake8-self/ )
- [flake8-simplify ](https://pypi.org/project/flake8-simplify/ )
2023-06-09 06:14:16 +02:00
- [flake8-slots ](https://pypi.org/project/flake8-slots/ )
2023-03-17 23:33:37 -04:00
- [flake8-super ](https://pypi.org/project/flake8-super/ )
- [flake8-tidy-imports ](https://pypi.org/project/flake8-tidy-imports/ )
2023-05-13 09:19:06 -05:00
- [flake8-todos ](https://pypi.org/project/flake8-todos/ )
2023-03-17 23:33:37 -04:00
- [flake8-type-checking ](https://pypi.org/project/flake8-type-checking/ )
- [flake8-use-pathlib ](https://pypi.org/project/flake8-use-pathlib/ )
2023-06-08 21:13:40 +05:30
- [flynt ](https://pypi.org/project/flynt/ ) ([#2102 ](https://github.com/astral-sh/ruff/issues/2102 ))
2023-03-17 23:33:37 -04:00
- [isort ](https://pypi.org/project/isort/ )
- [mccabe ](https://pypi.org/project/mccabe/ )
- [pandas-vet ](https://pypi.org/project/pandas-vet/ )
- [pep8-naming ](https://pypi.org/project/pep8-naming/ )
- [pydocstyle ](https://pypi.org/project/pydocstyle/ )
2023-05-10 23:26:29 -04:00
- [pygrep-hooks ](https://github.com/pre-commit/pygrep-hooks )
2023-05-28 23:25:06 -04:00
- [pylint-airflow ](https://pypi.org/project/pylint-airflow/ )
2023-03-17 23:33:37 -04:00
- [pyupgrade ](https://pypi.org/project/pyupgrade/ )
- [tryceratops ](https://pypi.org/project/tryceratops/ )
- [yesqa ](https://pypi.org/project/yesqa/ )
2023-09-15 22:49:42 -04:00
For a complete enumeration of the supported rules, see [_Rules_ ](https://docs.astral.sh/ruff/rules/ ).
2023-02-15 21:31:24 +01:00
2024-08-26 08:12:35 +01:00
## Contributing<a id="contributing"></a>
2022-11-01 20:34:38 -04:00
2023-02-01 19:10:41 -05:00
Contributions are welcome and highly appreciated. To get started, check out the
2023-09-15 22:49:42 -04:00
[**contributing guidelines** ](https://docs.astral.sh/ruff/contributing/ ).
2023-02-22 19:25:53 -05:00
2024-02-15 22:16:02 -06:00
You can also join us on [**Discord** ](https://discord.com/invite/astral-sh ).
2022-08-10 15:42:29 -04:00
2024-08-26 08:12:35 +01:00
## Support<a id="support"></a>
2022-08-10 15:42:29 -04:00
2023-06-08 21:13:40 +05:30
Having trouble? Check out the existing issues on [**GitHub** ](https://github.com/astral-sh/ruff/issues ),
or feel free to [**open a new one** ](https://github.com/astral-sh/ruff/issues/new ).
2022-08-28 14:38:44 -04:00
2024-02-15 22:16:02 -06:00
You can also ask for help on [**Discord** ](https://discord.com/invite/astral-sh ).
2022-08-19 15:38:43 -04:00
2024-08-26 08:12:35 +01:00
## Acknowledgements<a id="acknowledgements"></a>
2023-02-14 19:25:07 -05:00
Ruff's linter draws on both the APIs and implementation details of many other
tools in the Python ecosystem, especially [Flake8 ](https://github.com/PyCQA/flake8 ), [Pyflakes ](https://github.com/PyCQA/pyflakes ),
[pycodestyle ](https://github.com/PyCQA/pycodestyle ), [pydocstyle ](https://github.com/PyCQA/pydocstyle ),
[pyupgrade ](https://github.com/asottile/pyupgrade ), and [isort ](https://github.com/PyCQA/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.
2023-10-20 19:08:26 -04:00
Ruff's formatter is built on a fork of Rome's [`rome_formatter` ](https://github.com/rome/tools/tree/main/crates/rome_formatter ),
Port Pyright's import resolver to Rust (#5381)
## Summary
This PR contains the first step towards enabling robust first-party,
third-party, and standard library import resolution in Ruff (including
support for `typeshed`, stub files, native modules, etc.) by porting
Pyright's import resolver to Rust.
The strategy taken here was to start with a more-or-less direct port of
the Pyright's TypeScript resolver. The code is intentionally similar,
and the test suite is effectively a superset of Pyright's test suite for
its own resolver. Due to the nature of the port, the code is very, very
non-idiomatic for Rust. The code is also entirely unused outside of the
test suite, and no effort has been made to integrate it with the rest of
the codebase.
Future work will include:
- Refactoring the code (now that it works) to match Rust and Ruff
idioms.
- Further testing, in practice, to ensure that the resolver can resolve
imports in a complex project, when provided with a virtual environment
path.
- Caching, to minimize filesystem lookups and redundant resolutions.
- Integration into Ruff itself (use Ruff's existing settings, find rules
that can make use of robust resolution, etc.)
2023-06-27 12:15:07 -04:00
and again draws on both API and implementation details from [Rome ](https://github.com/rome/tools ),
2023-02-14 19:25:07 -05:00
[Prettier ](https://github.com/prettier/prettier ), and [Black ](https://github.com/psf/black ).
Port Pyright's import resolver to Rust (#5381)
## Summary
This PR contains the first step towards enabling robust first-party,
third-party, and standard library import resolution in Ruff (including
support for `typeshed`, stub files, native modules, etc.) by porting
Pyright's import resolver to Rust.
The strategy taken here was to start with a more-or-less direct port of
the Pyright's TypeScript resolver. The code is intentionally similar,
and the test suite is effectively a superset of Pyright's test suite for
its own resolver. Due to the nature of the port, the code is very, very
non-idiomatic for Rust. The code is also entirely unused outside of the
test suite, and no effort has been made to integrate it with the rest of
the codebase.
Future work will include:
- Refactoring the code (now that it works) to match Rust and Ruff
idioms.
- Further testing, in practice, to ensure that the resolver can resolve
imports in a complex project, when provided with a virtual environment
path.
- Caching, to minimize filesystem lookups and redundant resolutions.
- Integration into Ruff itself (use Ruff's existing settings, find rules
that can make use of robust resolution, etc.)
2023-06-27 12:15:07 -04:00
Ruff's import resolver is based on the import resolution algorithm from [Pyright ](https://github.com/microsoft/pyright ).
2023-02-14 19:25:07 -05:00
Ruff is also influenced by a number of tools outside the Python ecosystem, like
[Clippy ](https://github.com/rust-lang/rust-clippy ) and [ESLint ](https://github.com/eslint/eslint ).
2023-06-08 21:13:40 +05:30
Ruff is the beneficiary of a large number of [contributors ](https://github.com/astral-sh/ruff/graphs/contributors ).
2023-02-14 22:15:38 -05:00
2023-02-14 19:25:07 -05:00
Ruff is released under the MIT license.
2024-08-26 08:12:35 +01:00
## Who's Using Ruff?<a id="whos-using-ruff"></a>
2023-02-17 08:36:32 -05:00
2023-04-04 22:40:02 -04:00
Ruff is used by a number of major open-source projects and companies, including:
2023-02-17 08:36:32 -05:00
2025-09-15 15:59:43 +02:00
- [Albumentations ](https://github.com/albumentations-team/AlbumentationsX )
2023-04-04 22:40:02 -04:00
- Amazon ([AWS SAM ](https://github.com/aws/serverless-application-model ))
2025-07-01 12:44:04 -03:00
- [Anki ](https://apps.ankiweb.net/ )
2023-07-04 22:09:50 -04:00
- Anthropic ([Python SDK ](https://github.com/anthropics/anthropic-sdk-python ))
2023-02-27 16:14:05 +01:00
- [Apache Airflow ](https://github.com/apache/airflow )
2023-04-04 22:40:02 -04:00
- AstraZeneca ([Magnus ](https://github.com/AstraZeneca/magnus-core ))
- [Babel ](https://github.com/python-babel/babel )
2023-11-14 15:38:12 +01:00
- Benchling ([Refac ](https://github.com/benchling/refac ))
2023-02-27 16:14:05 +01:00
- [Bokeh ](https://github.com/bokeh/bokeh )
2025-07-09 20:50:27 -03:00
- Capital One ([datacompy ](https://github.com/capitalone/datacompy ))
2024-10-28 15:53:37 +01:00
- CrowdCent ([NumerBlox ](https://github.com/crowdcent/numerblox )) <!-- typos: ignore -->
2023-04-04 22:40:02 -04:00
- [Cryptography (PyCA) ](https://github.com/pyca/cryptography )
2024-01-02 23:47:22 +01:00
- CERN ([Indico ](https://getindico.io/ ))
2023-05-12 14:02:13 -04:00
- [DVC ](https://github.com/iterative/dvc )
2023-02-27 16:14:05 +01:00
- [Dagger ](https://github.com/dagger/dagger )
2023-04-04 22:40:02 -04:00
- [Dagster ](https://github.com/dagster-io/dagster )
2023-07-04 22:09:50 -04:00
- Databricks ([MLflow ](https://github.com/mlflow/mlflow ))
2024-07-31 20:56:52 +08:00
- [Dify ](https://github.com/langgenius/dify )
2023-04-04 22:40:02 -04:00
- [FastAPI ](https://github.com/tiangolo/fastapi )
2024-05-31 21:33:39 +02:00
- [Godot ](https://github.com/godotengine/godot )
2023-04-04 22:40:02 -04:00
- [Gradio ](https://github.com/gradio-app/gradio )
- [Great Expectations ](https://github.com/great-expectations/great_expectations )
2023-07-06 09:52:28 -04:00
- [HTTPX ](https://github.com/encode/httpx )
2023-11-14 15:38:12 +01:00
- [Hatch ](https://github.com/pypa/hatch )
- [Home Assistant ](https://github.com/home-assistant/core )
2023-05-28 22:45:56 -04:00
- Hugging Face ([Transformers ](https://github.com/huggingface/transformers ),
2023-07-13 12:32:59 -04:00
[Datasets ](https://github.com/huggingface/datasets ),
[Diffusers ](https://github.com/huggingface/diffusers ))
2024-07-21 12:17:24 -04:00
- IBM ([Qiskit ](https://github.com/Qiskit/qiskit ))
2023-07-06 17:55:27 +02:00
- ING Bank ([popmon ](https://github.com/ing-bank/popmon ), [probatus ](https://github.com/ing-bank/probatus ))
2023-04-04 22:40:02 -04:00
- [Ibis ](https://github.com/ibis-project/ibis )
2024-01-31 20:39:26 +05:30
- [ivy ](https://github.com/unifyai/ivy )
2025-02-08 11:45:30 -05:00
- [JAX ](https://github.com/jax-ml/jax )
2023-02-27 16:14:05 +01:00
- [Jupyter ](https://github.com/jupyter-server/jupyter_server )
2024-03-03 02:02:59 +02:00
- [Kraken Tech ](https://kraken.tech/ )
2023-04-04 22:40:02 -04:00
- [LangChain ](https://github.com/hwchase17/langchain )
2023-11-14 15:38:12 +01:00
- [Litestar ](https://litestar.dev/ )
2023-04-04 22:40:02 -04:00
- [LlamaIndex ](https://github.com/jerryjliu/llama_index )
- Matrix ([Synapse ](https://github.com/matrix-org/synapse ))
- [MegaLinter ](https://github.com/oxsecurity/megalinter )
2023-07-04 22:09:50 -04:00
- Meltano ([Meltano CLI ](https://github.com/meltano/meltano ), [Singer SDK ](https://github.com/meltano/sdk ))
2023-05-28 22:45:56 -04:00
- Microsoft ([Semantic Kernel ](https://github.com/microsoft/semantic-kernel ),
2023-07-13 12:32:59 -04:00
[ONNX Runtime ](https://github.com/microsoft/onnxruntime ),
[LightGBM ](https://github.com/microsoft/LightGBM ))
2024-05-07 20:00:08 -04:00
- Modern Treasury ([Python SDK ](https://github.com/Modern-Treasury/modern-treasury-python ))
2023-07-04 22:09:50 -04:00
- Mozilla ([Firefox ](https://github.com/mozilla/gecko-dev ))
- [Mypy ](https://github.com/python/mypy )
2024-05-23 21:50:17 +02:00
- [Nautobot ](https://github.com/nautobot/nautobot )
2023-04-04 22:40:02 -04:00
- Netflix ([Dispatch ](https://github.com/Netflix/dispatch ))
- [Neon ](https://github.com/neondatabase/neon )
2024-03-18 16:43:22 +01:00
- [Nokia ](https://nokia.com/ )
2023-10-26 03:03:04 +08:00
- [NoneBot ](https://github.com/nonebot/nonebot2 )
2024-01-11 16:16:15 +01:00
- [NumPyro ](https://github.com/pyro-ppl/numpyro )
2023-02-27 16:14:05 +01:00
- [ONNX ](https://github.com/onnx/onnx )
- [OpenBB ](https://github.com/OpenBB-finance/OpenBBTerminal )
2024-06-21 12:59:40 -07:00
- [Open Wine Components ](https://github.com/Open-Wine-Components/umu-launcher )
2023-04-04 22:40:02 -04:00
- [PDM ](https://github.com/pdm-project/pdm )
- [PaddlePaddle ](https://github.com/PaddlePaddle/Paddle )
- [Pandas ](https://github.com/pandas-dev/pandas )
2023-11-06 20:59:06 +02:00
- [Pillow ](https://github.com/python-pillow/Pillow )
2023-04-25 01:48:35 +02:00
- [Poetry ](https://github.com/python-poetry/poetry )
2023-04-04 22:40:02 -04:00
- [Polars ](https://github.com/pola-rs/polars )
- [PostHog ](https://github.com/PostHog/posthog )
2023-04-24 18:49:12 -05:00
- Prefect ([Python SDK ](https://github.com/PrefectHQ/prefect ), [Marvin ](https://github.com/PrefectHQ/marvin ))
2023-04-14 12:41:22 -04:00
- [PyInstaller ](https://github.com/pyinstaller/pyinstaller )
2024-01-11 16:16:15 +01:00
- [PyMC ](https://github.com/pymc-devs/pymc/ )
2023-11-14 15:38:12 +01:00
- [PyMC-Marketing ](https://github.com/pymc-labs/pymc-marketing )
2024-02-02 11:26:30 +00:00
- [pytest ](https://github.com/pytest-dev/pytest )
2023-05-12 14:02:13 -04:00
- [PyTorch ](https://github.com/pytorch/pytorch )
- [Pydantic ](https://github.com/pydantic/pydantic )
2023-02-27 16:14:05 +01:00
- [Pylint ](https://github.com/PyCQA/pylint )
2023-12-28 23:16:46 +09:00
- [PyVista ](https://github.com/pyvista/pyvista )
2023-07-19 12:46:49 -04:00
- [Reflex ](https://github.com/reflex-dev/reflex )
2023-11-17 15:13:50 +01:00
- [River ](https://github.com/online-ml/river )
2023-08-31 11:36:48 -07:00
- [Rippling ](https://rippling.com )
2023-04-18 16:51:20 +03:00
- [Robyn ](https://github.com/sansyrox/robyn )
2023-04-04 22:40:02 -04:00
- [Saleor ](https://github.com/saleor/saleor )
2023-11-14 15:38:12 +01:00
- Scale AI ([Launch SDK ](https://github.com/scaleapi/launch-python-client ))
2023-04-04 22:40:02 -04:00
- [SciPy ](https://github.com/scipy/scipy )
2023-11-14 15:38:12 +01:00
- Snowflake ([SnowCLI ](https://github.com/Snowflake-Labs/snowcli ))
2023-04-04 22:40:02 -04:00
- [Sphinx ](https://github.com/sphinx-doc/sphinx )
- [Stable Baselines3 ](https://github.com/DLR-RM/stable-baselines3 )
2023-11-14 15:38:12 +01:00
- [Starlette ](https://github.com/encode/starlette )
2024-06-11 17:14:23 +02:00
- [Streamlit ](https://github.com/streamlit/streamlit )
2023-04-04 22:40:02 -04:00
- [The Algorithms ](https://github.com/TheAlgorithms/Python )
- [Vega-Altair ](https://github.com/altair-viz/altair )
2025-07-04 16:24:44 -03:00
- [Weblate ](https://weblate.org/ )
2023-04-04 22:40:02 -04:00
- WordPress ([Openverse ](https://github.com/WordPress/openverse ))
- [ZenML ](https://github.com/zenml-io/zenml )
- [Zulip ](https://github.com/zulip/zulip )
2023-02-27 16:14:05 +01:00
- [build (PyPA) ](https://github.com/pypa/build )
2023-04-04 22:40:02 -04:00
- [cibuildwheel (PyPA) ](https://github.com/pypa/cibuildwheel )
- [delta-rs ](https://github.com/delta-io/delta-rs )
2023-02-27 16:14:05 +01:00
- [featuretools ](https://github.com/alteryx/featuretools )
- [meson-python ](https://github.com/mesonbuild/meson-python )
2023-03-16 19:32:17 -04:00
- [nox ](https://github.com/wntrblm/nox )
2023-07-04 22:09:50 -04:00
- [pip ](https://github.com/pypa/pip )
2023-02-17 08:36:32 -05:00
2023-05-12 13:58:29 -04:00
### Show Your Support
2024-02-02 08:09:19 -07:00
If you're using Ruff, consider adding the Ruff badge to your project's `README.md` :
2023-05-12 13:58:29 -04:00
```md
2023-07-25 18:25:46 -07:00
[](https://github.com/astral-sh/ruff)
2023-05-12 13:58:29 -04:00
```
...or `README.rst` :
```rst
2023-07-25 18:25:46 -07:00
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
2023-06-08 21:13:40 +05:30
:target: https://github.com/astral-sh/ruff
2023-05-12 13:58:29 -04:00
:alt: Ruff
```
...or, as HTML:
```html
2023-07-25 18:25:46 -07:00
< 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 >
2023-05-12 13:58:29 -04:00
```
2024-08-26 08:12:35 +01:00
## License<a id="license"></a>
2022-08-28 14:21:44 -04:00
2024-04-25 22:46:47 -04:00
This repository is licensed under the [MIT License ](https://github.com/astral-sh/ruff/blob/main/LICENSE )
2023-05-12 15:27:38 -04:00
< div align = "center" >
< a target = "_blank" href = "https://astral.sh" style = "background:none" >
2024-02-02 08:09:19 -07:00
< img src = "https://raw.githubusercontent.com/astral-sh/ruff/main/assets/svg/Astral.svg" alt = "Made by Astral" >
2023-05-12 15:27:38 -04:00
< / a >
< / div >