Skip to content

Command line and Python

For a script, a server or Python code, use duckOSM. It uses the same Rust engine as the page and gives the same tables.

duckOSM 0.7.0 and newer have this engine in the duckosm wheel, for Linux, macOS and Windows.

Build from the command line

  1. Install duckOSM:

    pip install duckosm
    
  2. Get an .osm.pbf file from Geofabrik.

  3. Build the networks. Repeat --modes for each network:

    duckosm build --pbf monaco.osm.pbf --output monaco.duckdb --modes driving --modes walking --modes cycling
    

The result is one DuckDB file (The tables).

Read the tables in Python

import duckdb

con = duckdb.connect("monaco.duckdb", read_only=True)
con.execute("SELECT highway, count(*) FROM driving.edges GROUP BY highway").fetchall()

More