Skip to main content

quantion-py

Python wrappers for the quantion Rust library for LC-MS data processing.

Install

pip install git+https://github.com/phenological/quantion#subdirectory=wrappers/python

The install downloads the native library for your platform from the GitHub release that matches the package version.

Concepts

Sample: an opened .ion or mzML file, from parse_ion() or parse_mzml(). Use it as a context manager (with) to free it automatically, or call dispose().

Options: every function with settings takes one options dict. Leave a key out to use its default. An unknown key raises QuantionError with kind "unknown_option".

Errors: every failure raises quantion.QuantionError, with kind, code, function, argument and a message like "calculate_eic: mz must be greater than 0, got -1".

Quick start

import quantion

sample = quantion.parse_ion("sample.ion")
eic = quantion.calculate_eic(sample, 174.112, {"from": 1, "to": 15})
peaks = quantion.find_peaks(eic["x"], eic["y"], {"min_snr": 3})
sample.dispose()

for peak in peaks:
    print(f"rt={peak['rt']:.3f}  intensity={peak['intensity']:.0f}")

The library loads automatically on import.

Files

Open

parse_ion reads a path, an http(s) URL or bytes. Paths and URLs are read lazily: only the bytes a query needs are fetched.

sample = quantion.parse_ion("sample.ion")
remote = quantion.parse_ion("https://example.org/sample.ion", {"max_cache_size": 64_000_000})

parse_mzml reads a path or bytes and loads the whole file. URLs are refused.

sample = quantion.parse_mzml("sample.mzML")

Write

Without out you get the bytes back. With a path the file is written; with a URL it is uploaded in one PUT request.

data = quantion.write_ion(sample)
quantion.write_ion(sample, {"out": "sample.ion", "level": 12})
quantion.write_ion(sample, {
    "out": "https://example.org/upload/sample.ion",
    "headers": [{"name": "Authorization", "value": "Bearer <token>"}],
})
quantion.write_mzml(sample, {"out": "sample.mzML"})

Scans

A range gives every scan in it; one number gives a list with the closest scan.

scans = quantion.get_scans(sample, rt={"from": 1.0, "to": 2.5})
closest = quantion.get_scans(sample, rt=108, options={"level": 2, "time_unit": quantion.TimeUnit.SECONDS})

EIC

The range is from and to in the options; the default is the whole run.

eic = quantion.calculate_eic(sample, 174.112, {"from": 1, "to": 15, "ppm_tolerance": 10})

Ion image

Only .ion files.

image = quantion.get_ion_image(sample, 760.585, {"tolerance": 0.05})

Traces

peaks = quantion.find_peaks(x, y, {"min_snr": 3})
peak = quantion.get_peak(x, y, 5.3, {"range": 0.6})
anywhere = quantion.get_peak(x, y, 5.3)
params = quantion.fit_peak(x, y, 5.3, {"shape": quantion.PeakShape.GAUSSIAN})
chromatogram = quantion.draw_peaks([params], {"from": 4.5, "to": 6.0, "points": 500})
noise = quantion.find_noise_level(y)["intensity"]
baseline = quantion.calculate_baseline(y, {"lambda": 50})

get_peak without a range searches the whole trace. A peak with every field 0 means no peak was found.

Targets

targets = [
    {"id": "compound_A", "mz": 174.112, "rt": 5.3, "range": 0.5},
    {"id": "compound_B", "mz": 203.156, "rt": 7.1, "range": 0.5},
]
peaks = quantion.find_targets(sample, targets, {
    "eic": {"from": 0.5, "to": 10.0},
    "find_peaks": {"min_intensity": 1000},
    "threads": 2,
})

Stored SRM chromatograms: each transition picks the chromatogram whose precursor (Q1) and product (Q3) m/z are both within 0.005. Needs the whole file.

transitions = [{"id": "compound_1", "precursor": 500.3, "product": 184.1, "rt": 3.20, "range": 0.4}]
peaks = quantion.find_transitions(sample, transitions, {"threads": 2})

Features

features = quantion.find_features(sample, {
    "grid": {"start": 100, "end": 600},
    "threads": 4,
})

matched = quantion.match_features("samples/", {
    "grouping": {"min_frequency": 0.5},
    "threads": 8,
})

frequency in each matched feature is the fraction of samples where it was found.

Retention-time models

model = quantion.load_model("model.onnx")
model.get_value("points")

warp = quantion.load_warp(model)
rts = warp.predict_rts(sample, [{"id": "feature_1", "mz": 300.1, "rt": 2.38}])

calibrated = warp.calibrate([ltr_1, ltr_2, ltr_3], [seen_in_ltr_1, seen_in_ltr_2, seen_in_ltr_3])
rts = warp.predict_rts(other_sample, calibrated)

warp.dispose()
model.dispose()

Each rt given to calibrate must be the one measured in that anchor sample.

Options and defaults

