malmal for Python
A thin wrapper over the C library of the malmal upload scanner. It has no dependencies beyond the standard library.
import malmal
scanner = malmal.Scanner() # build once, share between threads
report = scanner.scan(data, filename="a.png", content_type="image/png")
if not report.clean:
reject([finding["code"] for finding in report.findings])
Anything but report.clean, including a malmal.ScanError, means the file is not accepted.
Scanner(pdf_passwords=["..."]) supplies passwords to try on encrypted PDFs, and
Scanner(allow=["pdf.xfa", "pdf.embedded_file"]) names finding codes that do not count
against a file; they are still reported, at "info". A code that does not exist raises
ValueError. Which codes honest files carry, and what letting each through takes on, is
in the main README.
Scanner(max_memory=...) is what one scan may hold, in bytes (512 MiB unless given;
None or 0 for no limit); a scan that holds more is stopped with limit.memory.
scanner = malmal.Scanner(
policy="documents", # or "default", "strict"
types=["jpeg", "png", "pdf"], # accepted file types
limits={"max_size": 20_000_000, "scan_timeout": 5},
wait=30, # answer within 30 s whatever the file does
)
With wait, a scan that has not ended in time is reported with limit.time, never clean,
and left running on its thread; scanner.overdue counts those, and above 0 the program is
due a restart. sanitize also takes types, keep_cmyk, keep_profile, tone_map, pdf_dpi, pdf_jpeg, pdf_text and
pdf_vector_text.
sanitize scans and then writes a clean image anew from its pixels, so that nothing but the
picture is kept:
try:
image = scanner.sanitize(data, filename="a.png")
except malmal.SanitizeError: # Rejected (with .report) or NotRebuilt
reject()
else:
store(image.data, image.file_type)
Installing
A wheel from the releases carries the library, for x86-64 and ARM64 Linux with glibc 2.17 or newer:
pip install malmal-0.5.1-py3-none-manylinux2014_x86_64.whl
Such a wheel is built with bindings/python/build_wheel.sh x86_64 (or aarch64), which
needs pip install cargo-zigbuild ziglang and the Rust target for that machine.
Anywhere else, the package needs libmalmal_ffi, which is built from the Rust sources:
cargo build --release -p malmal-ffi
cp target/release/libmalmal_ffi.so bindings/python/malmal/
pip install ./bindings/python
The copy placed in the package is installed with it. Alternatively leave the library where
it is and point MALMAL_LIBRARY at it, or pass Scanner(library=...).
Tests
MALMAL_LIBRARY=$PWD/target/release/libmalmal_ffi.so PYTHONPATH=bindings/python python3 -m unittest discover -s bindings/python/tests
Metadata
Release files for malmal 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| malmal-0.5.1-py3-none-manylinux2014_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details for malmal-0.5.1-py3-none-manylinux2014_x86_64.whl |
| malmal-0.5.1-py3-none-manylinux2014_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details for malmal-0.5.1-py3-none-manylinux2014_aarch64.whl |
Total release size: 7.3 MB
Release files / malmal-0.5.1-py3-none-manylinux2014_x86_64.whl
| Download URL | malmal-0.5.1-py3-none-manylinux2014_x86_64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
2ca2243152b23408d8545a1d17844ee73a79de89a7be118fbc6a8d32ba979467
|
|
BLAKE2b-256 checksum How to use checksums |
c3b8783da834af4f9ebdc133d1217a3f342906f03278925ea66b6792ecdff4c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 16, 2026.
Transparency logRelease files / malmal-0.5.1-py3-none-manylinux2014_aarch64.whl
| Download URL | malmal-0.5.1-py3-none-manylinux2014_aarch64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
d9d7238c0e8cd668526dcc9f7da94a9ea5fcdeecf89dc8637bb167774222853c
|
|
BLAKE2b-256 checksum How to use checksums |
6f0e33ed74916e8b344c3c1fb304b11a08396669cb3d4b7e15aa49d96f5ac737
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 16, 2026.
Transparency logSecurity for malmal 0.5.1
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
Both files in this release have been uploaded with provenance metadata.
Attestation for malmal-0.5.1-py3-none-manylinux2014_x86_64.whl
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 Nov 16, 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.