pimht
Python mhtml parser
Installation
$ pip install pimht
Example
import pimht
mhtml = pimht.from_filename("test.mhtml")
for part in mhtml:
print(part.content_type, len(part.raw))
Modifying
import pimht
mhtml = pimht.from_filename("test.mhtml")
for part in mhtml.parts:
if part.is_text:
part.text = part.text.replace("Hello", "Goodbye")
with open("modified.mhtml", "wb") as f:
f.write(mhtml.to_bytes())
API
Parsing (all return an MHTML object):
pimht.from_filename(path)pimht.from_bytes(data)pimht.from_string(text)pimht.from_fileobj(fp)— text or binary mode
MHTML:
headers— top-level headers as a dictparts— list ofMHTMLPart(iterating theMHTMLobject yields the same parts)to_bytes()— serialize the archive, including any modifications
MHTMLPart:
headers— part headers as a dictcontent_type— mime type, e.g."text/html"is_text— whethercontent_typeistext/*charset— charset from the Content-Type header, orNoneraw— decoded content asbytes; assignabletext— decoded content asstr(text parts only); assignable
Assigning to raw or text re-encodes the content so to_bytes()
reflects the change.
Performance
The chardet module, used by default, is slow. Performance can be improved by also installing faust-cchardet and pybase64 with:
$ pip install pimht[speedups]
This is aimed specifically at parsing Google Chrome generated snapshots as fast as possible, but feel free to report issues with MHTML files from other sources.
Metadata
Release files for pimht 0.6.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 | Provenance | Actions |
|---|---|---|---|---|
| pimht-0.6.0.tar.gz | 6.2 kB | With provenance | Details for pimht-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pimht-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for pimht-0.6.0-py3-none-any.whl |
Total release size: 11.9 kB
Release files / pimht-0.6.0.tar.gz
| Download URL | pimht-0.6.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
376cee5bd02526e65659446518d827065dd4fb88b2d710d57ac83eadd5eefa91
|
|
BLAKE2b-256 checksum How to use checksums |
d49ce1f54623effc4dc7bf3bb4347aecd7edadcea3c63f5a99f206430a23a616
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 9, 2026.
Transparency logRelease files / pimht-0.6.0-py3-none-any.whl
| Download URL | pimht-0.6.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7ad5b4328fdccdde15bf556ea8f8df1d08f818ce04aa77d6387bdb6700e3eac
|
|
BLAKE2b-256 checksum How to use checksums |
ab54005e47f759629dc294eaa58b7bc34e84d452fbc67a695078ef9fe5bd8cf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jul 9, 2026.
Transparency logSecurity for pimht 0.6.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pimht-0.6.0.tar.gz
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 Jul 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.