Python formatter
Format Python in the Black style with Ruff’s formatter, compiled to WebAssembly and running in your browser. Choose line length, quotes and indentation; syntax errors are shown with their line.
Common mistakes
Pasting from an interactive session
Lines starting with >>> or In [1]: aren’t Python. Remove the prompts and the printed output first.
Mixing tabs and spaces
Python rejects indentation that mixes the two inconsistently, so the formatter reports it as an error. Re-indent the block, then format.
Being surprised by the magic trailing comma
A comma after the last item keeps a call, list or dict split one item per line. Remove the comma if you want it joined onto one line.
Expecting a linter
Unused imports, undefined names and bugs pass through untouched. Formatting only changes layout.
How it works
- 1
Paste Python
A function, a script or a module. Open or drop a .py file; nothing is uploaded.
- 2
Choose the options
“Default” is 4 spaces, as PEP 8 recommends. Set the line length (80, 100 or 120; Black’s own default is 88) and single or double quotes.
- 3
Read any error
Code that doesn’t parse isn’t formatted: you get the error and a button that jumps to its line.
Questions
- Is this the same as Black?
- Ruff’s formatter is built as a drop-in replacement for Black and gives the same output on almost all code. The few differences are documented by the Ruff project and rarely show up in everyday code.
- Does it sort imports or fix lint errors?
- No. It only formats. Sorting imports and fixing lint findings are separate Ruff commands (ruff check --fix) that don’t run here.
- Why is a line still longer than the limit?
- Like Black, Ruff doesn’t split long strings or comments, and a single long name can’t be broken. Those lines stay over the limit.
- Which Python syntax is supported?
- Current Python 3: type hints, f-strings, async and await, decorators, dataclasses, match statements and the walrus operator.