Skip to main content

MHTML to HTML converter library using Python stdlib

Project description

unmhtml

PyPI version

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 converts javascript: URLs to safe # anchors
  • sanitize_css=True - Removes external CSS URLs (http://, https://, //, /absolute) while preserving relative URLs (image.png, ../fonts/font.woff) and data URIs
  • remove_forms=True - Removes form elements (<form>, <input>, <textarea>, <select>) that could submit data externally
  • remove_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unmhtml-0.3.0.tar.gz (55.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unmhtml-0.3.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

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

Hashes for unmhtml-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8c0209465c1840f11c0fc6d2a136ac7cd209dfbbbd3dbae9756b12c85f8ff81b
MD5 1f8137667428e84c9f420923198f5ea4
BLAKE2b-256 f2d12d9a5e857b8d56d99116b5313d61349f6cf05ea0a5edf4e768b758ce828f

See more details on using hashes here.

Provenance

The following attestation bundles were made for unmhtml-0.3.0.tar.gz:

Publisher: publish.yml on opensanctions/unmhtml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for unmhtml-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b008fde92d8f070abd32d76ec323dc765e47ef429726f61d9c0c2bafb2dc06e4
MD5 82f161d3129fab529f1f71eb6ed6a069
BLAKE2b-256 cdc48abc21707b5a1dd6f8fae2c37c4c9da68d4050426f1d53241bd527b72d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for unmhtml-0.3.0-py3-none-any.whl:

Publisher: publish.yml on opensanctions/unmhtml

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page