Metadata-Version: 2.5
Name: korp-map-client
Version: 0.1.0
Summary: Python data client for the korp-map server: OpenStreetMap rows as Arrow tables, geocoding
Project-URL: Source, https://gunnar.rs/nordisk/korp-map
License-Expression: MIT OR Apache-2.0
License-File: LICENSE-APACHE
License-File: LICENSE-MIT
Keywords: arrow,geocoding,geoparquet,map,openstreetmap
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: pyarrow>=14
Provides-Extra: all
Requires-Dist: brotli>=1.0; extra == 'all'
Requires-Dist: geopandas>=0.14; extra == 'all'
Requires-Dist: shapely>=2.0; extra == 'all'
Requires-Dist: zstandard>=0.18; extra == 'all'
Provides-Extra: br
Requires-Dist: brotli>=1.0; extra == 'br'
Provides-Extra: geo
Requires-Dist: geopandas>=0.14; extra == 'geo'
Requires-Dist: shapely>=2.0; extra == 'geo'
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Provides-Extra: zstd
Requires-Dist: zstandard>=0.18; extra == 'zstd'
Description-Content-Type: text/markdown

# 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.

```sh
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

```python
import korp_map_client

c = korp_map_client.Client("http://83.190.65.118:8765")  # region = the first served region
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.

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

```sh
pip install -e '.[all,test]'
pytest                                          # the fake server
KORP_MAP_URL=http://127.0.0.1:8765 pytest -m live   # a running server (Stockholm queries)
```

License: MIT OR Apache-2.0.
