Clean indentation
Rewrites your code with even indentation and one statement per line, so nested blocks line up and the structure is clear. Choose 2 or 4 spaces per level.
def f(x):return x+1Afterdef f(x):
return x + 1Paste messy Python and get it back with even indentation, clean line breaks, and consistent spacing. It uses Ruff, which follows the same style as Black. Everything runs in your browser, so your code stays on your device.
Format uses Ruff, which follows the same style as Black. Options apply to Format.
Python can end up with uneven spacing after edits, merges, or a quick copy and paste. A formatter rewrites the code with even indentation, one statement per line, and consistent spacing, so the structure is clear at a glance. It keeps the behavior of your code and only changes the layout. This tool formats your code with Ruff, which follows the same style as Black.
Rewrites your code with even indentation and one statement per line, so nested blocks line up and the structure is clear. Choose 2 or 4 spaces per level.
def f(x):return x+1Afterdef f(x):
return x + 1Make string quotes consistent. Prefer double or single quotes across the file, or leave them as written. The formatter may keep the other quote to avoid extra escapes.
name = 'Ada'Aftername = "Ada"Wrap long lines where it can, such as calls, lists, and arguments, so nothing runs off the edge. Set the width to 79, 88, 100, or 120 characters.
result = func(aaaa, bbbb, cccc, dddd, eeee, ffff, gggg)Afterresult = func(
aaaa, bbbb, cccc, dddd, eeee, ffff, gggg
)Fixes spacing around operators, commas, and colons to match the common Python style. Extra blank lines and trailing spaces are cleaned up too.
a=[1 ,2, 3]Aftera = [1, 2, 3]A formatter helps any time code is hard to read. These are the cases that come up most:
This tool formats with Ruff, which follows the same style as Black. The result is what most Python projects now expect. To format your own code:
| To | Use |
|---|---|
| Install Ruff | pip install ruff |
| Format every file | ruff format . |
| Check in CI without changing files | ruff format --check . |
| Save your settings | Set line-length under [tool.ruff] and quote-style under [tool.ruff.format] in pyproject.toml |
Ruff's default line length is 88 characters, the same as Black. Black and Ruff produce nearly identical output, so a team can switch between them without reformatting everything.
For JavaScript, use theJavaScript formatter and beautifier. For JSON data, use the JSON formatter and validator. For Bash and sh scripts, use theshell script formatter.