Skip to content
ToolHive

Python Formatter

Format Python in your browser with the Ruff formatter compiled to WebAssembly — a reimplementation of Black's style. Choose 2 spaces, 4 spaces or tabs, then copy or download the result. No upload, no install.

Programming Language Tools

How to use Python Formatter

  1. Paste Python into the input panel.
  2. Pick your indentation — 4 spaces is the PEP 8 convention and the default in Python projects.
  3. Press Format. The WebAssembly formatter loads on first use, then runs instantly.
  4. Copy the result or download it as formatted.py.
  5. Syntax errors are reported with the parser's own message rather than silently ignored.

Examples

Before

Inconsistent spacing and a cramped one-line body.

def load(paths,*,verbose=False):
      out=[]
      for p in paths:
          if not os.path.exists( p ): continue
      return out

After

Ruff's canonical layout, matching what Black would produce.

def load(paths, *, verbose=False):
      out = []
      for p in paths:
          if not os.path.exists(p):
              continue
      return out

Features

  • The real Ruff formatter, compiled to WebAssembly and running locally
  • Black-compatible style: consistent quotes, magic trailing commas, line wrapping
  • 2-space, 4-space or tab indentation
  • Handles decorators, dataclasses, type hints, comprehensions, async def and match statements
  • Reports genuine syntax errors instead of producing broken output
  • Copy to clipboard or download formatted.py
  • Autosaves your draft to this browser only
  • The 1.2 MB engine downloads only when you press Format

Frequently asked questions

Is this actually Black?
It is Ruff's formatter, which is a reimplementation of Black's style. Output matches Black in the overwhelming majority of real code, and the Ruff project documents the small number of deliberate differences. We say Black-style rather than Black-compatible because that is the honest description.
Does it check my code for errors?
It parses your code, so a syntax error is reported and nothing is formatted. It does not lint — unused imports, naming and type problems are a separate job.
Which Python versions are supported?
Modern Python syntax including f-strings, walrus operators, positional-only parameters, match statements and the current type-hint syntax. Python 2 code will not parse.
Why 4 spaces rather than 2?
PEP 8 specifies four spaces, and essentially the whole Python ecosystem follows it. The 2-space and tab options exist for code that has to match an existing house style.
Is my code uploaded?
No. The formatter is a WebAssembly module that runs in your browser. Your source never leaves the tab.
Why is there a short wait the first time?
The engine is about 1.2 MB and is fetched only when you press Format, so nobody browsing the rest of the site downloads it. Your browser caches it afterwards.

Related tools

About Python Formatter

Python Formatter is part of Programming Language Tools on ToolHive, a growing collection of small, focused utilities for developers, designers and students. Formatters and playgrounds for Python, C, Java, Go, Rust and SQL. Everything runs client-side, so your data never leaves the browser tab — which makes these tools safe to use with work-in-progress code and private content.