Registry / serialization / htmlmin2

htmlmin2

JSON →
library0.1.13pypypi✓ verified 23d ago

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.

pip install htmlmin2
INSTALL
IMPORT
SIG · HTMLMIN2
H
htmlmin2
serializationpythonv0.1.13
Install
1.6s avg
Import
57ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.058s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.056s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minify
from htmlmin import minify
from htmlmin2 import minify
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.

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.

from htmlmin import minify html_input = """ <html> <head> <title> Hello, World! </title> </head> <body> <p> How are <em>you</em> doing? </p> </body> </html> """ minified_html = minify(html_input) print(minified_html)
htmlmin --version
Debug
Known issues
gotchaThe 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.
fix
Use `from htmlmin import minify` after installing `htmlmin2`.
affects: All versions of htmlmin2
breakingUsers 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.
fix
Install `htmlmin2` (`pip install htmlmin2`) instead of the original `htmlmin`.
affects: Python 3.13+
gotchaAggressive 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.
fix
Carefully test minified output when using aggressive whitespace removal options. Prefer default settings or less aggressive options unless thoroughly validated.
affects: All versions
gotchaWhile `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+).
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.
affects: All versions of htmlmin2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cgi'
The original `htmlmin` library, which `htmlmin2` is a fork of, depends on Python's `cgi` module. This module was removed in Python 3.13, causing installation and import failures for `htmlmin` on newer Python versions.
fix
Install `htmlmin2` instead of `htmlmin` by running `pip install htmlmin2`. `htmlmin2` was created to address this compatibility issue with modern Python versions.
ImportError: No module named 'htmlmin'
This error occurs when you have installed `htmlmin2` but are trying to import it using the package name of its predecessor, `htmlmin`.
fix
Ensure your import statements use `htmlmin2` instead of `htmlmin`, for example: `import htmlmin2` instead of `import htmlmin`. If you're using a specific function, it would be `from htmlmin2.main import minify` or `htmlmin2.minify()` if imported directly.
AttributeError: module 'htmlmin2' has no attribute 'minify'
This error happens if you try to call `htmlmin2.minify()` directly after `import htmlmin2`, but the `minify` function is located within a submodule, typically `htmlmin2.main` as seen in the original `htmlmin` library's structure.
fix
Import the `minify` function directly from its submodule: `from htmlmin2.main import minify`. Then, you can call `minify(html_content)` directly. Alternatively, if you only import `htmlmin2`, you would access it as `htmlmin2.main.minify(html_content)`.
Upgrade
Version history
0.1.13latest on PyPI · released Mar 14, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources