Paste your code into an online Python formatter and pick a style — no install needed. The three standard tools differ: Black is opinionated and non-configurable (it even converts single quotes to double), autopep8 only fixes PEP 8 violations and otherwise leaves your style alone (least invasive), and YAPF is configurable to match a house style. I ran the same messy file through all three — the results below show exactly how they differ.
Messy indentation, missing spaces, inconsistent quotes — a formatter fixes all of it in one pass so you can stop arguing about style in code review. The three mainstream Python formatters (Black, autopep8, YAPF) each take a different philosophy, and the quickest way to use any of them is in your browser, with nothing to install.
Here's the same deliberately-messy script formatted by each one (real output, current versions), what sets them apart, and how to pick.
The same messy code, three formatters (tested)
Here's the input — bad spacing, mixed indentation, combined imports, inconsistent quotes:
import os,sysdef add(a,b) :result=a+breturn resultx = { 'a':1,'b':2 }class foo:def bar(self):return add(1,2)
Black (26.5.1) — the opinionated one. Note it rewrote the quotes to double and applied its fixed two-blank-lines-between-defs rule:
import os, sysdef add(a, b):result = a + breturn resultx = {"a": 1, "b": 2}class foo:def bar(self):return add(1, 2)
autopep8 (2.3.2) — the minimalist. It only fixes PEP 8 violations, so it split `import os,sys` into two lines but kept your single quotes and touched as little as possible:
import osimport sysdef add(a, b):result = a+breturn resultx = {'a': 1, 'b': 2}class foo:def bar(self):return add(1, 2)
YAPF (0.43.0) — the configurable one. It kept single quotes but applied its own rules (note the blank line it inserted inside the class):
import os, sysdef add(a, b):result = a + breturn resultclass foo:def bar(self):return add(1, 2)
What sets them apart
| Black | autopep8 | YAPF | |
|---|---|---|---|
| Philosophy | Opinionated, one style | Fix PEP 8 only | Configurable |
| Quotes | Rewrites to double | Left as-is | Left as-is |
| Configurable? | Barely (line length) | Aggressiveness levels | Fully (style presets) |
| Invasiveness | High (reflows everything) | Lowest | Medium |
| Best for | Teams wanting zero debate | Minimal, safe cleanup | Matching a house style |
The big practical split: Black reformats your whole file to its style (great for ending style debates, but the diff is large), while autopep8 changes only what actually violates PEP 8 (small, safe diffs on an existing codebase). YAPF sits in between and bends to a config.
Method 1 — format online (no install)
The fastest way, with nothing to set up: paste your code into the free Python Formatter, choose Black, autopep8, or YAPF, and copy the result. It runs in your browser, so your code isn't uploaded — handy for a quick cleanup or when you can't install tools on the machine you're on.
Method 2 — install and run
For your own projects, install the one you like and run it (ideally as a pre-commit hook or CI check so formatting is automatic):
# Black — opinionated, zero configpip install black && black .# autopep8 — minimal PEP 8 fixespip install autopep8 && autopep8 --in-place --recursive .# YAPF — configurablepip install yapf && yapf --in-place --recursive .
If you're also linting, Ruff now includes a Black-compatible formatter (ruff format) that's dramatically faster and covers both jobs — worth a look if you want one tool. Try it in the online Ruff linter. See also autopep8 vs Black for a deeper head-to-head.
Which should you use?
- Black — if you want to end style arguments entirely. One style, (almost) no config, huge adoption. The diff on first run is big, then never again.
- autopep8 — if you have an existing codebase and want the *smallest safe* change: it only fixes real PEP 8 violations and preserves your quotes and layout.
- YAPF — if your team has a specific house style you want enforced via config rather than accepting Black's opinions.
- Ruff format — if you want formatting *and* linting from one very fast tool (Black-compatible output).
Format your Python — free
Paste your code, pick Black, autopep8, or YAPF, and copy the clean result. In your browser, nothing uploaded.
Open the Python FormatterFree tools mentioned here
Related guides
Frequently asked questions
How do I format Python code online?
Paste your code into an online Python formatter, pick a style (Black, autopep8, or YAPF), and copy the cleaned result — no installation needed. pyobfuscate.com's formatter runs in your browser, so your code isn't uploaded. For your own projects, install the formatter (e.g. pip install black) and run it as a pre-commit hook.
What is the difference between Black, autopep8, and YAPF?
Black is opinionated and reformats your whole file to one fixed style (and rewrites single quotes to double). autopep8 only fixes actual PEP 8 violations, making the smallest, least invasive change and preserving your quotes. YAPF is configurable to match a specific house style. Black ends style debates; autopep8 gives safe minimal diffs; YAPF bends to a config.
Does Black change my quotes?
Yes. Black normalizes string quotes to double quotes by default (you can opt out with --skip-string-normalization). autopep8 and YAPF leave your existing single/double quotes as they are, which is one visible difference when you run the same file through each.
Is it safe to format code in an online tool?
It's fine as long as the formatter runs client-side so your code isn't uploaded — pyobfuscate.com's formatter processes everything in your browser. Formatting never changes behavior, only whitespace, line breaks, and (with Black) quote style, so the output runs identically to your input.
Should I use Ruff instead?
Ruff now ships a Black-compatible formatter (ruff format) alongside its very fast linter, so if you want formatting and linting from a single tool it's a strong choice. If you only need formatting and already use Black, there's no urgency to switch — the output is compatible.