unmhtml
Convert MHTML files to standalone HTML with embedded CSS and resources.
Installation
pip install unmhtml
Usage
from unmhtml import MHTMLConverter
# Convert MHTML file to HTML (secure by default)
converter = MHTMLConverter()
html_content = converter.convert_file('saved_page.mhtml')
# Save as standalone HTML
with open('output.html', 'w') as f:
f.write(html_content)
# Unsafe conversion preserving original content
unsafe_converter = MHTMLConverter(
remove_javascript=False,
sanitize_css=False,
remove_forms=False,
remove_meta_redirects=False
)
html_content = unsafe_converter.convert_file('trusted_page.mhtml')
Features
- Pure Python - No external dependencies, uses only standard library
- Standalone HTML - Embeds CSS and converts resources to data URIs
- Secure by Default - All security sanitization enabled by default for safe processing
- Graceful degradation - Handles malformed MHTML files
- Memory efficient - Processes large files without excessive memory usage
Security
The library is secure by default - all security features are enabled automatically to safely display untrusted content:
Available Security Options (All Enabled by Default)
remove_javascript=True- Removes<script>tags, event handlers (onclick, onload, etc.), and convertsjavascript:URLs to safe#anchorssanitize_css=True- Removes external CSS URLs (http://,https://,//,/absolute) while preserving relative URLs (image.png,../fonts/font.woff) and data URIsremove_forms=True- Removes form elements (<form>,<input>,<textarea>,<select>) that could submit data externallyremove_meta_redirects=True- Removes dangerous meta tags (refresh redirects, set-cookie, dns-prefetch) that could be used maliciously
Requirements
- Python 3.8+
License
MIT
Metadata
Release files for unmhtml 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| unmhtml-0.3.0.tar.gz | 55.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unmhtml-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 69.7 kB
Release files / unmhtml-0.3.0.tar.gz
| Download URL | unmhtml-0.3.0.tar.gz |
|---|---|
| Size | 55.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c0209465c1840f11c0fc6d2a136ac7cd209dfbbbd3dbae9756b12c85f8ff81b
|
|
BLAKE2b-256 checksum How to use checksums |
f2d12d9a5e857b8d56d99116b5313d61349f6cf05ea0a5edf4e768b758ce828f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 23, 2026.
Transparency logRelease files / unmhtml-0.3.0-py3-none-any.whl
| Download URL | unmhtml-0.3.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b008fde92d8f070abd32d76ec323dc765e47ef429726f61d9c0c2bafb2dc06e4
|
|
BLAKE2b-256 checksum How to use checksums |
cdc48abc21707b5a1dd6f8fae2c37c4c9da68d4050426f1d53241bd527b72d6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 23, 2026.
Transparency log