Table Of Contents

Previous topic


This Page

Parsing API

Imposm comes with a single OSMParser class that implements a simple to use, callback-based parser for OSM files.

It supports XML and PBF files. It also supports BZip2 compressed XML files.


The parser uses multiprocessing to distribute the parsing across multiple CPUs. This does work with PBF as well as XML files.

You can pass the concurrency as an argument to OSMParser and it defaults to the number of CPU and cores of the host system. concurrency defines the number of parser processes. The main process where the callbacks are handled and the decompression (if you have a .bzip2 file) are handled in additional processes. So you might get better results if you reduce this number on systems with more than two cores.

You can double the number on systems with hyper threading CPUs.


class imposm.parser.OSMParser(concurrency=None, nodes_callback=None, ways_callback=None, relations_callback=None, coords_callback=None, nodes_tag_filter=None, ways_tag_filter=None, relations_tag_filter=None, marshal_elem_data=False)

High-level OSM parser.

  • concurrency – number of parser processes to start. Defaults to the number of CPUs.
  • xxx_callback – callback functions for coords, nodes, ways and relations. Each callback function gets called with a list of multiple elements. See callback concepts.
  • xxx_filter – functions that can manipulate the tag dictionary. Nodes and relations without tags will not passed to the callback. See tag filter concepts.

Parse the given file. Detects the filetype based on the file suffix. Supports .pbf, .osm and .osm.bz2.


Parse a PBF file.


Parse a XML file. Supports BZip2 compressed files if the filename ends with .bz2.