gizmobench

Python Formatter

Paste Python and get it back formatted by Ruff 0.16.8, Astral's formatter, running in your browser as WebAssembly. Your code stays in its box as you pasted it, Ruff's output appears in its own pane, and a unified diff shows exactly which lines changed. Set the line length anywhere from 40 to 120, indent with 2, 4 or 8 spaces, and prefer single or double quotes or keep each string's own. What it does differently: it is Ruff's own formatter at one pinned version that the page names; a syntax error comes back with its line and column while your code stays untouched; and your code is never run or uploaded. The first Format downloads the 11.0 MB formatter from this site, and input is limited to 64 KiB.

0 lines, 0 bytes of 64 KiB
40 to 120
Indent (spaces)
Quotes
the code is never run

formattedappears hereRuff 0.16.8

Paste Python into the box and press Format. The first Format downloads Ruff's 11.0 MB formatter from this site; your code stays in this browser and is never run.

Formatter
Ruff 0.16.8
Settings
88 cols, 4 spaces, double quotes
Lines
0 in
Diff
not yet

Ctrl+Enter or Cmd+Enter in the box formats too. Line length is the width Ruff fits lines to, from 40 to 120 characters; indent is the spaces per level; quotes is the quote Ruff prefers for strings, where preserve leaves each string as written and a string that would need more escapes keeps the other quote, so 'it\'s' becomes "it's" even under single. After a Format, changing a setting formats the same code again. Copy takes whichever view is showing; .py saves formatted.py and .diff saves formatted.diff, a unified diff from original.py that patch applies.

What comes out

  • x={"a":1,"b":2}default settings
    x = {"a": 1, "b": 2} and a final newline
  • result = some_function(argument_one, argument_two, argument_three)line length 40
    one argument per line, with a trailing comma after the last
  • def broken(:invalid syntax
    parse error at line 1, column 12; the input is kept exactly as typed
  • The formatted output, formatted againsame settings
    identical text, an empty diff
Accuracy. The output is what Ruff 0.16.8's formatter produces for the Python syntax it supports, and it can differ from Black in places. Your code is never run, lint fixes and import sorting are not applied, and a clean format says nothing about whether the code works. If the code does not parse, or formatting fails or runs past its limits, your original text stays exactly as you entered it. Formatting is done by Ruff 0.16.8 from Astral, compiled to WebAssembly and served from this site under the MIT license (copyright Charles Marsh); the full LICENSE, with the notices of the components Ruff bundles is served beside it. Your code never leaves this page: the only downloads are Ruff's two files (11.0 MB), from this site, on your first Format. Your line length, indent, quote and view settings are kept in this browser, and the Start over button at the top of the page forgets them; your code is not saved.

Common questions

Is this the same as running ruff format?
It runs the formatter from Ruff 0.16.8, the same version on every visit, compiled to WebAssembly by Astral and loaded from this site. You choose the line length (40 to 120), the indent (2, 4 or 8 spaces) and the quote style (single, double or preserve); every other formatter option stays at Ruff's default. A project whose pyproject.toml sets other options, such as tab indentation, can therefore get different output from ruff format there. It does not lint, fix lint errors or sort imports.
Is Ruff's output the same as Black's?
Mostly. Astral describes Ruff's formatter as a drop-in replacement for Black and documents the places where the two differ, so the output can differ from Black in those places. This page shows what Ruff 0.16.8 produces and makes no claim of byte-for-byte Black output.
What happens if my code has a syntax error?
Nothing is formatted, and the code in your box is left exactly as you typed it. The page shows Ruff's parser message with the line and column and marks the spot on that line: def broken(: stops at line 1, column 12 with Expected a parameter or the end of the parameter list. Fix that spot and press Format again.
Is my code run or uploaded?
No. The code is only text handed to Ruff's formatter in a background worker on this page; Ruff parses and prints it and has no way to execute it, so a raise statement or a line that writes a file is formatted, never run. Nothing you type is sent anywhere: the only downloads are Ruff's two files from this site on the first Format. Your line length, indent, quote and view settings are saved in this browser, never the code.
How big a file can it format?
Up to 64 KiB of UTF-8, which is 65,536 bytes. It counts bytes, so an accented letter such as é takes two and most emoji take four. The formatted result may be up to 256 KiB, and each format gets 2 seconds. A very long run of semicolon-separated statements on one line can take longer than that, and very deep nesting or a very long chain of calls can exhaust Ruff's stack; in each case the page says what happened and keeps your code.
Why does it not sort my imports or remove unused ones?
Those are lint fixes in Ruff (its isort rules and F401), not formatting. This page runs only Ruff's formatter, so import order, unused imports and comparisons such as x == None are left as written, and only the layout changes.
What does the diff show?
A unified diff from original.py to formatted.py with three lines of context, in the form the patch program reads, so you can review or apply exactly the lines Ruff changed. Copy takes whichever view is showing, and .diff saves the diff as formatted.diff.

The output is what Ruff 0.16.8's formatter produces for the Python syntax it supports, and it can differ from Black in places. Your code is never run, lint fixes and import sorting are not applied, and a clean format says nothing about whether the code works. If the code does not parse, or formatting fails or runs past its limits, your original text stays exactly as you entered it.