Options Keys (defaults)
FindPeaksOptions min_integral (off), min_intensity (500), min_peak_width_points (3), noise (off), auto_noise (True), auto_baseline (True), lambda (20), max_iterations (4), allow_overlap (False), min_snr (2), min_r2 (0), shape ("EMG"), kernel_size (0)
CalculateEicOptions from (0), to (inf), ppm_tolerance (20), mz_tolerance (0.005), time_unit ("MINUTES")
GridOptions start (40), end (1000), step_size (0.005)
GroupingOptions ppm_tolerance (5), mz_tolerance (0.0025), rt_tolerance (0.05), min_frequency (0)
GetPeakOptions range (0), find_peaks
FitPeakOptions shape ("EMG"), intensity (0 = taken from the peak)
DrawPeaksOptions from (0), to (0; both 0 fit the range around the peaks), points (1000)
CalculateBaselineOptions lambda (20), max_iterations (4)
FindTargetsOptions eic, find_peaks, threads (1)
FindTransitionsOptions find_peaks, threads (1)
FindFeaturesOptions eic, grid, find_peaks, threads (1)
MatchFeaturesOptions eic, grid, grouping, find_peaks, threads (1)
GetScansOptions level (1), time_unit ("MINUTES")
ParseIonOptions max_cache_size (0 = no limit)
WriteIonOptions out, overwrite (False), level (12), f32_compress (False), headers ([])
WriteMzmlOptions out, overwrite (False)
GetIonImageOptions tolerance (0.125), level (1), on_progress

TimeUnit is "MINUTES" or "SECONDS"; PeakShape is "GAUSSIAN" or "EMG". Both accept the enum or the uppercase text.

Metadata

Release files for quantion 0.2.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 quantion 0.2.0
File Actions
quantion-0.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for quantion-0.2.0-py3-none-win_amd64.whl
quantion-0.2.0-py3-none-manylinux_2_34_x86_64.whl Python 3 none Linux glibc 2.34+ x86-64 Details for quantion-0.2.0-py3-none-manylinux_2_34_x86_64.whl
quantion-0.2.0-py3-none-manylinux_2_34_aarch64.whl Python 3 none Linux glibc 2.34+ ARM64 Details for quantion-0.2.0-py3-none-manylinux_2_34_aarch64.whl
quantion-0.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for quantion-0.2.0-py3-none-macosx_11_0_arm64.whl
quantion-0.2.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for quantion-0.2.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 6.4 MB

Release files / quantion-0.2.0-py3-none-win_amd64.whl

Download URL quantion-0.2.0-py3-none-win_amd64.whl
Size 1.3 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ab7d129ca48feec6985e682b03c1ff1bb193eb9657e32d97824ca0489a04135b
BLAKE2b-256 checksum
How to use checksums
9f6ec5e55c4c353dd98e40bf0f9b436a3989e0fd3c5dc74dd346b76925294e5d
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 Oct 30, 2026.

Transparency log

Release files / quantion-0.2.0-py3-none-manylinux_2_34_x86_64.whl

Download URL quantion-0.2.0-py3-none-manylinux_2_34_x86_64.whl
Size 1.4 MB
Tags Linux glibc 2.34+ x86-64 Python 3
SHA-256 checksum
How to use checksums
e5acd1182e7f1031c8e8a0f7ea0b0675f03662d44b4f298cdabbc6d6a240a81f
BLAKE2b-256 checksum
How to use checksums
1bb1ba45b79b24b5c81e3ee6e775f6ea836c0a8e165a810bb9d75088bded53d3
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 Oct 30, 2026.

Transparency log

Release files / quantion-0.2.0-py3-none-manylinux_2_34_aarch64.whl

Download URL quantion-0.2.0-py3-none-manylinux_2_34_aarch64.whl
Size 1.2 MB
Tags Linux glibc 2.34+ ARM64 Python 3
SHA-256 checksum
How to use checksums
2c30a9b761980d1feff241acff6176f3ccaa37497fc464bf2f0e2bd0b2c1c381
BLAKE2b-256 checksum
How to use checksums
589f0a590dc0bd1064dc11fd67682e16c58d4b4a8d5eabdaba227899b99a84ae
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 Oct 30, 2026.

Transparency log

Release files / quantion-0.2.0-py3-none-macosx_11_0_arm64.whl

Download URL quantion-0.2.0-py3-none-macosx_11_0_arm64.whl
Size 1.2 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9d137c13fb1ab11a3fc40a406cb90fad13ff5bfc6227fb66a0d44ebe2a5166d7
BLAKE2b-256 checksum
How to use checksums
34cbe8cdeb2d55d93a946d6979f7f5e502bc16da908e36f0f2459b3ccd2002c4
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 Oct 30, 2026.

Transparency log

Release files / quantion-0.2.0-py3-none-macosx_10_12_x86_64.whl

Download URL quantion-0.2.0-py3-none-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e7de6477aba8da46e990e3799d824adc325abb577ff93a28d1383af3c7e4be2a
BLAKE2b-256 checksum
How to use checksums
dadb48f8ab8c0d58e963ab2faef12272b880ef2f3b8986185bb35eed7f423ac2
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 Oct 30, 2026.

Transparency log

Security for quantion 0.2.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

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for quantion-0.2.0-py3-none-win_amd64.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 Oct 30, 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

5 release files Full provenance

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