Python code formatter

Paste a Python script indented with tabs or an inconsistent number of spaces: the tool normalizes the indentation to a consistent 4 spaces per level, without ever touching the logical structure of the code.

Note: in Python, indentation is part of the syntax. This formatter only normalizes the width of existing indentation (like autopep8 --select=E1); it doesn't reorganize lines or expressions the way a full-featured tool such as black would.

Example:

How it works

The tool detects the indentation unit used in your script (for example 2 spaces, 3 spaces, or tabs converted to 4 spaces each) by computing the greatest common divisor of the indentation lengths found on non-empty lines. Each line is then rewritten with exactly 4 spaces per detected relative level, without changing its content or order. Blank lines and trailing whitespace are cleaned up.

Can the script's behavior change after formatting?

No, as long as the original indentation was consistent (the same unit used throughout): only the visual width of the indentation changes, never the actual nesting level of the blocks. If the source file already mixed inconsistent indentation (for example 2 spaces in one place and 3 in another), automatic detection may get it wrong: always review the result before running it.

Are tabs properly supported?

Yes: each leading tab is converted to 4 spaces before analysis, so a tab-indented script is handled exactly like a script indented with 4 spaces.

Formatting runs 100% locally in your browser: your Python code is never sent to a server.