Python Formatter

Paste messy Python code and get it back clean: 4-space indentation, consistent spacing, tidy line breaks. Choose Black or autopep8. The code never leaves your browser.

How to format Python online

  1. Paste your code.
  2. Pick a style. Black rewrites the layout fully. autopep8 makes smaller PEP 8 fixes.
  3. Press Format and copy the result.

The online Python formatter needs nothing installed, so you can format Python code online on any computer with a browser.

Python beautifier: what changes

This Python code formatter online is also a Python code beautifier: it changes how the code looks, not what it does.

  • Indentation becomes 4 spaces. Tabs and uneven indents are replaced.
  • Spaces around operators, commas and colons are made consistent.
  • Long lines are wrapped, extra blank lines are removed.
  • Formatting a second time changes nothing.

Format a Python dictionary or list

Need a Python pretty print online for a long dictionary or list written on one line? Paste it. Black puts each item on its own line and adds a trailing comma, so the structure is easy to read.

Indentation: what can and cannot be fixed

If your code runs but the indentation is untidy (tabs, 2 spaces, mixed widths), the formatter rewrites it to 4 spaces.

If Python cannot read the code at all (IndentationError or TabError), the formatter does not guess where a block should end. It shows the line and the reason, and you fix that line by hand. A tool that guesses can silently change what the program does.

FAQ

Which formatter is used?

Black 26.10.1 by default. autopep8 2.3.2 is the alternative for smaller changes.

Will formatting change what my code does?

No. The page compares the code structure before and after formatting and shows the result only if it is the same.

Will it fix my IndentationError?

Not automatically. It shows the line with the problem. Code that Python can read gets its indentation normalized.

Is my code uploaded?

No. Formatting happens in your browser.

Can I change the line length?

Not yet. Black's default of 88 characters is used.

My code does not format. Why?

It has a syntax error. Open it in the Python Code Checker to see the line.