{"id":4040,"library":"htmlmin2","title":"htmlmin2","description":"An HTML Minifier, `htmlmin2` is a configurable HTML minifier with safety features. It is a fork of the `htmlmin` library, created to address compatibility issues with modern Python versions, particularly Python 3.13+. The current version is 0.1.13, released in March 2023. While functional and widely used, its release cadence is currently stalled.","status":"maintenance","version":"0.1.13","language":"en","source_language":"en","source_url":"https://github.com/wilhelmer/htmlmin/","tags":["html","minifier","minify","web","frontend","htmlmin","fork"],"install":[{"cmd":"pip install htmlmin2","lang":"bash","label":"Install `htmlmin2`"}],"dependencies":[],"imports":[{"note":"Despite being installed as `htmlmin2`, the main minification function is imported from the `htmlmin` package, as it's a direct fork retaining the original module structure.","wrong":"from htmlmin2 import minify","symbol":"minify","correct":"from htmlmin import minify"}],"quickstart":{"code":"from htmlmin import minify\n\nhtml_input = \"\"\"\n<html>\n    <head>\n        <title> Hello, World! </title>\n    </head>\n    <body>\n        <p> How are <em>you</em> doing? </p>\n    </body>\n</html>\n\"\"\"\nminified_html = minify(html_input)\nprint(minified_html)","lang":"python","description":"This example demonstrates how to minify a simple HTML string using the `minify` function. By default, it safely removes unnecessary whitespace and comments, preserving the structure and functionality of the HTML."},"warnings":[{"fix":"Use `from htmlmin import minify` after installing `htmlmin2`.","message":"The package is installed via `pip install htmlmin2`, but the main functionality is imported from the `htmlmin` module (e.g., `from htmlmin import minify`). This is due to `htmlmin2` being a fork that retained the original module name.","severity":"gotcha","affected_versions":"All versions of htmlmin2"},{"fix":"Install `htmlmin2` (`pip install htmlmin2`) instead of the original `htmlmin`.","message":"Users on Python 3.13 or newer *must* use `htmlmin2` because the original `htmlmin` library relies on the deprecated `cgi` module which was removed in Python 3.13. Attempting to use the original `htmlmin` will result in import errors.","severity":"breaking","affected_versions":"Python 3.13+"},{"fix":"Carefully test minified output when using aggressive whitespace removal options. Prefer default settings or less aggressive options unless thoroughly validated.","message":"Aggressive whitespace removal options, such as `remove_empty_space` and `remove_all_empty_space`, can lead to unintended changes in HTML rendering or JavaScript behavior, especially with inline elements or if client-side scripts depend on specific whitespace patterns. Use with caution.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that updates may be infrequent. Verify compatibility for very new Python versions if they emerge after the last `htmlmin2` release. The Python 3.2 classifier can be ignored as it is a remnant.","message":"While `htmlmin2` addresses compatibility issues with modern Python, its PyPI metadata indicates a 'Stalled' release cadence. The `Programming Language :: Python :: 3.2` classifier on PyPI is outdated; `htmlmin2` is actively used and intended for newer Python versions (3.10+).","severity":"gotcha","affected_versions":"All versions of htmlmin2"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}