Skip to main content

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, 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.4.0-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.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for malmal 0.4.0
File Interpreter ABI Platform Actions
malmal-0.4.0-py3-none-manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for malmal-0.4.0-py3-none-manylinux2014_x86_64.whl
malmal-0.4.0-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for malmal-0.4.0-py3-none-manylinux2014_aarch64.whl

Total release size: 4.9 MB

Release files / malmal-0.4.0-py3-none-manylinux2014_x86_64.whl

Download URL malmal-0.4.0-py3-none-manylinux2014_x86_64.whl
Size 2.6 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
706c294f196656c558a8d3132a9b51dcafc25e0c90d68b42b1e78030c81e77b9
BLAKE2b-256 checksum
How to use checksums
1ca877f6ef28710da39ae00035d653939505930b3c75c95ccdfa849e910ec5db
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 15, 2026.

Transparency log

Release files / malmal-0.4.0-py3-none-manylinux2014_aarch64.whl

Download URL malmal-0.4.0-py3-none-manylinux2014_aarch64.whl
Size 2.3 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
90b20b1b4371161a3f869431007a0654d4bd05f236da606cd1e9f6b825103618
BLAKE2b-256 checksum
How to use checksums
55e157699a7c2db1647ffdf51ecc05a4837a886c10db3aa02c3a7c23d687d782
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 15, 2026.

Transparency log

Security for malmal 0.4.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for malmal-0.4.0-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 15, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page