Skip to main content

Python API

The Python bindings (crates/openszraw-py, a PyO3 crate) expose a small, eager reader built on the same Rust core as the Rust reader. Install with pip install openszraw, see Install.

import openszraw

reader = openszraw.RawReader("sample.lcd")

RawReader auto-detects .qgd GC-MS vs .lcd IT-TOF vs .lcd QTOF from the file's internal CFBF layout, exactly like the Rust reader (see Format variants). Opening it decodes every spectrum up front into memory, so construction is where the work happens and subsequent access is cheap. For streaming access over large acquisitions, use the Rust reader's iter_spectra instead.

RawReader

MemberTypeDescription
RawReader(path)constructorOpen the .qgd/.lcd file at path and decode it
scan_countintNumber of decoded spectra
read_spectrum(index)SpectrumThe spectrum at zero-based index (raises if out of range)
print(reader.scan_count)
for i in range(reader.scan_count):
spectrum = reader.read_spectrum(i)
...

Spectrum

AttributeTypeDescription
mzlist[float]m/z values (float64)
intensitylist[float]Intensities (float32)
ms_levelintMS level (1 for MS1, 2+ for MS/MS)
retention_time_secfloatRetention time in seconds

len(spectrum) returns the peak count. For .lcd IT-TOF files, mz is calibrated physical m/z (derived from the file's own embedded TOF tuning data); for .lcd QTOF MS2 spectra, precursor m/z is not yet populated. See Scan data for the details and the current known limitations.

spectrum = reader.read_spectrum(0)
print(spectrum.ms_level, spectrum.retention_time_sec, len(spectrum))
mz, intensity = spectrum.mz, spectrum.intensity

Next