Python Formatter
Reformat Python the way Black would - and see exactly how many lines it changed.
Your code
0 charactersFormatted
Reformat Python the way Black would - and see exactly how many lines it changed.
This runs Black - the formatter most Python projects already agree on - over whatever you paste, with the line length and quote handling you choose. If the file does not parse it says which line, and if it is already formatted it says that too rather than pretending to have done something.
Formatting Python does not require running it. The code is parsed into a syntax tree and rewritten from that tree, entirely in memory - it is never written to a file, never imported and never executed. A formatter that ran what you pasted would be a remote shell with a text box.
Black is an AST-preserving transform: the code that comes out is the same program as the code that went in. That property is the whole reason a formatter can be trusted, and it is why no language model is involved anywhere in this tool. A model asked to tidy code will occasionally rewrite a line while it is there, and a silent change to working code is the one failure a formatter cannot afford.
The same question CI asks: would this file change? Check mode returns your original code untouched and reports whether Black would have reformatted it, and by how many lines. It is the quick way to find out why a pipeline is failing on a file you cannot reproduce locally.
A comma after the last item tells Black to keep a call or collection one item per line: result = compute(alpha, beta,) comes back as four lines, with alpha, and beta, each on its own line. Tick Ignore magic trailing comma and the same input becomes result = compute(alpha, beta) whenever it fits the line length. To protect a hand-aligned block such as a matrix, put # fmt: off on the line above it and # fmt: on below it, and Black leaves everything in between as you wrote it; # fmt: skip at the end of a line protects that one line. These are Black's own comments, so they keep working when your project's CI runs Black.
It is sent to the server, formatted in memory and returned in the same response. Nothing is written to disk, cached or logged, and the usage record keeps only counts - size, options, how many lines changed - never the code.
No. Black changes layout, not behaviour, but it does more than move spaces. It removes redundant parentheses (x = (1) becomes x = 1), lower-cases number prefixes and exponents (0XABCDEF becomes 0xABCDEF, 1E5 becomes 1e5), adds a trailing comma when it splits a call over several lines, collapses runs of blank lines and trims the spaces inside a docstring (""" Doc. """ becomes """Doc."""). That last change alters the text of __doc__, which matters only if your code reads its own docstrings.
Because it was already formatted at the line length you chose. The tool says "already formatted" rather than quietly returning a copy.
No. Import sorting is isort's job, not Black's, and the two disagree often enough that doing it here would surprise you.
No formatter can - an unparseable file has no structure to rewrite. You get the line, the column and the surrounding code so you can fix it and try again.
Black is PEP 8 compatible with one well-known deviation: its default line length is 88 rather than 79. Pick 79 in the line length selector if you need the stricter figure.
Up to 400,000 characters per run. Formatting stops after 10 seconds, which only very large or deeply repetitive files reach, and each IP address can run 30 formats every 10 minutes.
This page runs Black, and its version is shown in the page header on wide screens. Black reads project settings from pyproject.toml under [tool.black], using the long option names: line-length = 88 for the "Line length" you picked, skip-string-normalization = true if you ticked "Keep my quotes", skip-magic-trailing-comma = true for "Ignore magic trailing comma", and target-version = ["py311"] for a fixed "Target". Editor plugins and the pre-commit hook read the same file. Run black . to format and black --check --diff . in CI: it changes nothing and exits with code 1 when a file would be reformatted. Pin the same Black version as this page, because the first release of each calendar year may change the stable style.
Almost always, but not byte for byte. Ruff's formatter is designed as a drop-in replacement for Black, and Ruff's documentation reports that on large Black-formatted projects such as Django and Zulip more than 99.9% of lines come out identical. It differs more on code that was never Black-formatted, especially around end-of-line comments, and its documentation lists its intentional deviations. Its default line length is also 88, set with line-length under [tool.ruff]; quote-style = "preserve" under [tool.ruff.format] matches "Keep my quotes" and skip-magic-trailing-comma = true matches "Ignore magic trailing comma". If your CI runs ruff format --check, test the file with Ruff, not with this page.