Skip to main content

🌍 osm-simplify

osm-simplify is a lightweight, dependency-minimal Python library designed to make querying OpenStreetMap (OSM) data effortless. Whether you are building local spatial routing, geographic data parsers, or 100% offline mapping applications, this library bridges the gap between raw map data and clean, ready-to-use Python objects.


💡 Why Use osm-simplify? (The Benefits)

Working directly with OpenStreetMap's Overpass API or raw binary extracts can be tedious, requiring complex query syntax or heavy C++ bindings. osm-simplify solves this by giving you:

  • Zero Heavy GIS Bloat: Avoid installing massive, hard-to-configure geographic libraries like GDAL, GEOS, or PyPBF just to load map extracts or perform local lookups.

  • Pure-Python PBF Binary Parser: Native streaming .osm.pbf reader powered purely by standard library zlib and struct—no C/C++ build chains required.

  • Sub-Millisecond $O(1)$ Spatial Indexing: Built-in LocalSpatialIndex partitions map primitives into ~1.1km spatial grid cells on cold start, delivering instant sub-millisecond offline lookups.

  • Smart Dual-Mode Engine: Query live public Overpass servers with built-in failover, or seamlessly pass a local .osm XML or .osm.pbf file for offline parsing.

  • GeoJSON Batch Exports: PlaceList collections export directly to RFC 7946-compliant GeoJSON FeatureCollection dictionaries ready for web mapping engines (Leaflet, Mapbox, Deck.gl).

  • Raw Tag Retention: Full unparsed OpenStreetMap key-value dictionaries are preserved on every Place object for custom tag filtering (tags={"historic": "castle"}) and metadata inspection.


🚀 Installation & Local Clone

You can install the package directly from PyPI:

pip install osm-simplify

Or if you want to perform a local clone for development:

git clone https://github.com/DoguH72/osm-simplify.git

cd osm-simplify

pip install -e .

📖 Quick Start

import os

from osm_simplify import GeoFinder, Category



# Initialize search anchor (via address string or direct coordinates)

spot = GeoFinder.from_address("Piazza Castello", "Turin")



# Attach a local .osm XML or .osm.pbf file for offline fallback

if os.path.exists("nord-ovest-latest.osm.pbf"):

    spot.local_file = "nord-ovest-latest.osm.pbf"



# Find nearby food spots within 500m (automatically sorted by distance)

restaurants = spot.get_nearby(Category.FOOD, radius_m=500)



for place in restaurants[:5]:

    print(f"- {place.name} ({place.subtype}): {place.distance_m}m away")



# Find the single closest monument

closest = spot.get_closest(Category.MONUMENT, radius_m=1000)

if closest:

    print(f"Closest Monument: {closest.name} @ {closest.distance_m}m")

2. Pure Offline Mode (.osm.pbf Binary & .osm XML)

Pass a local PBF binary extract or XML file to bypass network calls completely. The engine builds an in-memory spatial grid hash map on cold start for instant lookups:

from osm_simplify import GeoFinder, Category



# Pass local PBF file directly during initialization

spot = GeoFinder(

    lat=45.0705, 

    lon=7.6868, 

    location_name="Turin Center", 

    local_file="nord-ovest-latest.osm.pbf"

)



# Sub-millisecond indexed search

parks = spot.get_nearby(Category.PARK, radius_m=1000)

print(f"Found {len(parks)} parks offline in sub-milliseconds!")

3. Custom Tag Filtering & Raw Tag Access

Query exact OpenStreetMap key-value tags directly without preset dictionaries, and access original tag metadata:

# Direct OSM tag key-value filter

castles = spot.get_nearby("historic", radius_m=1000, tags={"historic": "castle"})



# Access raw unparsed OSM tags on any returned Place

if castles:

    place = castles[0]

    print(f"Name:    {place.name}")

    print(f"Website: {place.raw_tags.get('website', 'N/A')}")

    print(f"Hours:   {place.raw_tags.get('opening_hours', 'N/A')}")

4. GeoJSON Exports for Web Maps

Export search results directly to GeoJSON format:

import json



places = spot.get_nearby(Category.FOOD, radius_m=500)



# Export batch PlaceList collection to GeoJSON FeatureCollection dictionary

geojson_data = places.to_geojson()



with open("food_spots.geojson", "w", encoding="utf-8") as f:

    json.dump(geojson_data, f, indent=2)

5. NumPy Export

Install the optional extra with pip install "osm-simplify[numpy]", or pip install -e ".[numpy]" from a local clone.

places = spot.get_nearby(Category.PARK, radius_m=1000)
rows = places.to_numpy()
nearby_latitudes = rows["lat"][rows["distance_m"] <= 250]

The structured array has one row per place and fields for name, category, subtype, lat, lon, distance_m, and raw_tags. Text and tag dictionaries use object fields. Empty results have the same dtype and zero rows.

PBF Geometry and Coverage

The offline PBF reader supports snapshot extracts with ordinary nodes, dense nodes, ways, and relations, using raw or zlib-compressed blocks. Each tagged way or relation becomes one searchable point at the center of its available geometry's latitude and longitude bounds. Way centers use the shortest longitude span, accounting for wraparound at the antimeridian. Nested relation members are followed, and missing references are skipped. Ways and relations with no available coordinates are omitted. Centers can fall outside the feature, especially for relations crossing the antimeridian. The reader loads PBF blocks incrementally and keeps node coordinates and unresolved references in memory during indexing.

OSM IDs and Offline Map Viewports

Search results include place.osm_type and place.osm_id when the source provides them. GeoJSON feature properties include the available fields too. Store the two fields together because nodes, ways, and relations have separate ID namespaces. Keep your own application ID for ratings or other user data.

For an offline map, use places_in_bbox() to fetch the pins in the current viewport. The bounds are (west, south, east, north) in degrees. The bounds are inclusive, and a west value greater than east crosses the antimeridian.

from osm_simplify import GeoFinder

spot = GeoFinder(45.0705, 7.6868, local_file="turin.osm.pbf")
museums = spot.places_in_bbox((7.65, 45.05, 7.72, 45.10), tags={"tourism": "museum"})
pins = museums.to_geojson()

The query reuses the local index, matches every supplied tag, and tests each place's indexed point or center against the box. Offline viewport results have distance_m=0.

Running Tests

Run python -B -m unittest discover -s tests -v from the repository root. GitHub Actions runs the suite on Python 3.8 and 3.12 with the NumPy extra installed. The fixtures are generated locally and the Overpass calls are mocked.

🧩 Core API Reference

  • GeoFinder(lat, lon, location_name=..., local_file=...): Core spatial engine handling online API requests, mirror failovers, and offline PBF/XML spatial indexing.

  • LocalSpatialIndex: In-memory spatial hash grid storing POI candidates inside ~1.1km bounding cells for instant $O(1)$ candidate lookups.

  • Place: Clean dataclass representing a found location (.name, .category, .subtype, .lat, .lon, .distance_m, .raw_tags, .to_dict(), .to_geojson_feature()).

  • PlaceList: Collection of Place objects with .to_geojson() and .to_numpy() exports.

  • Category: Pre-configured presets (Category.FOOD, Category.PARK, Category.MONUMENT).

  • OverpassServerError: Custom exception raised when all public Overpass mirrors are overloaded or unreachable.


📄 License

Distributed under the MIT License. Feel free to use, modify, and adapt it for your own projects!

Metadata

Release files for osm-simplify 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osm-simplify 1.2.0
File Size Uploaded Provenance Actions
osm_simplify-1.2.0.tar.gz 22.4 kB With provenance Details for osm_simplify-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for osm-simplify 1.2.0
File Interpreter ABI Platform Actions
osm_simplify-1.2.0-py3-none-any.whl Python 3 none any Details for osm_simplify-1.2.0-py3-none-any.whl

Total release size: 39.3 kB

Release files / osm_simplify-1.2.0.tar.gz

Download URL osm_simplify-1.2.0.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
77246b926bb04881a006ade2332f6419023a82a3794f134f794ecc69e7e18688
BLAKE2b-256 checksum
How to use checksums
5ee383dd4fc087501747ef1fbb067d9b119d328e2092be850d4cacb44b3251a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / osm_simplify-1.2.0-py3-none-any.whl

Download URL osm_simplify-1.2.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
820a51b940f201567846b7f21072e44a7f00982411e3d0fe801035aa49df729e
BLAKE2b-256 checksum
How to use checksums
ec49ebe873823fb7e29b05bc247e33c87bff7f253ada89faed497ccb44fe4926
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for osm-simplify 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for osm_simplify-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page