{"id":1518,"library":"jsbeautifier","title":"JSBeautifier Python Library","description":"jsbeautifier is the official Python wrapper for the popular js-beautify project, providing JavaScript, HTML, and CSS code formatting and beautification capabilities. It is actively maintained with releases typically aligning with the core JavaScript library, currently at version 1.15.4.","status":"active","version":"1.15.4","language":"en","source_language":"en","source_url":"https://github.com/beautify-web/js-beautify","tags":["javascript","html","css","code formatting","beautifier","linter"],"install":[{"cmd":"pip install jsbeautifier","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"beautify","correct":"from jsbeautifier import beautify"},{"symbol":"html_beautify","correct":"from jsbeautifier import html_beautify"},{"symbol":"css_beautify","correct":"from jsbeautifier import css_beautify"},{"symbol":"default_options","correct":"from jsbeautifier import default_options"}],"quickstart":{"code":"import jsbeautifier\n\n# Example for JavaScript beautification\njs_code = \"function test( ){ var x=1;if(x){ return x;} else { return 0;}}\"\n\n# Create and customize options object\noptions = jsbeautifier.default_options()\noptions.indent_size = 2\noptions.space_in_paren = True\noptions.keep_array_indentation = True\n\nbeautified_js = jsbeautifier.beautify(js_code, options)\n\nprint(\"Original JS:\\n\", js_code)\nprint(\"\\nBeautified JS:\\n\", beautified_js)\n\n# Example for HTML beautification (using the same options)\nhtml_code = \"<html><head><title>Test</title></head><body><h1>Hello</h1>  <p>World</p></body></html>\"\nbeautified_html = jsbeautifier.html_beautify(html_code, options)\n\nprint(\"\\nOriginal HTML:\\n\", html_code)\nprint(\"\\nBeautified HTML:\\n\", beautified_html)","lang":"python","description":"This quickstart demonstrates how to beautify JavaScript and HTML code using `jsbeautifier`. It shows how to import the necessary functions, create and customize an options object, and apply it to format code strings."},"warnings":[{"fix":"Ensure your environment uses Python 3.7 or higher. Always consult the `python_requires` metadata in the official source distribution or `pyproject.toml` for the most accurate requirement.","message":"The PyPI metadata for `jsbeautifier` incorrectly states `requires_python: None`. The actual minimum Python version required by `jsbeautifier` 1.15.4 and newer is Python 3.7.","severity":"gotcha","affected_versions":"1.15.4+"},{"fix":"Create an options object: `opts = jsbeautifier.default_options(); opts.indent_size = 4; beautified = jsbeautifier.beautify(code, opts)`.","message":"Beautifier options must be passed as an `options` object, typically initialized via `jsbeautifier.default_options()`, rather than directly as keyword arguments to `beautify()`, `html_beautify()`, or `css_beautify()`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always consult the changelog of the main `beautify-web/js-beautify` GitHub repository for potential behavioral changes or deprecations when upgrading `jsbeautifier`.","message":"The `jsbeautifier` Python package's version directly reflects the version of the underlying `js-beautify` JavaScript project. Breaking changes in the core `js-beautify` library will implicitly affect the Python wrapper, even if the Python API surface itself doesn't change.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}