jsbeautifier
The official Python port of js-beautify for beautifying, unpacking, and deobfuscating JavaScript
Repository Health
Technical Analysis
jsbeautifier is the Python implementation of the js-beautify project, living inside the js-beautify monorepo’s python/ directory alongside the original JavaScript version and a companion cssbeautifier package. It reformats minified or poorly formatted JavaScript into readable, consistently indented code, and can unpack or deobfuscate JavaScript wrapped by popular online obfuscators.
It installs a js-beautify console script for command-line use as well as an importable jsbeautifier module for programmatic beautification, making it usable both as a standalone formatting tool and as a library embedded in other Python tools — including security research scripts that need to unpack obfuscated JavaScript payloads for analysis.
What You Get
- A
js-beautifyconsole script for beautifying JavaScript files from the command line - An importable
jsbeautifierPython module for programmatic beautification inside scripts and tools - Built-in unpackers for common JavaScript obfuscation/packing schemes used by online obfuscators
- Configurable formatting options (indent size, brace style, wrap line length) matching the upstream js-beautify options
- A companion
cssbeautifierpackage in the same repository for CSS formatting
Common Use Cases
- Formatting minified or bundled JavaScript into readable code during debugging or code review
- Deobfuscating suspicious JavaScript payloads as part of malware or security analysis tooling
- Normalizing JavaScript formatting as a pre-processing step in a static analysis or linting pipeline
- Embedding a beautifier programmatically inside a build tool, IDE plugin, or code-review bot
Under The Hood
Architecture jsbeautifier lives at python/jsbeautifier inside the js-beautify monorepo and mirrors the structure of the JavaScript implementation: a core/ package handles tokenizing and output formatting, javascript/ contains the JS-specific beautifier logic, and unpackers/ implements detection and reversal of known obfuscation/packing formats, all exposed through a 300-line __init__.py that provides the public beautify()/beautify_file() functions and CLI entry point. Tech Stack Pure Python with a single runtime dependency (editorconfig) for picking up .editorconfig-based formatting defaults; the CLI is registered via console_scripts in setup-js.py as js-beautify = jsbeautifier:main. Code Quality Dedicated tests/ and unpackers/tests/ directories (including a generated/ fixture set) exercise formatting output and unpacker detection against known obfuscation patterns, and the package is kept in lockstep with the JavaScript implementation’s version and options to minimize behavioral drift between the two ports. API Design The module exposes a small, direct surface (beautify(source), beautify_file(path)) that mirrors the CLI’s options as keyword arguments, so anyone already familiar with js-beautify’s JavaScript options can use the Python port without relearning a different configuration model.