Pyrosm is a Python library for reading OpenStreetMap from Protocolbuffer Binary Format -files (*.osm.pbf) into Geopandas GeoDataFrames. Pyrosm makes it easy to extract various datasets from OpenStreetMap pbf-dumps including e.g. road networks, buildings, Points of Interest (POI), landuse, natural elements, administrative boundaries and much more. Fully customized queries are supported which makes it possible to parse any kind of data from OSM, even with more specific filters.
Pyrosm is easy to use and it provides a somewhat similar user interface as OSMnx. The main difference between pyrosm and OSMnx is that OSMnx reads the data using an OverPass API, whereas pyrosm reads the data from local OSM data dumps that are downloaded from the PBF data providers (Geofabrik, BBBike). This makes it possible to parse OSM data faster and make it more feasible to extract data covering large regions.
For instance, parsing all roads from the state of New York (USA) with a “basic” work laptop (16GB memory, SSD, and Intel Core i5 CPU), takes less than 3 minutes and parsing the buildings from the same region takes less than 4 minutes (see benchmarks for details):
download PBF data easily from hundreds of locations across the world
read street networks (separately for driving, cycling, walking and all-combined)
read buildings from PBF
read Points of Interest (POI) from PBF
read landuse from PBF
read “natural” from PBF
read boundaries from PBF (such as administrative borders)
read any other data from PBF by using a custom user-defined filter
filter data based on bounding box
export networks as a directed graph to igraph, networkx and pandana
When should I use Pyrosm?¶
Pyrosm can of course be used whenever you need to parse data from OSM into geopandas GeoDataFrames. However, pyrosm is better suited for situations where you want to fetch data for whole city or larger regions (even whole country).
If you are interested to fetch OSM data for smaller areas such as neighborhoods, or search data around a specific location/address, we recommend using OSMnx which is more flexible in terms of specifying the area of interest. That being said, it is also possible to extract neighborhood level information with pyrosm and filter data based on a bounding box (see docs).
Pyrosm is licensed under MIT (see license).
- Basic usage
- Protobuf file: What is it and how to get one?
- Initializing the Pyrosm OSM -reader object
- Read street networks
- Read buildings
- Read Points of Interest
- Read landuse
- Read natural
- Read boundaries
- Read OSM data with custom filter
- Filtering data based on bounding box
- Pyrosm/OSM tagging system
- Export street networks to graph
- Customizing the queries
- Working with graphs
- Find shortest path with Pyrosm + NetworkX + OSMnx
- Calculate the catchment areas of hospitals in Estonia with pyrosm + igraph
- Calculate the job accessibility in Helsinki Region with pyrosm + pandana
- Reference to All Attributes and Methods