MHTML to HTML converter library using Python stdlib
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unmhtml-0.3.0.tar.gz.
File metadata
- Download URL: unmhtml-0.3.0.tar.gz
- Upload date:
- Size: 55.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c0209465c1840f11c0fc6d2a136ac7cd209dfbbbd3dbae9756b12c85f8ff81b
|
|
| MD5 |
1f8137667428e84c9f420923198f5ea4
|
|
| BLAKE2b-256 |
f2d12d9a5e857b8d56d99116b5313d61349f6cf05ea0a5edf4e768b758ce828f
|
Provenance
The following attestation bundles were made for unmhtml-0.3.0.tar.gz:
Publisher:
publish.yml on opensanctions/unmhtml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unmhtml-0.3.0.tar.gz -
Subject digest:
8c0209465c1840f11c0fc6d2a136ac7cd209dfbbbd3dbae9756b12c85f8ff81b - Sigstore transparency entry: 1162514536
- Sigstore integration time:
-
Permalink:
opensanctions/unmhtml@79d432d5db34d53b44374b6a0b161315572ef6dc -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/opensanctions
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79d432d5db34d53b44374b6a0b161315572ef6dc -
Trigger Event:
release
-
Statement type:
File details
Details for the file unmhtml-0.3.0-py3-none-any.whl.
File metadata
- Download URL: unmhtml-0.3.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b008fde92d8f070abd32d76ec323dc765e47ef429726f61d9c0c2bafb2dc06e4
|
|
| MD5 |
82f161d3129fab529f1f71eb6ed6a069
|
|
| BLAKE2b-256 |
cdc48abc21707b5a1dd6f8fae2c37c4c9da68d4050426f1d53241bd527b72d6c
|
Provenance
The following attestation bundles were made for unmhtml-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on opensanctions/unmhtml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unmhtml-0.3.0-py3-none-any.whl -
Subject digest:
b008fde92d8f070abd32d76ec323dc765e47ef429726f61d9c0c2bafb2dc06e4 - Sigstore transparency entry: 1162514577
- Sigstore integration time:
-
Permalink:
opensanctions/unmhtml@79d432d5db34d53b44374b6a0b161315572ef6dc -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/opensanctions
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@79d432d5db34d53b44374b6a0b161315572ef6dc -
Trigger Event:
release
-
Statement type: