Registry / data / osm2geojson

osm2geojson

JSON →
library0.3.2pypypi✓ verified 84d ago

A Python library to convert OSM and Overpass JSON responses into valid GeoJSON. Version 0.3.2 is the latest stable release. The library is actively maintained, with recent bug fixes for polygon hole handling and blacklist/whitelist rules. Releases are sporadic.

pip install osm2geojson
INSTALL
IMPORT
SIG · OSM2GEOJSON
O
osm2geojson
datapythonv0.3.2
Install
4.6s avg
Import
974ms
Disk
104MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 4.8s
py 3.11
✓ —
✓ 4.3s
py 3.12
✓ —
✓ 4.2s
py 3.13
✓ —
✓ 4.2s
py 3.9
✕ build_error
✓ 5.4s
104MB installed
● package 104MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

osm2geojson
import osm2geojson

Converts an OSM JSON dict (e.g., from Overpass API) into a GeoJSON FeatureCollection.

import osm2geojson # Example: convert an Overpass JSON response to GeoJSON overpass_json = { "elements": [ { "type": "node", "id": 1, "lat": 50.0, "lon": 10.0, "tags": {"amenity": "cafe"} } ] } geojson = osm2geojson.json2geojson(overpass_json) print(geojson)
Debug
Known issues
gotchaInput must be a parsed JSON dict, not a raw string. If you pass a string, the function will fail.
fix
Ensure you pass a dict via json.loads() if reading from a string.
affects: all
gotchaThe 'elements' key in Overpass JSON is required. If your JSON is malformed (e.g., missing 'elements'), the conversion will return an empty FeatureCollection.
fix
Validate your Overpass JSON structure before passing to osm2geojson.
affects: all
deprecatedThe function 'overpass2geojson' in older versions is deprecated in favor of 'json2geojson'. Using the old name may raise a deprecation warning or be removed.
fix
Use json2geojson instead of overpass2geojson.
affects: <0.3.0
gotchaPolygon orientation (clockwise/counter-clockwise) is not automatically corrected. The library follows the OSM convention, which may produce invalid GeoJSON if the winding order is wrong.
fix
Post-process with a polygon winding fixer if required by your GeoJSON consumer.
affects: all
Errors
Common errors & fixes
AttributeError: module 'osm2geojson' has no attribute 'overpass2geojson'
The function 'overpass2geojson' was renamed to 'json2geojson' in version 0.3.0.
fix
Use osm2geojson.json2geojson(data) instead of osm2geojson.overpass2geojson(data).
KeyError: 'elements'
The input JSON dict does not contain the expected 'elements' key. The library expects the standard Overpass JSON format.
fix
Check your JSON structure; ensure it has an 'elements' list. If from Overpass, use the raw response (the JSON output from the API).
TypeError: the JSON object must be str, bytes or bytearray, not dict
The user passed a Python dict without calling json2geojson, but tried to use json.loads on an already-parsed dict.
fix
Pass the dict directly to osm2geojson.json2geojson(dict). If you have a string, do: geojson = osm2geojson.json2geojson(json.loads(json_string)).
Upgrade
Version history
0.3.2latest on PyPI · released Mar 4, 2026
Audit
Dependencies
overpyoptionaloptional dependency for Overpass API queries
Agent activity
2 hits · last 30 days
node
2
Resources