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

  1. Paste your Python code into the box.
  2. Choose what to re-indent with: 4 spaces (PEP 8), 2, 8, or tabs.
  3. Set how wide your existing tabs should be read as, so mixed files convert correctly.
  4. Leave “Strip trailing spaces” on to tidy line ends, and read the status line to see what changed.
  5. Copy the fixed code or download it as a .py file.

Examples

Mixed tabs and spaces
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.
Pasting from the web
Code copied from a blog or PDF often arrives with broken indentation; this normalises it back into runnable Python in one paste.
Switching to PEP 8
Convert an old 2-space or tab-indented module to clean 4-space indentation to match a project's style guide.
Strings stay intact
A multi-line SQL string or docstring keeps its own internal spacing — only the code's block indentation is changed.

Frequently asked questions

Can it fix any broken Python?
It fixes inconsistent and mixed indentation whenever the code's nesting is still logical (deeper blocks are more indented than their parents). It normalises each distinct indent level to your chosen width. It can't guess intent in genuinely ambiguous code, but it flags odd levels it had to align.
Does it convert tabs to spaces and back?
Yes, both directions. Pick spaces (2, 4 or 8) or tabs as the output, and set how many spaces an existing tab should count as so mixed files are measured correctly before conversion.
Will it change my strings or comments?
No. The tool tracks triple-quoted strings and line continuations, so text inside multi-line strings is preserved exactly. Comment lines are aligned to the current block.
Why 4 spaces by default?
Because PEP 8, Python's official style guide, recommends 4 spaces per indent level and spaces over tabs. You can override this to 2, 8 or tabs if your project differs.
Is this a full code formatter?
No — it focuses on indentation only, which is what actually breaks Python at runtime. For full reformatting (line length, quotes, spacing) use a dedicated formatter like Black in your editor.
Is my code uploaded?
No. All parsing and re-indentation happen in your browser, so private or proprietary code never leaves your device.