Python Whitespace Formatter: Indentation and Blank Lines (No Ruff)
Normalises Python indentation, trailing spaces and blank lines around functions and classes.
Use the tool
Why this tool exists
Mixed tabs and spaces break Python, and pasted code often has uneven blank lines. The tool maps whatever indents it finds onto one level per step, keeps continuation lines inside brackets in step with their statement, leaves triple-quoted strings alone and puts two blank lines around top-level defs and classes and one around methods.
It does not change quotes, spacing around operators or line length, so it is not Black or Ruff. To check it, 465 standard library files were formatted and parsed again: the syntax tree was identical for all of them, as it was for 60 files whose indents were first turned into tabs and odd widths.
How to use it
- Paste Python code.
- Choose the indent and whether to add blank lines around defs.
- Copy the result.
- Use Ruff or Black for full formatting.
Frequently asked questions
Does it change my code?
No. The syntax tree stayed identical in the tests. Review the diff anyway.
Why does it not fix quotes?
That is a style rewrite and needs a real formatter.
What about comments?
They take the indent of the next statement.
Is my input sent anywhere?
No. Everything runs in your browser and nothing is uploaded.