Registry / serialization / htmlmin

htmlmin

JSON →
library0.1.12pypypi✓ verified 23d ago

Htmlmin is a configurable Python library designed for minifying HTML, offering safety features and various options to control the minification process. It removes extra whitespace, comments, and other unneeded characters to reduce page size and improve load times. The current version is 0.1.12, released in December 2017. The original project appears to be in maintenance mode or largely inactive, leading to the creation of several forks (e.g., `htmlmin2`, `htmlmin4`) to address compatibility with newer Python versions and continued development.

pip install htmlmin
INSTALL
IMPORT
SIG · HTMLMIN
H
htmlmin
serializationpythonv0.1.12
Install
2.9s avg
Import
108ms
Disk
18MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.12 · 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
glibc
py 3.10
✓ —
✓ 3.9s
py 3.11
✓ —
✓ 2.1s
py 3.12
✓ —
✓ 3s
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 2.5s
18MB installed
● package 18MB
Code
Verified usage

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

minify
from htmlmin import minify
import htmlmin
Minifier
from htmlmin import Minifier
escape
from htmlmin import escape

This example demonstrates how to use the `htmlmin.minify` function to minify a basic HTML string, removing comments and empty spaces. The `pre` tag content is preserved by default.

import htmlmin input_html = ''' <html> <head> <title> My Page </title> </head> <body> <!-- This is a comment --> <h1> Welcome! </h1> <p> This is some text. </p> <pre> Preformatted text </pre> </body> </html> ''' minified_html = htmlmin.minify( input_html, remove_comments=True, remove_empty_space=True ) print(minified_html) # Expected output: <html><head><title>My Page</title></head><body><h1>Welcome!</h1><p>This is some text.</p><pre> Preformatted text </pre></body></html>
htmlmin --version
Debug
Known issues
breakingThe `htmlmin` library implicitly relies on Python's built-in `cgi` module, which was deprecated in Python 3.11 and removed in Python 3.13. Attempting to use `htmlmin` on Python 3.13 or newer will result in a `ModuleNotFoundError`.
fix
Consider using a maintained fork like `htmlmin2` or `htmlmin4` which address this compatibility issue, or port your code to use an alternative, actively maintained HTML minification library.
affects: Python >= 3.13
gotchaUsing `remove_all_empty_space=True` can lead to unexpected visual or functional breakage, especially with inline HTML elements. This option removes all whitespace between tags, potentially collapsing space where it is semantically important (e.g., between `<i>X</i> <i>Y</i>` becoming `<i>X</i><i>Y</i>`).
fix
Use `remove_empty_space=True` (which is safer as it primarily targets newlines) or carefully test with `remove_all_empty_space=True` and only use if you are confident in the result. Ensure essential spaces are preserved within content or explicitly protected.
affects: All versions
gotchaThe original `htmlmin` library has not seen updates since late 2017, indicating it is no longer actively maintained. This means it may not receive bug fixes, security patches, or compatibility updates for newer Python versions or HTML standards.
fix
For new projects or if encountering issues with modern Python, evaluate actively maintained forks such as `htmlmin2` (latest 0.1.13, March 2023) or `htmlmin4` (latest 0.2.15, March 2025) or other HTML minification alternatives.
affects: All versions (due to lack of future maintenance)
gotchaTo prevent `htmlmin` from minifying specific blocks of HTML, you can add a `pre` attribute to the HTML tag wrapping the content. By default, `htmlmin` will remove this `pre` attribute from the output.
fix
Wrap the content you wish to protect in an element with the `pre` attribute (e.g., `<div pre>...</div>`). If you need to keep the `pre` attribute in the output, use the `keep_pre=True` option in the `minify` function or `Minifier` class. You can also specify custom attributes via `pre_attr` and additional pre-defined tags via `pre_tags`.
affects: All versions
Upgrade
Version history
0.1.12latest on PyPI · released Dec 29, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
htmlmin — pip install htmlmin · libregistry