Python Formatter
Reformat Python toward PEP 8 spacing and indentation conventions without changing logic.
What is Python Formatter?
A Python reformatter for the mechanical part of PEP 8: consistent indentation, no trailing whitespace, sensible blank-line runs and a space after commas. It reads the source line by line and never touches strings or comments.
How it works
The indent unit is inferred from the file (the smallest positive indent width), so a 2-space file converts to 4 spaces without changing which lines share a block. Each line is then masked — string literals and comments are replaced by placeholders, normalised and put back — which is why a comma inside a string is never rewritten.
- Paste the source. Drop in code, a stylesheet, a query or a selector list. Everything is read locally — the page never uploads what you paste.
- Choose the options. Indent width, quote style, keyword case or target browsers. The result updates as you change them, so you can see the effect immediately.
- Copy or download. Copy the result to the clipboard or download it as a file. Reset clears the form and returns every option to its default.
Examples
A file mixing tabs and spaces
Indentation becomes one consistent style, which is what keeps Python 3 from raising TabError the next time somebody opens the file.
Code pasted from a notebook cell
Notebook cells often arrive with trailing spaces and three blank lines between functions; both are normalised to the PEP 8 shape.
Common mistakes
Expecting a formatter to fix invalid code
Formatting is whitespace and quoting. A missing brace, an unclosed tag or an unquoted variable survives the round trip and is reported instead — check the findings list.
Minifying without running the tests afterwards
Even a safe, non-mangling minifier can expose an existing automatic-semicolon-insertion bug. The JavaScript Minifier keeps the newlines that matter, but re-run your tests before shipping.
Treating a rewritten query as verified
The SQL Dialect Converter translates the syntax it can prove; data types, casts and function differences are listed for review, not guessed. Run the converted query against a real database.
Renaming or reformatting generated files
Regenerating a formatter's output is a no-op only if the formatter is the same one that produced it. Keep generated code out of the round trip and format the source it came from.
Frequently asked questions
Will it wrap my long lines?
No. Line wrapping requires understanding where an expression may legally break — something only a real parser can do safely. It formats the lines you have and leaves their length to you.
Is it a replacement for Black?
No. Black re-parses the AST and reprints it, which guarantees a canonical style. This tool fixes indentation and spacing rules that can be applied line by line, and says so instead of pretending otherwise.
Could it break a multi-line string?
Triple-quoted strings spanning several lines are indentation-sensitive. The formatter masks strings, so their contents are untouched, but the leading whitespace of a continuation line inside a triple-quoted string is part of the string in some styles — check those regions after converting indentation.