Skip to content
Laviyx Learn

Try

Python Formatter

Paste Python code to format it in a consistent, PEP 8 style, and check it for common problems. Your code never leaves your browser.

The formatter engine (about 11 MB, smaller when compressed) downloads the first time you use it.

Formatted code

Formatted Python

Press Format code to see the result.

What the formatter changes

  • Indentation becomes 4 spaces, and two blank lines separate top-level functions and classes.
  • Spacing around operators, commas and colons becomes consistent (a+b → a + b).
  • Statements joined with ; or written after a colon move onto their own lines.
  • Long lines are wrapped to the chosen line length, and strings use one quote style.

Formatting never changes what your program does; it only changes how the code looks. It also cannot fix invalid Python: if there is a syntax error, the tool tells you where.

Check for problems

Check for problems runs a linter that reports PEP 8 style issues and likely bugs, such as unused imports (F401) or names that are used but never defined (F821).

About the engine

This tool uses Ruff, an open-source Python formatter and linter whose formatting is compatible with Black, the most widely used Python formatter. It runs as WebAssembly inside your browser. Using it in your own projects is easy: python -m pip install ruff, then ruff format ..

Want to understand the style rules? See Python Syntax and Comments.