Python Spacing Formatter
Paste a Python snippet to normalize its leading indentation and some common spaces around operators and commas. This is a lightweight text cleanup: it does not parse Python, validate syntax, wrap long lines, sort imports or reproduce Black or Ruff. Always review the result before replacing working source code.
How to use the spacing formatter
-
1
Paste a copy
Use a copy of the snippet, especially when it contains strings, comments or unusual spacing.
-
2
Choose the output indent
Select 2, 4 or 8 spaces for each indentation level inferred from the input.
-
3
Format and compare
The tool adjusts whitespace line by line. Compare the output with the original before copying it.
What this tool actually changes
The formatter works on text one line at a time. It removes existing leading whitespace, estimates an indentation level from groups of roughly four input spaces, and rebuilds that indent with the selected width. It also standardizes spaces around common operator characters and after commas, and collapses repeated spaces in the remaining line.
| Input pattern | Typical output |
|---|---|
x=1+2 |
x = 1 + 2 |
items=[1,2,3] |
items = [1, 2, 3] |
| an indented line | same inferred level with 2, 4 or 8 spaces |
Important limitations
This is not a Python parser. It cannot tell code apart from text inside a string or comment, and it does not understand unary operators, slices, type annotations, continuation lines or the special spacing rules used by full formatters. A spacing change can therefore alter a string literal or produce invalid code. The tool also does not check that the input was valid before formatting.
For production projects, run Black or ruff format locally, where the formatter can parse the whole file and your tests can verify the result. This page is best for a quick visual cleanup of a small, simple example.
Privacy and handling
Formatting is performed by the site when you submit the snippet. Do not paste passwords, private keys, access tokens or confidential source code. Use a local formatter for sensitive material.
Frequently Asked Questions
No. It is a small whitespace normalizer and does not parse an abstract syntax tree or implement those formatters’ rules.
No. The result may still contain errors, so run Python, a linter and your tests after making changes.
Yes. Because it works on plain text, its spacing rules may also affect strings and comments. Review the diff carefully.
Related Tools
ASCII Table Reference
Full ASCII table from 0 to 127 with decimal, hex, octal, binary, standard names and HTML numeric-reference notation, including NUL, LF and DEL.
Color Palette Generator
Generate monochromatic, analogous, complementary, triadic or tetradic color palettes from a base HEX color and export copy-ready CSS variables.
FPS Counter
Measure browser FPS with requestAnimationFrame, smoothing, min/max frame rate, warnings and an optional graph. Runs locally with no upload or API.
HTML Character Reference
Searchable list of HTML entities, their named and numeric codes, and a one-click copy for special characters and symbols.
HEX Color Picker
Pick or enter a HEX colour and get RGB, HSL, approximate CMYK, relative luminance and contrast ratios against white and black.
Keyboard Shortcut Reference
Search documented default keyboard shortcuts for VS Code, Chrome and Bash with GNU Readline on macOS, Windows and Linux.
Tool available in other languages
- เครื่องจัดช่องว่าง Python [TH]
- Narzędzie odstępów w kodzie Python [PL]
- Trình định dạng khoảng trắng Python [VI]
- Formatador de espaçamento Python [PT]
- Python空白フォーマッター [JA]
- منسّق المسافات في Python [AR]
- Python-spatieformatter [NL]
- Python 공백 포매터 [KO]
- Formateador de espacios para Python [ES]
- Python-verktyg för indrag och blanksteg [SV]
- Pemformat Spasi Python [ID]
- Outil d'espacement Python [FR]
- Python-Abstandsformatierer [DE]
- Formattatore di spazi Python [IT]
- Форматирование пробелов в Python [RU]
- Python boşluk düzenleyici [TR]
- Python 空格格式化工具 [ZH]