---
source: https://iinventedlight.com/library/notes/ruff-format.md
title: "Format Python files with ruff format, following PEP 8 indentation"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Ruff docs); Public-Domain (Python PEPs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Ruff docs, The Ruff formatter; Python PEPs, PEP 8 – Style Guide for Python Code. MIT; Public-Domain."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: ruff format and PEP 8"
tags: [python, ruff, formatter, pep-8, style]
client: Librarian
sources:
  - id: S1
    title: "The Ruff formatter"
    publisher: Ruff docs
    url: https://docs.astral.sh/ruff/formatter/
    accessed: 2026-11-19
    license: "MIT"
  - id: S2
    title: "PEP 8 – Style Guide for Python Code"
    publisher: Python PEPs
    url: https://peps.python.org/pep-0008/
    accessed: 2026-11-19
    license: "Public-Domain"
---
# Format Python files with ruff format, following PEP 8 indentation
**Answer:** The Ruff formatter is an extremely fast Python code formatter. It is designed as a drop-in replacement for Black and is available as part of the `ruff` CLI via `ruff format`. PEP 8 says to use 4 spaces per indentation level.

## Running the formatter

`ruff format` is the primary entrypoint to the formatter. Pass a list of files or directories; it formats all discovered Python files. With no path, it formats all files in the current directory. You can also pass a path to a file or a directory (and any subdirectories).

## Indentation and continuation lines

PEP 8 says continuation lines should align wrapped elements vertically, or using a hanging indent. When using a hanging indent, there should be no arguments on the first line. Further indentation should clearly distinguish the continuation line. The formatter is designed as a drop-in replacement for Black.

| ruff format | PEP 8 |
|---|---|
| ruff format | Primary entrypoint to the formatter |
| drop-in replacement | Designed as a replacement for Black |
| 4 spaces | Indentation level in PEP 8 |
| hanging indent | One way to align continuation lines |

## See also

- [python-f-strings](https://iinventedlight.com/library/notes/python-f-strings/)
- [python-pathlib](https://iinventedlight.com/library/notes/python-pathlib/)
- [python-list-comprehensions](https://iinventedlight.com/library/notes/python-list-comprehensions/)

## Claims

- id: C1
  claim: The Ruff formatter is a fast drop-in replacement for Black, invoked as ruff format.
  source: S1
  evidence: "designed as a drop-in replacement for Black"

- id: C2
  claim: ruff format accepts files or directories and formats discovered Python files.
  source: S1
  evidence: "It accepts a list of files or directories, and formats all discovered Python files"

- id: C3
  claim: PEP 8 uses 4 spaces per indentation level.
  source: S2
  evidence: "Use 4 spaces per indentation level"

## Sources

- [S1] The Ruff formatter. Ruff docs. https://docs.astral.sh/ruff/formatter/ . License: MIT. Accessed 2026-11-19.

- [S2] PEP 8 – Style Guide for Python Code. Python PEPs. https://peps.python.org/pep-0008/ . License: Public-Domain. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Ruff docs, The Ruff formatter; Python PEPs, PEP 8 – Style Guide for Python Code. MIT; Public-Domain. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
