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

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.1
File Interpreter ABI Platform Actions
malmal-0.4.1-py3-none-manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for malmal-0.4.1-py3-none-manylinux2014_x86_64.whl
malmal-0.4.1-py3-none-manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for malmal-0.4.1-py3-none-manylinux2014_aarch64.whl

Total release size: 4.9 MB

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

Download URL malmal-0.4.1-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
76c5733ccc4b52b8c70c4b32c967560c96cf0b58ae81ec2f74db0b1853754cc9
BLAKE2b-256 checksum
How to use checksums
9e7b22fc40a3eb7022cda573cda41e47f2808d15e6fb6e307975bf7dc9854fea
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.1-py3-none-manylinux2014_aarch64.whl

Download URL malmal-0.4.1-py3-none-manylinux2014_aarch64.whl
Size 2.3 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
1e0c8d2abad78a4e51d4e0b76be844c311c0b64732b4a05d5f26d79a47014e75
BLAKE2b-256 checksum
How to use checksums
dcbf4d477d3ac7844982b5054dbfe22934ddb24c3a3ec78bbd245279de0c49e5
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.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.

Select from 2 files

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