Skip to main content
MZMLpy Logo

A lightweight Python library for parsing mzML mass spectrometry files. Implements a type-safe, lazy-loading API with direct support for modern mzML structures (>= 1.1.0).

Python package codecov PyPI version Python 3.12+ License: MIT

Installation

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)

Quick Start

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.

Reading Gzipped Files

When opening .mzML.gz files, the gzip_mode parameter controls how the file is accessed:

Mode Description
"extract" (default) Decompress to <tmpdir>/mzmlpy/ and cache across sessions. First open pays decompression cost; subsequent opens reuse the cache instantly. The OS clears tmp on reboot.
"indexed" Seekable access to the compressed file using rapidgzip. No decompression to disk. Requires pip install mzmlpy[rapidgzip].
"stream" Stream sequentially. Lowest startup cost but no efficient random access.

For most use cases, "extract" or "indexed" is recommended:

# Default — extracts to tmp, cached across sessions
with Mzml("data.mzML.gz") as reader:
    spec = reader.spectra[0]

# Indexed — no extraction, seekable access (requires rapidgzip)
with Mzml("data.mzML.gz", gzip_mode="indexed") as reader:
    spec = reader.spectra[0]

To reclaim disk space before the OS clears tmp on reboot:

from mzmlpy import clear_cache
clear_cache()

Performance

"extract" pays a one-time decompression cost then matches plain .mzML speed on later opens (the extracted copy is cached). "indexed" pays a one-time index-build cost for seekable access with no disk copy. "stream" has the lowest startup cost but random access re-scans from the start, so it's sequential-only in practice. See benchmarks/ for a reproducible harness with real numbers on real files, including a head-to-head against pyteomics and pymzml.

mzmlpy vs pymzml

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 the full results in the Benchmarks page or run benchmarks/bench_vs_pymzml.py yourself.

For full usage examples see the Getting Started guide and API Reference.

Using an AI coding assistant? Point it at llms.txt — a compact, accurate API guide for generating correct mzmlpy code.

Citation

Citation metadata are provided in CITATION.cff. A DOI will be added after the first Zenodo archive is published.

Benchmarks

benchmarks/ contains a reproducible harness comparing mzmlpy against pyteomics and pymzml on compression-format support, throughput, and gzip handling. See benchmarks/README.md for how to run it and current results.

Development

just lint     # ruff check
just format   # ruff isort + format
just ty       # ty type checker
just test     # pytest

# or all at once:
just check

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mzmlpy-0.6.0.tar.gz (51.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mzmlpy-0.6.0-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file mzmlpy-0.6.0.tar.gz.

File metadata

  • Download URL: mzmlpy-0.6.0.tar.gz
  • Upload date:
  • Size: 51.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mzmlpy-0.6.0.tar.gz
Algorithm Hash digest
SHA256 9fded46a9d0bffd5ec71bace52c650e82823b092304299204b0859b632486b81
MD5 9e3ba225b22b4c5eb5eb743c3d2aa9b9
BLAKE2b-256 cfd710d283393d0442a975e0f722840133d684c913383717c91d11ca30d960ff

See more details on using hashes here.

File details

Details for the file mzmlpy-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: mzmlpy-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 57.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mzmlpy-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d55ccdf413c959bcb99e341a57bb7761eb554c9371ad5d252813b3b165da432
MD5 8b3689042b5f3283b98f89dbbadeef23
BLAKE2b-256 21c9b6a5e03e11bec60df61d58a44684199181cff9d3ca11addb48bde9284bfc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 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