3.1. Main reader interface

The class Reader has been designed to selectively extract data from a mzML file and to expose the data as a python object. Necessary information are read in and stored in a fast accessible format. The reader itself is an iterator, thus looping over all spectra follows the classical pythonian syntax. Additionally one can random access spectra by their nativeID if the file if not truncated by a conversion Program.


The class Writer is still in development.

class pymzml.run.Reader(path, MS_precisions=None, obo_version=None, **kwargs)[source]

Initialize Reader object for a given mzML file.


path (str) – path to the mzml file to parse.

Keyword Arguments:
  • MS_precisions (dict) –

    measured precisions for the different MS levels. e.g.:

        1 : 5e-6,
        2 : 20e-6
  • obo_version (str, optional) – obo version number as string. If not specified the version will be extracted from the mzML file


Setting the precision for MS1 and MSn spectra has changed in version 1.2. However, the old syntax as kwargs is still compatible ( e.g. ‘MS1_Precision=5e-6’).


Access spectrum with native id ‘identifier’.

Parameters:identifier (str or int) – last number in the id tag of the spectrum element
Returns:spectrum/chromatogram object with native id ‘identifier’
Return type:spectrum (Spectrum or Chromatogram)

Return file object in use.


Number of chromatograms in file.

Returns:Number of chromatograms in file.
Return type:chromatogram count (int)

Number of spectra in file.

Returns:Number of spectra in file.
Return type:spectrum count (int)

Function to return the next Spectrum element.