⚡
usefultools.dev
Py

Python Formatter – Fix Indentation & Whitespace

NOVO

Python formatter for safe whitespace cleanup: tabs to spaces, consistent indentation, PEP 8 blank lines and operator spacing, with a diff. Free, runs in your browser.

Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.

Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.

Clean-up rules

Formatted code

import os


def total(items, tax=0.2, *args, **kw):
    if tax == 0:
        return sum(items)
    result = sum(i * (1 + tax) for i in items)
    return round(result, 2)  # two decimals


class Cart:
    def __init__(self, items: list = None):
        self.items = items or []

    def add(self, item):
        self.items.append(item)


print(total([10, 20]), "a=b, c")

15 lines changed

8 lines re-indented · 4 with tabs · 22 spacing fixes · 1 trailing whitespace removed · 7 blank lines added · 3 blank lines removed

Whitespace-only clean-up. It does not wrap long lines, change quotes or reorder imports like black or ruff format would.

⚡

Exemplos rápidos

Entradas típicas e os resultados que esta ferramenta gera.

Operators
if a==b :
if a == b:
Keyword arg
f(key = 2)
f(key=2)
Annotated
def f(x: int=0):
def f(x: int = 0):
Comment
return x # note
return x # note
Comma
add(1,2)
add(1, 2)
📖

Visão geral

This Python formatter cleans up whitespace without touching anything else. It converts tab indentation to spaces and rebuilds every indentation level from the block structure, removes trailing whitespace, puts two blank lines around top-level functions and classes and one between methods, and adds the spaces PEP 8 expects around operators, after commas and before inline comments — while keeping keyword arguments like f(key=2) tight.

It is deliberately not black or ruff format. It never re-wraps long lines, never changes quotes, never reorders imports and never changes anything inside a string or comment; even trailing spaces inside a multi-line string are kept. Continuation lines inside brackets move with their statement, so aligned arguments stay aligned.

Because it uses a real Python tokenizer, unterminated strings, unbalanced brackets and inconsistent dedents are reported with a line number instead of being "fixed" into different code. A line-by-line diff shows exactly what changed. Your code never leaves the browser.

Por que usar esta ferramenta?

  • Fix mixed tabs and spaces in seconds
  • Never changes strings, quotes or line breaks
  • PEP 8 blank lines and operator spacing
  • See every change in a line diff
  • Works without installing anything
⭐

Recursos

↹

Re-indentation

Indentation is rebuilt from the block structure with 2, 4 or 8 spaces, converting tabs.

➕

Operator spacing

Spaces around =, ==, +=, ->, := and binary operators, but not around keyword arguments or unary minus.

📏

PEP 8 blank lines

Two blank lines around top-level def/class, one between methods, none right after a block header.

🧹

Trailing whitespace

Removed from code lines, never from inside multi-line strings.

🔍

Diff summary

Counts of re-indented lines, spacing fixes and blank lines, plus a full line diff.

🛑

Safe on errors

Unterminated strings or bad dedents are reported with a line number instead of guessed.

🛠️

Como usar

1

Paste your code

Paste a script or a snippet into the Python code box.

2

Choose the rules

Pick the indent size and turn individual clean-up rules on or off.

3

Review the changes

Read the summary and open Show line diff.

4

Copy or download

Press Copy or Download .py.

🤔

Perguntas frequentes