Python Formatter
Format Python source with black at a chosen line length; reports the line and column when the code does not parse.
Python is the language where a formatter cannot be a text editor. Indentation is syntax, so a re-indent that moves a block changes what the program does; comments attach to the statements around them, so the standard library's ast.unparse loses them; and implicit string concatenation, match arms and walrus assignments all have shapes a token-level rebuild gets wrong. This page runs black on the server — the formatter the Python ecosystem standardised on — and returns exactly what black . would write. When the source does not parse, the answer is black's own diagnostic with a line and a column, not a guess.
Paste Python source, choose a line length, and press the button: black runs on the tool server and returns the same program with its spacing, line breaks and string quotes rewritten to its house style.
This is a formatter, not a compiler. It changes how the file is written, not what it does: it does not type-check, does not resolve imports, does not run the code and does not rename anything. A file that is syntactically invalid is refused with black's own message instead of being half-formatted.
Four line lengths are offered — 79, 88, 100 and 120 columns — and any other value is refused rather than passed through. String normalisation can be switched off, which leaves your quote style alone while the rest is still reformatted.
What black rewrites
black parses the file, re-emits it and parses the result again before returning anything. Indentation, blank lines between top-level definitions, the wrapping of long calls and the choice between single and double quotes are its decisions, and it is deliberately opinionated about them.
Turning off string normalisation passes --skip-string-normalization, so quotes stay as written; spacing, indentation and line wrapping are still applied. Nothing else on the page is configurable, because the point of black is that a project does not argue about the rest.
- Line length: 79, 88 (default), 100 or 120
- Normalise string quotes: on by default
- Runs black in a temporary directory with no project config
What it will not do
The formatter accepts up to 200,000 characters and gives black ten seconds; a longer input or a slower run is refused with the reason. It is not a linter, so unused imports, shadowed names and type errors survive untouched.
The output is produced by the black installed on this server. A project pinned to an older black may format slightly differently, which is why the version that ran is worth checking when the output must match a repository's own CI.
How to use the formatter
Paste the source into the Python Source panel, pick a line length of 79, 88, 100 or 120 columns from the dropdown, and leave Normalise string quotes ticked unless the project keeps its own quote style. Press the format button and the Formatted panel shows black's rewrite.
When the file does not parse, the page returns black's own refusal instead of a half-formatted file; repair the syntax and run again. Compare the result with the project's configured width before pasting it back.
What to Expect
Best for
- Tidying a snippet before pasting it into a project that uses black
- Seeing how black would wrap a long call at a chosen width
- Normalising spacing without opening an editor
Not ideal for
- Finding bugs, unused imports or type errors, which need a linter and a type checker
- Formatting a file that must match a project pinned to a different black version
- Reformatting a 2 MB generated file, which exceeds the input ceiling
What this tool keeps
- The program's behaviour, because the source is parsed and re-emitted rather than text-substituted
- Comments, which black preserves
- Your quote style when normalisation is switched off
What may need cleanup
- A file that black refuses because it does not parse, which has to be fixed by hand
- Line length choice, which should match the project's configuration
- Very long string literals, which black will not split
Common errors
- Pasting JavaScript or a fragment with an unclosed bracket and reading the syntax error as a formatter bug
- Expecting import sorting, which black does not do
- Choosing a line length the page does not offer and finding the request refused
Example use cases
- Formatting a function copied out of a notebook
- Checking how a 100-column project would wrap a call
- Producing a clean snippet for a code review comment
Sample input
A five-line function with two imports on one line, a one-line loop body and single-quoted strings, formatted at 88 columns with quote normalisation on.
Sample output
The same function with the imports split, the loop body indented onto its own line, double-quoted strings and an info line reporting the width.
Who this is for
- Python developers pasting a snippet
- Reviewers preparing a minimal diff
- Students learning black's default style
Frequently asked questions
What does the Python formatter change?
black rewrites spacing, line breaks and string quotes to its house style, at the line length you choose.
Does it find bugs or unused imports?
No. It formats only; a linter and a type checker are needed for that.
What if the file does not parse?
black refuses it, and the file has to be fixed by hand before formatting can run.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.