The Python packages only beautify JavaScript and CSS. HTML beautification is not supported by the Python implementation. For HTML, use the Node.js library or CLI.
Installation
Install the packages you need from PyPI:JavaScript Beautifier
Basic Usage
Beautify from a File
Custom Options
Fetch the default options object, modify the attributes you need, then pass it tobeautify:
CSS Beautifier
Basic Usage
Custom Options
CLI from Python Install
Installingjsbeautifier also installs the js-beautify command-line script. Beautified output goes to stdout by default:
Options Reference
Option names are the same as CLI flags with hyphens replaced by underscores. For example,--indent-size 2 --space-in-empty-paren corresponds to:
| Option | Default | Description |
|---|---|---|
indent_size | 4 | Spaces per indentation level |
indent_char | " " | Character used for indentation |
indent_with_tabs | False | Use tabs instead of spaces |
eol | "auto" | Line terminator character(s) (auto = detect from file, else \n) |
end_with_newline | False | End output with a newline |
preserve_newlines | True | Keep existing blank lines |
max_preserve_newlines | 10 | Maximum blank lines to preserve |
brace_style | "collapse" | Brace placement style |
space_in_paren | False | Pad inside parens: f( a, b ) |
space_in_empty_paren | False | Space inside empty parens: f( ) |
jslint_happy | False | Enable jslint-stricter mode |
wrap_line_length | 0 | Wrap lines longer than N characters |
comma_first | False | Put commas at the start of lines |