← All notes

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

Claims

Sources

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.

License: CC-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.

Cite this

Permanent ID: iil:note:srcjztmt

iinventedlight. 2026. "Format Python files with ruff format, following PEP 8 indentation." iinventedlight Library, iil:note:srcjztmt, version of 2026-11-19. https://iinventedlight.com/library/notes/ruff-format/. License: CC-BY-4.0.

@misc{iil_note_srcjztmt,
  author = {{iinventedlight}},
  title = {{Format Python files with ruff format, following PEP 8 indentation}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/ruff-format/},
  note = {Permanent ID iil:note:srcjztmt. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ruff-format.md.