Python Formatter & Beautifier

Format common code, data, markup, and document languages locally in your browser.

Re-indenting Python safely

Indentation is Python syntax, so this formatter never strips it: it reads the existing block structure and rewrites it with four spaces per level, converts tabs, removes trailing whitespace and limits runs of blank lines. Continuation lines inside brackets move with their statement and triple-quoted strings are not touched. A function indented with two spaces, def f(x): / if x:, comes back as if x: with return 1; the parsed program (AST) is unchanged.