Skip to main content
MZMLpy Logo

Python package codecov PyPI version DOI Python 3.12+ License: MIT

mzmlpy is a Python library for reading mzML mass spectrometry files. It's built for people writing proteomics or metabolomics pipelines who need a reader that's fast on large files, tells them exactly what's wrong with a malformed file, and doesn't force a full decode just to look at a spectrum's metadata.

Why mzmlpy?

  • Lazy by design — metadata is parsed up front; binary m/z and intensity arrays are only decoded when you actually touch them.
  • Fast — 5–9x faster than pymzml on complex files in our benchmarks (see below).
  • Type-safe — dataclass-based models with full type annotations, not loosely-typed XML trees.
  • Handles gzip well — reads .mzML.gz directly, with a self-indexed gzip format for random access without re-extracting the file.
  • Common compressions — zlib out of the box; zstd and MS-Numpress through optional extras.
  • Validates, not just parses — a validate() function reports structural and decoding problems instead of silently producing bad data.

Install

pip install mzmlpy

Optional extras:

pip install mzmlpy[numpress]   # MS-Numpress decoding
pip install mzmlpy[zstd]       # Zstandard compression
pip install mzmlpy[rapidgzip]  # Parallel gzip decompression (recommended for .gz files)
pip install mzmlpy[mcp]        # MCP server for AI coding assistants

Quick example

from mzmlpy import Mzml

with Mzml("path/to/file.mzML") as reader:
    print(f"File: {reader.file_name}  |  Spectra: {len(reader.spectra)}")

    for spectrum in reader.spectra:
        mz = spectrum.mz
        intensity = spectrum.intensity
        print(f"  {spectrum.id} MS{spectrum.ms_level} — {len(mz)} peaks")

Both .mzML and .mzML.gz files are supported. Metadata is parsed eagerly; binary data is decoded on demand.

What else it can do

from mzmlpy import Mzml, validate

# Structural/decoding validation, no repair attempted
report = validate("data.mzML", decode_binary=True)
print(report.valid, report.issues)

# Filter by metadata without decoding any arrays
with Mzml("data.mzML", in_memory=False) as reader:
    for spectrum in reader.spectra.filter(ms_level=2, retention_time=(60, 180)):
        print(spectrum.id)

Gzipped files get the same lazy, indexable access as plain mzML — gzip_mode picks between an embedded index, an extracted cache, or streaming, and self-indexed files (via write_indexed_gzip) support random access with no extraction step at all. Ion mobility data (e.g. Bruker timsTOF PASEF) is exposed on the spectrum whether it's stored as a binary array or a scan-level parameter.

Feature Notes
.mzML / .mzML.gz Transparent gzip handling, including self-indexed files
Validation validate() reports issues without altering the file
Filtering By MS level, retention time, and precursor, without decoding arrays
Ion mobility Detects both array-based and scan-level IM data
MCP server pip install mzmlpy[mcp] — file discovery, metadata, and bounded array access for AI clients
CLI python -m mzmlpy for validation and inspection from the shell

See the Getting Started guide and API Reference for the full picture, including gzip mode details, the CLI, and the MCP server.

Using an AI coding assistant? Point it at llms.txt, a short index of the package and its docs, or at llms-full.txt for the full API guide with signatures and examples.

In the tacular-omics family

mzmlpy reads mzML; tdfpy reads the Bruker timsTOF .d format the same way. Both feed spectra into spxtacular, the shared spectrum-processing layer for deisotoping, deconvolution, and downstream analysis.

Citation

Citation metadata are provided in CITATION.cff. All archived releases are available from Zenodo at doi:10.5281/zenodo.21960079.

Benchmarks

benchmarks/ contains a reproducible harness comparing mzmlpy against pyteomics and pymzml on compression-format support, throughput, and gzip handling.

Compared against pymzml 2.6.0 on a Bruker timsTOF file with ion mobility (10 spectra, 6.7 MB):

Benchmark mzmlpy pymzml Ratio
Startup 0.012s 0.092s 8.0x faster
Iterate (decode) 0.039s 0.228s 5.8x faster
Random access 0.012s 0.110s 9.2x faster

Both libraries produce identical m/z and intensity arrays. The gap narrows on smaller files (~1.1–1.3x) and widens on larger, more complex files. See benchmarks/README.md for how to run it yourself, and the full results on the Benchmarks page.

License

MIT — see LICENSE.

Release files for mzmlpy 0.9.2

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

Source distribution (sdist)

Source distribution for mzmlpy 0.9.2
File Size Uploaded
mzmlpy-0.9.2.tar.gz 89.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mzmlpy 0.9.2
File Interpreter ABI Platform
mzmlpy-0.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 189.4 kB

Release files / mzmlpy-0.9.2.tar.gz

Download URL mzmlpy-0.9.2.tar.gz
Size 89.8 kB
Tags Source
SHA-256 checksum
How to use checksums
604321cdb4a6873119c39ae53e06af000edfabce30078c5a2e333c646d30375a
BLAKE2b-256 checksum
How to use checksums
4a3c4d0d4547634500cbaddc00f2c48abd5203ba3462d9ba8920a8a249a9ac56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 23, 2026.

Transparency log

Release files / mzmlpy-0.9.2-py3-none-any.whl

Download URL mzmlpy-0.9.2-py3-none-any.whl
Size 99.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e8b9ea63bec4883033dc552155ba461f2233855f730c6a82f24203c8081e836
BLAKE2b-256 checksum
How to use checksums
90d8f1ff6a87149f122b9c8fa43004e82f276c8abdde3af455c08648d5ee16ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.10.0

2 release files

0.9.3

2 release files

This release

0.9.2 This release

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

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