---
title: "Use Ruff to lint and format Python · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/testing-and-code-quality/ruff
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use Ruff to lint and format Python

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
- Rule: Lint and format Python with Ruff, in one config section, and fail the build on either.
- Cost: Open source. MIT licence, free to use in any project.
- How: Ruff fails one test. It is still on version 0.17, first released in August 2022, so it has no five-year stable record. It passes the rest by a wide margin. Version 0.17.1 came out on 15 October 2026, and PyPI counted 89 million downloads that week. Flake8 had under 10 million. It is MIT licensed and backed by Astral. Record it as an exception with a decision record. Choose something else when a policy bars 0.x software. Flake8 with Black does the same job in two tools. It is the one formatter that [Format all code with one tool](https://agentwranglers.se/playbook/architecture/structure/one-formatter) asks for.
- Check: `ruff check .` and `ruff format --check .` both exit 0 in the build, and no other Python linter or formatter is in the dependencies.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### TOML example

```toml
# pyproject.toml
[tool.ruff]
line-length = 100

[tool.ruff.lint]
select = ["E", "F", "I", "B", "UP"]
```

### Shell example

```sh
ruff check .
ruff format --check .
```

## Sources

- [Ruff](https://docs.astral.sh/ruff/)

## Related rules

- [Format all code with one tool](https://agentwranglers.se/playbook/architecture/structure/one-formatter) in Architecture

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/testing-and-code-quality/ruff">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use ESLint and Prettier for JavaScript code](https://agentwranglers.se/playbook/stack/testing-and-code-quality/eslint-and-prettier)
- Next: [Use TypeScript in strict mode](https://agentwranglers.se/playbook/stack/testing-and-code-quality/typescript-strict)
- [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
