Skip to main content

korp-map-client (Python)

A Python data client for the korp-map server: OpenStreetMap rows for a bounding box as Arrow tables (or GeoDataFrames), plus address geocoding. For notebooks and analysis; it speaks the map wire, contract v1.2 (HTTP). Formerly published as korp-map (import korp_map); that name is now a deprecated shim that installs this package.

Try it

The public server is https://karta.gunnar.rs (all of Sweden from OpenStreetMap), and it is the default, so Client() needs no URL. Real output:

>>> import korp_map_client
>>> c = korp_map_client.Client()          # https://karta.gunnar.rs
>>> c.regions()
[{'name': 'sweden', 'bbox': [10.59326171875, 55.13720703125, 24.177734375, 69.06005859375], 'data_version': 'files-aff34692ba7c0dd8'}]

>>> res = c.map("lines", bbox=(18.05, 59.32, 18.08, 59.34), lod=14)   # Stockholm, Gamla stan
>>> res.num_rows, res.truncated, res.geometry_source
(3508, False, 'full')
>>> res.table.column_names
['id', 'tags', 'min_zoom', 'geometry']

>>> c.geocode("Drottninggatan 53 Stockholm", max=1)
[{'street': 'Drottninggatan', 'housenumber': '53', 'city': 'Stockholm', 'postcode': '', 'lon': 18.0618896484375, 'lat': 59.3333740234375, 'source': 2453165069, 'score': 110}]

>>> c.revgeocode(18.07, 59.33)
{'street': 'Jakobs Torg', 'housenumber': '4', 'city': 'Stockholm', 'postcode': '', 'lon': 18.0701904296875, 'lat': 59.3299560546875, 'source': 2336793900, 'score': 0, 'distance_m': 11.85489947514537}

Install

pip install korp-map-client             # pyarrow + httpx
pip install 'korp-map-client[geo]'      # + geopandas, shapely: map_gdf()
pip install 'korp-map-client[zstd,br]'  # + zstd / brotli Content-Encoding
pip install 'korp-map-client[all]'

Use

import korp_map_client

c = korp_map_client.Client("https://karta.gunnar.rs")  # the default; region = the first served one
c.regions()        # [{"name": "sweden", "bbox": [...], "data_version": "files-..."}]

res = c.map("lines", bbox=(17.9, 59.2, 18.2, 59.4), lod=14)
res.table          # pyarrow.Table; schema metadata kept (geo, data_version, ...)
res.truncated, res.data_version, res.geometry_source, res.row_groups_scanned
res.to_pandas()

gdf = c.map_gdf("areas", bbox=(17.9, 59.2, 18.2, 59.4), lod=12)   # GeoDataFrame, EPSG:4326
gdf.attrs["truncated"]

c.geocode("Drottninggatan 53 Stockholm", max=5)   # [{"street", "housenumber", "city", "postcode",
                                                  #   "lon", "lat", "source", "score"}, ...]
c.revgeocode(18.07, 59.33)                        # {..., "distance_m": 11.9} or None
  • kind is points (tagged nodes), lines or areas.
  • bbox is (minlon, minlat, maxlon, maxlat); lod (0 to 20 or so) keeps rows with min_zoom <= lod and picks the geometry detail (geometry_source: z6, z9, z12, full).
  • max=K caps the rows; the reply then says truncated=True.
  • compress="zstd" asks for zstd Arrow IPC buffers (pyarrow decodes them).
  • tags is a JSON string per row: res.to_pandas().tags.map(json.loads).
  • MapResult speaks the Arrow stream protocol: polars.from_arrow(res), duckdb.sql("from res").
  • c.map_table(...) gives the bare pyarrow.Table.
  • korp_map_client.geometry_to_shapely(col) turns a separated-layout geometry column (struct<x, y> in lists, GeoParquet 1.1) into shapely geometries, vectorised.

Files (/v1/files)

The server also offers its files for download: the native set (the GeoParquet 1.1 files it serves from) and geoparquet2 (GeoParquet 2.0 points, lines, areas).

c.files()      # [{"name", "set", "format", "size", "sha256", "url", "last_modified"}, ...]
url = c.file_url("geoparquet2/lines.parquet")  # absolute URL; a bare name works when unique
duckdb.sql(f"select count(*) from read_parquet('{url}')")   # DuckDB httpfs
gdal_path = "/vsicurl/" + url                               # GDAL / OGR

c.download("native/ways.multilinestring.parquet", "data/", progress=True)
# streams to data/<name>.part, resumes a broken download with HTTP Range,
# checks size + sha256, then renames into place; an intact file is not fetched again

t = c.read_parquet("native/ways.multilinestring.parquet", bbox=(18.05, 59.32, 18.08, 59.34),
                   columns=["id", "tags", "geometry"])
c.last_read   # {"row_groups_read": 25, "row_groups_total": 443, "bytes_fetched": 15661663, ...}
gdf = c.read_gdf("geoparquet2/lines.parquet", bbox=(18.05, 59.32, 18.08, 59.34))

read_parquet reads over HTTP Range requests (through the client's own connection, so https, verify= and headers apply) and fetches only the footer and the row groups whose statistics touch bbox: the covering bbox column (GeoParquet 1.1) or the geometry column's geospatial statistics (GeoParquet 2.0). Rows are then cut to those whose bbox touches bbox (by the covering column; for 2.0 WKB files by the geometry bounds when shapely is installed, else whole row groups). read_gdf gives a GeoDataFrame for WKB (2.0) and separated (native) geometry, CRS from the file.

Errors raise korp_map_client.KorpMapError; .code is the wire code (korp-map-108 for an unknown region, ...) and .status the HTTP status. Replies compressed with gzip, br or zstd are decoded transparently; Accept-Encoding names what is installed. https:// URLs work; extra keyword arguments go to httpx.Client (verify=, proxy=, ...).

Test

pip install -e '.[all,test]'
pytest                                          # the fake server
KORP_MAP_URL=https://karta.gunnar.rs pytest -m live   # a running server (Stockholm queries)
# tests/test_live_files.py skips while the server has no /v1/files;
# KORP_MAP_FILES=1 makes that a failure

License: MIT OR Apache-2.0.

Metadata

Release files for korp-map-client 0.2.1

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

Source distribution (sdist)

Source distribution for korp-map-client 0.2.1
File Size Uploaded Provenance Actions
korp_map_client-0.2.1.tar.gz 31.7 kB Without provenance Details for korp_map_client-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for korp-map-client 0.2.1
File Interpreter ABI Platform Actions
korp_map_client-0.2.1-py3-none-any.whl Python 3 none any Details for korp_map_client-0.2.1-py3-none-any.whl

Total release size: 54.8 kB

Release files / korp_map_client-0.2.1.tar.gz

Download URL korp_map_client-0.2.1.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2b74f2370795023cc8d7f1fc9b45232b2f8d0147c20d99d57710f36ddb4305d9
BLAKE2b-256 checksum
How to use checksums
106f18ee57008637bbe62b786bd1378fe36ca214a04a5852cb6c4db0b6dc4e54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / korp_map_client-0.2.1-py3-none-any.whl

Download URL korp_map_client-0.2.1-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8659dc4f8fe14ca508cf049bf13da84b9dd5e0d4f5bed2cc243dacc12515088
BLAKE2b-256 checksum
How to use checksums
0dbef344e04ef04aa84aa3d15458c817a729bacd0cb15d95baffe5e824ead8f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for korp-map-client 0.2.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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