Python Indentation Fixer
Clean up messy Python indentation — convert tabs and spaces, fix mixed indentation and normalise every block to a consistent width.
🔒 Runs entirely in your browser — nothing you type is uploaded or stored on a server.
The Python Indentation Fixer re-indents messy Python so every block lines up consistently. Paste code with a mix of tabs and spaces, two-space here and four-space there, or a stray level pasted in from somewhere else, and the tool rebuilds the indentation to a single clean width — 4 spaces by default, as PEP 8 recommends. It is the fastest way to kill a TaskError: inconsistent use of tabs and spaces without hand-fixing every line.
It works by reading the structure of your code, not just find-and-replacing whitespace. The tool tracks each block's nesting depth — following colons, brackets, backslash continuations and triple-quoted strings — and re-emits each line at the right level using your chosen unit. Because it understands strings and continuation lines, indentation inside a multi-line string or a wrapped function call is left untouched, so it never corrupts your data.
Choose your target: 4, 2 or 8 spaces, or tabs, and tell it how wide your existing tabs should count. It converts tabs to spaces or spaces to tabs, strips trailing whitespace, and reports what it changed — mixed indentation found, odd levels aligned, lines touched. Everything runs in your browser, so proprietary code never leaves your machine. For a before-and-after view, drop the original and the fixed code into the Diff Viewer.
How to use
- Paste your Python code into the box.
- Choose what to re-indent with: 4 spaces (PEP 8), 2, 8, or tabs.
- Set how wide your existing tabs should be read as, so mixed files convert correctly.
- Leave “Strip trailing spaces” on to tidy line ends, and read the status line to see what changed.
- Copy the fixed code or download it as a .py file.
Examples
A file where some lines use tabs and others spaces is rebuilt so every level is the same 4-space width — the “inconsistent use of tabs and spaces” error disappears.
Code copied from a blog or PDF often arrives with broken indentation; this normalises it back into runnable Python in one paste.
Convert an old 2-space or tab-indented module to clean 4-space indentation to match a project's style guide.
A multi-line SQL string or docstring keeps its own internal spacing — only the code's block indentation is changed.