README 未说明硬件或依赖限制,但需注意默认 target-version 为 py311、line-length 为 88,与项目实际不符时需在配置中改;在 pyproject.toml 中配置时各段需加 tool.ruff 前缀,如 [tool.ruff.lint];部分新规则需开启 preview 模式才会生效
ruff
astral-shMIT活跃维护用 Rust 写成的超快 Python 代码检查与格式化工具,能替代 Flake8、Black 等,大幅缩短 lint 和格式化耗时。
An extremely fast Python linter and code formatter, written in Rust.
pip install ruff
ruff check
ruff formatREADME 未说明,纯 CPU 工具,无 GPU 或显存要求
用 Rust 写的超快 Python linter 和格式化工具,一个命令替代 Flake8、Black、isort
用 Rust 写成的超快 Python 代码检查与格式化工具,能替代 Flake8、Black 等,大幅缩短 lint 和格式化耗时。
核心能力
- 用 Rust 原生实现 900+ 条 lint 规则
- 内置缓存,跳过未改动文件避免重复分析
- 支持 --fix 自动修复,如删除未使用导入
- 与 Flake8、isort、Black 行为对齐,可直接替换
- 支持 pyproject.toml 及层级级联配置,适合 monorepo
容易踩的坑
- 0.17.4最新正式版2026-11-05 · 2026-11-05 18:53 UTC
Release Notes
Released on 2026-11-05.
Preview features
- [
flake8-logging-format] Avoid behavior changes and syntax errors in fixes (G004) (#27419) - [
security] Implementtarfile-ignore-zeros-true(#28680)
Bug fixes
- Accept a bare raise before a semicolon (#29761)
- Allow match identifiers after a semicolon (#29760)
- Fix panic on BOM-prefixed files in diagnostic renderer (#30017)
- [
flake8-simplify] Report collapsibleelifclauses after a multi-statementifbranch (SIM102) (#29814)
Rule changes
- Show more nonprinting characters in diagnostic fix diffs (#30062)
Performance
- Coalesce source slices when formatting attributes (#29841)
- Collect return statements with a statement-only visitor (#29911)
- [
pyflakes] Defer value comparisons for repeated dictionary keys (F601,F602) (#29739) - Format node fields directly when comment handling is unnecessary (#29853)
- Reduce formatter source-slice overhead (#29855)
- Reuse a callee's qualified name across lint rules (#29916)
- Skip invalid string character checks when the source contains none (#29883)
- Use a Bloom filter for formatter comment lookups (#29852)
- Use a concrete buffer for ordinary writes (#29819)
CLI
- Give
NO_COLORprecedence in Ruff and ty diagnostics (#29898) - Honor
CLICOLOR=0in Ruff and ty diagnostics (#29910)
Documentation
- Correct the documented
versionandsrcdefaults forruff-action(#29880) - [
flake8-bugbear] MakeB014example error out-of-the-box (#29941) - [
flake8-no-pep420] Document preview behavior (INP001) (#29764) - [
isort] ExpandI001documentation (#29843)
Other changes
- [syntax-errors] Extend
__debug__write check to attribute targets (#27908)
Contributors
- @fixfon
- @hirehamir
- @MichaReiser
- @saberoueslati
- @mangod12
- @Sacrimento
- @AlexWaygood
- @mulaihonglixihonglixi-web
- @adarrevah
- @charliermarsh
- @shan3520
- @halcyon-past
Install ruff 0.17.4
Install prebuilt binaries via shell script
curl --proto '=https' --tlsv1.2 -LsSf https://releases.astral.sh/github/ruff/releases/download/0.17.4/ruff-installer.sh | shInstall prebuilt binaries via powershell script
powershell -ExecutionPolicy Bypass -c "irm https://releases.astral.sh/github/ruff/releases/download/0.17.4/ruff-installer.ps1 | iex"Download ruff 0.17.4
File Platform Checksum [ruff-aarch64-apple-darw - [
- 0.17.32026-10-27 · 2026-10-27 00:35 UTC
查看更新说明
Release Notes
Released on 2026-10-26.
Preview features
- [
suspicious] Addshared-clock-mock(#29074)
Bug fixes
- [
pyupgrade] Avoid incorrect conversions to f-strings (UP032) (#25485)
Performance
- Buffer stdout in
ruff format(#29631) - Specialize ASCII identifier lexing (#29503)
- Speed up identifier and keyword lexing (#29463)
Documentation
- [
flake8-bandit] Describe what the rule actually checks forhttpx(S113) (#27936)
Contributors
Install ruff 0.17.3
Install prebuilt binaries via shell script
curl --proto '=https' --tlsv1.2 -LsSf https://releases.astral.sh/github/ruff/releases/download/0.17.3/ruff-installer.sh | shInstall prebuilt binaries via powershell script
powershell -ExecutionPolicy Bypass -c "irm https://releases.astral.sh/github/ruff/releases/download/0.17.3/ruff-installer.ps1 | iex"Download ruff 0.17.3
File Platform Checksum ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum ruff-i686-pc-windows-msvc.zip x86 Windows checksum ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum ruff-riscv64gc-unknown-linux-gnu.tar.gz RISCV Linux checksum [ruff-s390x-unknown-linux-gnu.tar.gz](https://releases.astral.sh/git - [
- 0.17.22026-10-22 · 2026-10-22 18:39 UTC
查看更新说明
Release Notes
Released on 2026-10-22.
Preview features
- [
complexity] Addunnecessary-regular-expression-compile(#25533)
Bug fixes
- Avoid syntax errors for type variables with starred constraints (
UP040,UP046,UP047,RUF053) (#28362) - [
pydocstyle] Treat backslash-escaped*argsand**kwargsas documented (D417) (#29536) - [
pylint] Avoid false positive on starred elements (PLE0643) (#29483) - [
pylint] Mark fixes unsafe when deleting comments (PLR5501,PLW0120) (#29414) - [
pyupgrade] Mark fix unsafe when deleting comments (UP035) (#29413)
Performance
- Avoid intermediate names in lint name resolution (#29506)
- Prefilter bidirectional Unicode checks by UTF-8 leading bytes (#29561)
- Share postfix parsing and reduce expression copies (#29480)
Configuration
- [
pylint] Add a configurable allowlist formagic-value-comparison(PLR2004) (#18961)
Documentation
- Clarify documentation and correct stale guidance (#29374)
- [
pyupgrade] Remove mentions of variance related to fix safety (UP040,UP047) (#29592)
Contributors
- @fixfon
- @MichaReiser
- @zaniebot
- @FrancescoPezzella
- @anishgirianish
- @rajveer3x
- @charliermarsh
- @LckyLike
- @DaniBodor
Install ruff 0.17.2
Install prebuilt binaries via shell script
curl --proto '=https' --tlsv1.2 -LsSf https://releases.astral.sh/github/ruff/releases/download/0.17.2/ruff-installer.sh | shInstall prebuilt binaries via powershell script
powershell -ExecutionPolicy Bypass -c "irm https://releases.astral.sh/github/ruff/releases/download/0.17.2/ruff-installer.ps1 | iex"Download ruff 0.17.2
File Platform Checksum ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum ruff-i686-pc-windows-msvc.zip x86 Windows checksum ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum [ruff-aarch64-unknown-lin - [
- 0.17.12026-10-15 · 2026-10-15 15:24 UTC
查看更新说明
Release Notes
Released on 2026-10-15.
Preview features
- [
pycodestyle] Don't treatNone,True, orFalseas keywords (E271-E274) (#29322)
Bug fixes
- Fix dedent with multiple leading comments (#29382)
- [
flake8-pyi] Detect legacy positional-only parameters in__new__methods (PYI063) (#28502) - [
flake8-pyi] Fix false positives on quoted annotations (PYI036) (#29274) - [
perflint] Avoid invalid comprehension suggestions (PERF401,PERF403) (#29366)
Rule changes
- Treat more
collectionsandweakrefcontainers as mutable (#29213)
Documentation
- [
flake8-import-conventions] Update default and examplealiases(#29333)
Contributors
Install ruff 0.17.1
Install prebuilt binaries via shell script
curl --proto '=https' --tlsv1.2 -LsSf https://releases.astral.sh/github/ruff/releases/download/0.17.1/ruff-installer.sh | shInstall prebuilt binaries via powershell script
powershell -ExecutionPolicy Bypass -c "irm https://releases.astral.sh/github/ruff/releases/download/0.17.1/ruff-installer.ps1 | iex"Download ruff 0.17.1
File Platform Checksum ruff-aarch64-apple-darwin.tar.gz Apple Silicon macOS checksum ruff-x86_64-apple-darwin.tar.gz Intel macOS checksum ruff-aarch64-pc-windows-msvc.zip ARM64 Windows checksum ruff-i686-pc-windows-msvc.zip x86 Windows checksum ruff-x86_64-pc-windows-msvc.zip x64 Windows checksum ruff-aarch64-unknown-linux-gnu.tar.gz ARM64 Linux checksum ruff-i686-unknown-linux-gnu.tar.gz x86 Linux checksum ruff-powerpc64le-unknown-linux-gnu.tar.gz PPC64LE Linux checksum [ru - [
- 0.17.02026-10-09 · 2026-10-09 19:48 UTC
查看更新说明
Release Notes
Released on 2026-10-09.
The executables in our macOS and Windows release archives and
ruffwheels are now code-signed. macOS executables are signed with an Apple Developer ID certificate and notarized by Apple. Windows executables have timestamped Authenticode signatures from Azure Artifact Signing. This enables verification of the release publisher and binary integrity, supports publisher-based allowlisting, and should reduce security warnings and antivirus false positives.Breaking changes
-
Update the default and latest Python versions for 3.15 (#28792)
Ruff now defaults to Python 3.11 instead of 3.10 when no Python version is configured through
target-versionorrequires-python. When checking for syntax errors without a configured Python version, Ruff now defaults to Python 3.15 instead of 3.14. -
Update the default rule set (#28786)
Several of the
flake8-datetimezrules (DTZ001,DTZ005,DTZ006,DTZ007,DTZ011,DTZ012, andDTZ901) are no longer enabled by default, whileundefined-local-with-nested-import-star-usage(F406), which corresponds to a syntax error, is now enabled by default. -
Update Rust crate quick-junit to 0.8.0 (#27295)
JUnit output now uses a
skippedattribute instead ofdisabledon<testsuite>elements and includes askippedattribute on the root<testsuites>element. -
[
flake8-import-conventions] Adddatetime as dtas a conventional alias (ICN001) (#28790) -
Support Unicode dummy variable names (#28722)
The default
lint.dummy-variable-rgxnow recognizes underscore-prefixed Unicode names, such as_次, as dummy variables. -
Update to Unicode 17 (#21229, #28784)
Ruff now uses Unicode 17 data for identifier normalization and named character escapes (
"\N{...}"). -
Always show unsafe and display-only fixes in the CLI (#27810)
The default
fulloutput format now shows unsafe fixes and suggestions requiring manual review, regardless of theunsafe-fixessetting. Actually applying unsafe fixes still requires explicit opt-in. -
Remove the Python dependency from conda-forge builds (conda-forge/ruff-feedstock#361)
The conda-forge build no longer depends on Python, now supports linux-riscv64, win-arm64, and linux-ppc64le platforms, and now includes shell completions. However, no longer depending on Python means that
python -m ruffandimport ruffwill no longer work. Useruffdirectly fromPATHinstead. PyPI installations and those from the standalone installer are unaffected. -
Remove support for ruff-lsp (#28750)
Support for
ruff-lsp, the legacy Python language server [deprecated in Ruff v0.9.5](h
-
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Ruff
An extremely fast Python linter and code formatter, written in Rust.
- ⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)
- 🐍 Installable via
pip - 🛠️
pyproject.tomlsupport - 🤝 Python 3.15 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 900 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 actively developed and used in major open-source projects like:
Ruff is backed by Astral, the creators of uv and ty.
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 (also here):
This is just ridiculously fast...
ruffis amazing.
Table of Contents
For more, see the documentation.
Getting Started
For more, see the documentation.
Installation
Ruff is available as ruff on PyPI.
Invoke Ruff directly with uvx:
uvx [email protected] check # Lint all files in the current directory.
uvx [email protected] format # Format all files in the current directory.
Or install Ruff with uv (recommended), pip, or pipx:
# With uv.
uv tool install ruff@latest # Install Ruff globally.
uv add --dev ruff # Or add Ruff to your project.
# With pip.
pip install ruff
# With pipx.
pipx install ruff
Starting with version 0.5.0, Ruff can be installed with our standalone installers:
# 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.
curl -LsSf https://astral.sh/ruff/0.17.4/install.sh | sh
powershell -c "irm https://astral.sh/ruff/0.17.4/install.ps1 | iex"
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.17.4
hooks:
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format
Ruff can also be used as a VS Code extension or with various other editors.
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@v4
- uses: astral-sh/ruff-action@v3
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).
For the complete list of enabled rules, see Default Rules.
If left unspecified, Ruff's default configuration is equivalent to the following ruff.toml file:
# 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.11
target-version = "py311"
[lint]
# select = [...] # See the Default Rules page for the full listing.
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[\\p{XID_Continue}]*[\\p{XID_Continue}--_]+?))$"
[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"
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:
ruff check --select F401 --select F403 --quiet
The remaining configuration options can be provided through a catch-all --config argument:
ruff check --config "lint.per-file-ignores = {'some_file.py' = ['F841']}"
To opt in to the latest lint rules, formatter style changes, interface updates, and more, enable
preview mode 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.
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 900 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 rules from the F, E, B, UP, and RUF categories,
as well as many more, 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. See Default Rules for the complete list.
Beyond the defaults, Ruff re-implements some of the most popular Flake8 plugins and related code quality tools, including:
- autoflake
- eradicate
- flake8-2020
- flake8-annotations
- flake8-async
- flake8-bandit (#1646)
- flake8-blind-except
- flake8-boolean-trap
- flake8-bugbear
- flake8-builtins
- flake8-commas
- flake8-comprehensions
- flake8-copyright
- flake8-datetimez
- flake8-debugger
- flake8-django
- flake8-docstrings
- flake8-eradicate
- flake8-errmsg
- flake8-executable
- flake8-future-annotations
- flake8-gettext
- flake8-implicit-str-concat
- flake8-import-conventions
- flake8-logging
- flake8-logging-format
- flake8-no-pep420
- flake8-pie
- flake8-print
- flake8-pyi
- flake8-pytest-style
- flake8-quotes
- flake8-raise
- flake8-return
- flake8-self
- flake8-simplify
- flake8-slots
- flake8-super
- flake8-tidy-imports
- flake8-todos
- flake8-type-checking
- flake8-use-pathlib
- flynt (#2102)
- isort
- mccabe
- pandas-vet
- pep8-naming
- pydocstyle
- pygrep-hooks
- pylint-airflow
- pyupgrade
- tryceratops
- yesqa
For the complete list of 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.
Show Your Support
If you're using Ruff, consider adding the Ruff badge to your project's README.md:
[](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
This repository is licensed under the MIT License