osmfeatures 1.0.2__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/PKG-INFO +29 -2
  2. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/README.md +28 -1
  3. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/pyproject.toml +1 -1
  4. osmfeatures-1.2.0/src/osmfeatures/_geocode.py +98 -0
  5. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/_query.py +11 -1
  6. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/async_client.py +51 -0
  7. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/client.py +77 -0
  8. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/mcp/AGENT_INSTRUCTIONS.md +3 -1
  9. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/mcp/_mcp_session.py +22 -4
  10. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/mcp/mcp_server.py +15 -1
  11. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/README.md +1 -1
  12. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_geo_agent.py +4 -5
  13. osmfeatures-1.2.0/tests/mcp/test_geocode.py +266 -0
  14. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/mcp/test_mcp_server.py +69 -14
  15. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/uv.lock +1 -1
  16. osmfeatures-1.0.2/src/osmfeatures/mcp/_geocode.py +0 -98
  17. osmfeatures-1.0.2/tests/mcp/test_geocode.py +0 -79
  18. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/.cursor/rules/maplark-mcp-dogfood.mdc +0 -0
  19. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/.github/copilot-instructions.md +0 -0
  20. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/.github/instructions/osmgeojson-python-conventions.instructions.md +0 -0
  21. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/.gitignore +0 -0
  22. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/AUTO_TILES.md +0 -0
  23. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/Dockerfile +0 -0
  24. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/LICENSE +0 -0
  25. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/Makefile +0 -0
  26. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/__init__.py +0 -0
  27. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/_geo_agent.py +0 -0
  28. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/_http.py +0 -0
  29. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/_pagination.py +0 -0
  30. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/_places.py +0 -0
  31. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/_split.py +0 -0
  32. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/chunking.py +0 -0
  33. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/cli.py +0 -0
  34. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/convenience.py +0 -0
  35. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/geometry.py +0 -0
  36. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/mcp/__init__.py +0 -0
  37. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/mcp/_preview.py +0 -0
  38. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/models.py +0 -0
  39. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/nearest.py +0 -0
  40. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/output.py +0 -0
  41. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/py.typed +0 -0
  42. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/src/osmfeatures/retry.py +0 -0
  43. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/.env.example +0 -0
  44. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/__init__.py +0 -0
  45. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/conftest.py +0 -0
  46. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/__init__.py +0 -0
  47. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/conftest.py +0 -0
  48. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/graph_utils.py +0 -0
  49. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_bike_path_dijkstra_liljeholmen_to_djurgarden.py +0 -0
  50. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_city_cycling_infrastructure.py +0 -0
  51. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_cycling_trails.py +0 -0
  52. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_flood_zone_buildings.py +0 -0
  53. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_geometry_filters.py +0 -0
  54. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_lakeside_ice_cream_hunt.py +0 -0
  55. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_park_bench_finder.py +0 -0
  56. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_park_explorer.py +0 -0
  57. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_pedestrian_shortest_path.py +0 -0
  58. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_pedestrian_wavefront_bfs.py +0 -0
  59. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_restaurant_guide.py +0 -0
  60. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/example_apps/test_split_until_fit.py +0 -0
  61. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/mcp/test_mcp_http.py +0 -0
  62. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/mcp/test_mcp_session.py +0 -0
  63. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/mcp/test_preview.py +0 -0
  64. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_async_client.py +0 -0
  65. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_chunking.py +0 -0
  66. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_cli.py +0 -0
  67. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_client.py +0 -0
  68. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_geo_agent_client.py +0 -0
  69. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_http.py +0 -0
  70. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_nearest_within.py +0 -0
  71. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_output.py +0 -0
  72. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_pagination.py +0 -0
  73. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_retry.py +0 -0
  74. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/test_split.py +0 -0
  75. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/tutorial/conftest.py +0 -0
  76. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/tutorial/osm_features_query.py +0 -0
  77. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/tutorial/places_nearby.py +0 -0
  78. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/tutorial/places_search.py +0 -0
  79. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tests/tutorial/test_tutorial.py +0 -0
  80. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tmp/preview_redraw.pid +0 -0
  81. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tmp/preview_redraw.url +0 -0
  82. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tmp/preview_sweden_buildings.pid +0 -0
  83. {osmfeatures-1.0.2 → osmfeatures-1.2.0}/tmp/sweden_amenities_combined.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: osmfeatures
3
- Version: 1.0.2
3
+ Version: 1.2.0
4
4
  Summary: Official client for the MapLark OpenStreetMap Features API (GeoJSON, FlatGeobuf, GeoParquet, CSV)
5
5
  Project-URL: Homepage, https://maplark.com
6
6
  Project-URL: Repository, https://github.com/MapLark/osmfeatures-python
@@ -63,6 +63,7 @@ Official Python client for the [MapLark OSM Features API](https://maplark.com) w
63
63
  - [Cursor / Claude Desktop](#cursor--claude-desktop)
64
64
  - [Typical AI questions](#typical-ai-questions)
65
65
  - [Places and routes](#places-and-routes)
66
+ - [Geocode](#geocode)
66
67
  - [Places search](#places-search)
67
68
  - [Nearby](#nearby-ranked-from-a-point)
68
69
  - [Place details](#place-details)
@@ -171,6 +172,8 @@ Common filters:
171
172
  - `type="node" | "way" | "relation"`
172
173
  - `way_shape="polygon" | "line" | "all"` (omit = both shapes; `all` also means both)
173
174
  - `clip_geometry=True | False` (omit for the API default; set `False` to keep full geometry outside bbox)
175
+ - `node_ids=False` drops way `properties.node_ids`, the ordered OSM node IDs (on by default; a closed way repeats the first ID). Smaller responses cost fewer credits
176
+ - `members=False` drops relation `properties.members`, the ordered OSM members as `{type, ref, role}` (on by default, like Overpass `out body`)
174
177
  - `bbox_tiles=2` (power of 2) to split a bbox that exceeds your tier area cap
175
178
  - `auto_split=True` to split and fetch directly (`auto_split_skip_count=False` to count first, then fetch; reads `max_limit` from `GET /v1/account/tier`, cached on the client; jumps to a power-of-2 grid when the match set exceeds that cap; one extra jump if a leftover leaf is still dense; a lower `limit` truncates; jumps when a 400 names a bbox-area cap). Caps at 16 tiles (`OSMFeaturesTooManyTilesError` if covering the bbox needs more, `OSMFeaturesTooDenseError` if a tile still overflows). `OSMFeaturesTimeoutError` is only a real wall-clock miss.
176
179
  - `accept="text/csv"` / `"application/flatgeobuf"` / `"application/vnd.apache.parquet"` (returns `BinaryQueryResult`)
@@ -282,7 +285,7 @@ Results come back as summaries (ids, names, OSM tags, lon/lat scalars, `distance
282
285
  #### Tools
283
286
 
284
287
  - Places: `places_search`, `places_nearby`, `places_details`
285
- - Geocode: `geocode` (Nominatim interim)
288
+ - Geocode: `geocode`, `geocode_reverse`, `geocode_status` (`GET /geocode/nominatim/{search,reverse,status}`)
286
289
  - Routes: `routes_isochrone`, `routes_path`, `routes_optimized_path`
287
290
  - Generic OSM: `query`, `count` (histogram / total), `density` (grid bins; `preview_map` the id)
288
291
  - Local (no HTTP): `nearest_within`, `pairs_within`, `filter_open`, `point_in_polygon`, `points_in_polygon`
@@ -362,6 +365,30 @@ These are the same operations as the MCP tools; call them on `OSMFeaturesClient`
362
365
 
363
366
  Runnable Python chains live in `tests/example_apps/test_geo_agent.py`. Full HTTP reference: [https://maplark.com/developer](https://maplark.com/developer).
364
367
 
368
+ ### Geocode
369
+
370
+ Nominatim search, reverse, and status. Nominatim's `boundingbox` (`[south, north, west, east]`) is remapped to MapLark `west,south,east,north` for `places_search` and `query`. MCP tools return the same objects.
371
+
372
+ `geocode()` is the top search hit (`GET /geocode/nominatim/search` with `format=json` and `limit=1`):
373
+
374
+ ```python
375
+ found = client.geocode("Södermalm, Stockholm")
376
+ bbox = found["place"]["bbox"]
377
+ # {"status": "ok", "place": {label, lon, lat, bbox, osm_type, osm_id}}
378
+ # or {"status": "no_results", "reason": ..., "place": None}
379
+ ```
380
+
381
+ `geocode_reverse(lat, lon)` is the place at a point (`GET /geocode/nominatim/reverse` with `format=json`). Optional `zoom` is Nominatim detail 0..18 (API default 18). Same `{status, place}` shape; no hit is `no_results`.
382
+
383
+ ```python
384
+ at = client.geocode_reverse(59.325, 18.071)
385
+ print(at["place"]["label"], at["place"]["bbox"])
386
+ ```
387
+
388
+ `geocode_status()` is geocoder health (`GET /geocode/nominatim/status?format=json`): `{"status": "ok", "message": "OK", "data_updated": ...}`. HTTP 503 raises `OSMFeaturesAPIError`.
389
+
390
+ Async: `geocode_async`, `geocode_reverse_async`, `geocode_status_async`.
391
+
365
392
  ### Places search
366
393
 
367
394
  `places_search()` finds places in a bounding box **or** a `location` plus `radius` (not both). `tags` items are AND (JSON array). `|` inside one item is OR (`tags=["amenity=cafe|amenity=bar"]`). A leading `!` excludes. Quote a value that contains `|` or `&`. Unquoted `&` is not AND. Omit `limit` to use the API default (100). Paid keys may raise `limit` up to their `/v3` `max_limit`; `asOf` / `openNow` still cap hours parse at 10_000.
@@ -20,6 +20,7 @@ Official Python client for the [MapLark OSM Features API](https://maplark.com) w
20
20
  - [Cursor / Claude Desktop](#cursor--claude-desktop)
21
21
  - [Typical AI questions](#typical-ai-questions)
22
22
  - [Places and routes](#places-and-routes)
23
+ - [Geocode](#geocode)
23
24
  - [Places search](#places-search)
24
25
  - [Nearby](#nearby-ranked-from-a-point)
25
26
  - [Place details](#place-details)
@@ -128,6 +129,8 @@ Common filters:
128
129
  - `type="node" | "way" | "relation"`
129
130
  - `way_shape="polygon" | "line" | "all"` (omit = both shapes; `all` also means both)
130
131
  - `clip_geometry=True | False` (omit for the API default; set `False` to keep full geometry outside bbox)
132
+ - `node_ids=False` drops way `properties.node_ids`, the ordered OSM node IDs (on by default; a closed way repeats the first ID). Smaller responses cost fewer credits
133
+ - `members=False` drops relation `properties.members`, the ordered OSM members as `{type, ref, role}` (on by default, like Overpass `out body`)
131
134
  - `bbox_tiles=2` (power of 2) to split a bbox that exceeds your tier area cap
132
135
  - `auto_split=True` to split and fetch directly (`auto_split_skip_count=False` to count first, then fetch; reads `max_limit` from `GET /v1/account/tier`, cached on the client; jumps to a power-of-2 grid when the match set exceeds that cap; one extra jump if a leftover leaf is still dense; a lower `limit` truncates; jumps when a 400 names a bbox-area cap). Caps at 16 tiles (`OSMFeaturesTooManyTilesError` if covering the bbox needs more, `OSMFeaturesTooDenseError` if a tile still overflows). `OSMFeaturesTimeoutError` is only a real wall-clock miss.
133
136
  - `accept="text/csv"` / `"application/flatgeobuf"` / `"application/vnd.apache.parquet"` (returns `BinaryQueryResult`)
@@ -239,7 +242,7 @@ Results come back as summaries (ids, names, OSM tags, lon/lat scalars, `distance
239
242
  #### Tools
240
243
 
241
244
  - Places: `places_search`, `places_nearby`, `places_details`
242
- - Geocode: `geocode` (Nominatim interim)
245
+ - Geocode: `geocode`, `geocode_reverse`, `geocode_status` (`GET /geocode/nominatim/{search,reverse,status}`)
243
246
  - Routes: `routes_isochrone`, `routes_path`, `routes_optimized_path`
244
247
  - Generic OSM: `query`, `count` (histogram / total), `density` (grid bins; `preview_map` the id)
245
248
  - Local (no HTTP): `nearest_within`, `pairs_within`, `filter_open`, `point_in_polygon`, `points_in_polygon`
@@ -319,6 +322,30 @@ These are the same operations as the MCP tools; call them on `OSMFeaturesClient`
319
322
 
320
323
  Runnable Python chains live in `tests/example_apps/test_geo_agent.py`. Full HTTP reference: [https://maplark.com/developer](https://maplark.com/developer).
321
324
 
325
+ ### Geocode
326
+
327
+ Nominatim search, reverse, and status. Nominatim's `boundingbox` (`[south, north, west, east]`) is remapped to MapLark `west,south,east,north` for `places_search` and `query`. MCP tools return the same objects.
328
+
329
+ `geocode()` is the top search hit (`GET /geocode/nominatim/search` with `format=json` and `limit=1`):
330
+
331
+ ```python
332
+ found = client.geocode("Södermalm, Stockholm")
333
+ bbox = found["place"]["bbox"]
334
+ # {"status": "ok", "place": {label, lon, lat, bbox, osm_type, osm_id}}
335
+ # or {"status": "no_results", "reason": ..., "place": None}
336
+ ```
337
+
338
+ `geocode_reverse(lat, lon)` is the place at a point (`GET /geocode/nominatim/reverse` with `format=json`). Optional `zoom` is Nominatim detail 0..18 (API default 18). Same `{status, place}` shape; no hit is `no_results`.
339
+
340
+ ```python
341
+ at = client.geocode_reverse(59.325, 18.071)
342
+ print(at["place"]["label"], at["place"]["bbox"])
343
+ ```
344
+
345
+ `geocode_status()` is geocoder health (`GET /geocode/nominatim/status?format=json`): `{"status": "ok", "message": "OK", "data_updated": ...}`. HTTP 503 raises `OSMFeaturesAPIError`.
346
+
347
+ Async: `geocode_async`, `geocode_reverse_async`, `geocode_status_async`.
348
+
322
349
  ### Places search
323
350
 
324
351
  `places_search()` finds places in a bounding box **or** a `location` plus `radius` (not both). `tags` items are AND (JSON array). `|` inside one item is OR (`tags=["amenity=cafe|amenity=bar"]`). A leading `!` excludes. Quote a value that contains `|` or `&`. Unquoted `&` is not AND. Omit `limit` to use the API default (100). Paid keys may raise `limit` up to their `/v3` `max_limit`; `asOf` / `openNow` still cap hours parse at 10_000.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "osmfeatures"
7
- version = "1.0.2"
7
+ version = "1.2.0"
8
8
  description = "Official client for the MapLark OpenStreetMap Features API (GeoJSON, FlatGeobuf, GeoParquet, CSV)"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -0,0 +1,98 @@
1
+ """MapLark Nominatim-compatible search, reverse, and status.
2
+
3
+ ``GET /geocode/nominatim/search`` and ``/reverse`` return Nominatim JSON
4
+ (``lat``, ``lon``, ``display_name``, ``boundingbox`` as south, north, west, east).
5
+ ``GET /geocode/nominatim/status`` with ``format=json`` is geocoder health.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+ NOMINATIM_SEARCH_PATH = "/geocode/nominatim/search"
13
+ NOMINATIM_REVERSE_PATH = "/geocode/nominatim/reverse"
14
+ NOMINATIM_STATUS_PATH = "/geocode/nominatim/status"
15
+
16
+ _NO_RESULTS = {
17
+ "status": "no_results",
18
+ "reason": "Geocoder returned no candidates.",
19
+ "place": None,
20
+ }
21
+
22
+
23
+ def bbox_from_nominatim(boundingbox: Any) -> str | None:
24
+ """Nominatim ``[south, north, west, east]`` → MapLark ``west,south,east,north``."""
25
+ if not isinstance(boundingbox, (list, tuple)) or len(boundingbox) != 4:
26
+ return None
27
+ south, north, west, east = (str(x).strip() for x in boundingbox)
28
+ if not all((south, north, west, east)):
29
+ return None
30
+ return f"{west},{south},{east},{north}"
31
+
32
+
33
+ def _place_from_hit(hit: Any, *, query: str) -> dict[str, Any]:
34
+ """One Nominatim place as ``{status, place}``, or ``no_results``."""
35
+ if not isinstance(hit, dict):
36
+ return dict(_NO_RESULTS)
37
+ try:
38
+ lon = float(hit["lon"])
39
+ lat = float(hit["lat"])
40
+ except (KeyError, TypeError, ValueError):
41
+ return {
42
+ "status": "no_results",
43
+ "reason": "Geocoder hit had no lon/lat.",
44
+ "place": None,
45
+ }
46
+
47
+ label = hit.get("display_name") or hit.get("name") or query
48
+ place: dict[str, Any] = {
49
+ "label": str(label),
50
+ "lon": lon,
51
+ "lat": lat,
52
+ "bbox": bbox_from_nominatim(hit.get("boundingbox")),
53
+ }
54
+ if hit.get("osm_type") is not None:
55
+ place["osm_type"] = hit["osm_type"]
56
+ if hit.get("osm_id") is not None:
57
+ place["osm_id"] = hit["osm_id"]
58
+ return {"status": "ok", "place": place}
59
+
60
+
61
+ def geocode_result(payload: Any, *, query: str) -> dict[str, Any]:
62
+ """Top search hit as ``{status, place}``. ``place`` is lon/lat + bbox, no GeoJSON."""
63
+ if not isinstance(payload, list) or not payload:
64
+ return dict(_NO_RESULTS)
65
+ return _place_from_hit(payload[0], query=query)
66
+
67
+
68
+ def geocode_reverse_result(payload: Any, *, query: str) -> dict[str, Any]:
69
+ """Reverse hit as ``{status, place}``. Nominatim no-hit is ``{"error": ...}``."""
70
+ if isinstance(payload, dict) and payload.get("error"):
71
+ return {
72
+ "status": "no_results",
73
+ "reason": str(payload["error"]),
74
+ "place": None,
75
+ }
76
+ return _place_from_hit(payload, query=query)
77
+
78
+
79
+ def geocode_status_result(payload: Any) -> dict[str, Any]:
80
+ """Nominatim ``format=json`` status as ``{status, message, data_updated}``."""
81
+ if not isinstance(payload, dict):
82
+ return {
83
+ "status": "unavailable",
84
+ "message": "Geocoder status was not JSON.",
85
+ }
86
+ message = payload.get("message")
87
+ if payload.get("status") == 0:
88
+ out: dict[str, Any] = {
89
+ "status": "ok",
90
+ "message": str(message) if message is not None else "OK",
91
+ }
92
+ if payload.get("data_updated") is not None:
93
+ out["data_updated"] = payload["data_updated"]
94
+ return out
95
+ return {
96
+ "status": "unavailable",
97
+ "message": str(message) if message is not None else "Geocoder unavailable.",
98
+ }
@@ -81,7 +81,7 @@ disable_budget_warning:
81
81
  bbox_tiles, auto_split, auto_split_skip_count, timeout:
82
82
  See above.
83
83
  osm_ids, within, way_shape, shape, zoom, min_length_m, max_length_m,
84
- min_area_m2, max_area_m2, centroid, clip_geometry, geometry:
84
+ min_area_m2, max_area_m2, centroid, node_ids, members, clip_geometry, geometry:
85
85
  Additional filters and output options, passed through to the API.
86
86
 
87
87
  Raises
@@ -132,6 +132,8 @@ def _query_filters(
132
132
  min_area_m2: float | None = None,
133
133
  max_area_m2: float | None = None,
134
134
  centroid: bool | None = None,
135
+ node_ids: bool | None = None,
136
+ members: bool | None = None,
135
137
  clip_geometry: bool | None = None,
136
138
  geometry: Any = None,
137
139
  ) -> dict[str, Any]:
@@ -167,6 +169,10 @@ def _query_filters(
167
169
  params["max_area_m2"] = max_area_m2
168
170
  if centroid is not None:
169
171
  params["centroid"] = centroid
172
+ if node_ids is not None:
173
+ params["node_ids"] = node_ids
174
+ if members is not None:
175
+ params["members"] = members
170
176
  if clip_geometry is not None:
171
177
  params["clip_geometry"] = clip_geometry
172
178
  if geometry is not None:
@@ -195,6 +201,8 @@ async def execute_query(
195
201
  min_area_m2: float | None = None,
196
202
  max_area_m2: float | None = None,
197
203
  centroid: bool | None = None,
204
+ node_ids: bool | None = None,
205
+ members: bool | None = None,
198
206
  clip_geometry: bool | None = None,
199
207
  geometry: Any = None,
200
208
  accept: str | None = None,
@@ -223,6 +231,8 @@ async def execute_query(
223
231
  min_area_m2=min_area_m2,
224
232
  max_area_m2=max_area_m2,
225
233
  centroid=centroid,
234
+ node_ids=node_ids,
235
+ members=members,
226
236
  clip_geometry=clip_geometry,
227
237
  geometry=geometry,
228
238
  )
@@ -6,6 +6,14 @@ from typing import Any
6
6
 
7
7
  import httpx
8
8
 
9
+ from ._geocode import (
10
+ NOMINATIM_REVERSE_PATH,
11
+ NOMINATIM_SEARCH_PATH,
12
+ NOMINATIM_STATUS_PATH,
13
+ geocode_result,
14
+ geocode_reverse_result,
15
+ geocode_status_result,
16
+ )
9
17
  from ._geo_agent import (
10
18
  PLACES_NEARBY_PATH,
11
19
  PLACES_SEARCH_PATH,
@@ -193,6 +201,8 @@ class AsyncOSMFeaturesClient:
193
201
  min_area_m2: float | None = None,
194
202
  max_area_m2: float | None = None,
195
203
  centroid: bool | None = None,
204
+ node_ids: bool | None = None,
205
+ members: bool | None = None,
196
206
  clip_geometry: bool | None = None,
197
207
  geometry: Any = None,
198
208
  accept: str | None = None,
@@ -223,6 +233,8 @@ class AsyncOSMFeaturesClient:
223
233
  min_area_m2=min_area_m2,
224
234
  max_area_m2=max_area_m2,
225
235
  centroid=centroid,
236
+ node_ids=node_ids,
237
+ members=members,
226
238
  clip_geometry=clip_geometry,
227
239
  geometry=geometry,
228
240
  accept=accept,
@@ -700,6 +712,45 @@ class AsyncOSMFeaturesClient:
700
712
  ),
701
713
  )
702
714
 
715
+ async def geocode_async(self, q: str) -> dict[str, Any]:
716
+ """Top hit for a place name (``GET /geocode/nominatim/search``).
717
+
718
+ Same payload as :meth:`OSMFeaturesClient.geocode`.
719
+ """
720
+ text = (q or "").strip()
721
+ if not text:
722
+ return {"status": "no_results", "reason": "Empty query.", "place": None}
723
+ payload: Any = await self._get_json(
724
+ NOMINATIM_SEARCH_PATH,
725
+ {"q": text, "format": "json", "limit": 1},
726
+ )
727
+ return geocode_result(payload, query=text)
728
+
729
+ async def geocode_reverse_async(
730
+ self,
731
+ lat: float,
732
+ lon: float,
733
+ *,
734
+ zoom: int | None = None,
735
+ ) -> dict[str, Any]:
736
+ """Place at a point (``GET /geocode/nominatim/reverse``).
737
+
738
+ Same payload as :meth:`OSMFeaturesClient.geocode_reverse`.
739
+ """
740
+ params: dict[str, Any] = {"lat": lat, "lon": lon, "format": "json"}
741
+ if zoom is not None:
742
+ params["zoom"] = zoom
743
+ payload: Any = await self._get_json(NOMINATIM_REVERSE_PATH, params)
744
+ return geocode_reverse_result(payload, query=f"{lat},{lon}")
745
+
746
+ async def geocode_status_async(self) -> dict[str, Any]:
747
+ """Geocoder health (``GET /geocode/nominatim/status?format=json``).
748
+
749
+ Same payload as :meth:`OSMFeaturesClient.geocode_status`.
750
+ """
751
+ payload: Any = await self._get_json(NOMINATIM_STATUS_PATH, {"format": "json"})
752
+ return geocode_status_result(payload)
753
+
703
754
  async def close(self) -> None:
704
755
  """Close the underlying HTTP client."""
705
756
  if self._client is not None:
@@ -6,6 +6,14 @@ from typing import Any
6
6
 
7
7
  import requests
8
8
 
9
+ from ._geocode import (
10
+ NOMINATIM_REVERSE_PATH,
11
+ NOMINATIM_SEARCH_PATH,
12
+ NOMINATIM_STATUS_PATH,
13
+ geocode_result,
14
+ geocode_reverse_result,
15
+ geocode_status_result,
16
+ )
9
17
  from ._geo_agent import (
10
18
  PLACES_NEARBY_PATH,
11
19
  PLACES_SEARCH_PATH,
@@ -192,6 +200,8 @@ class OSMFeaturesClient:
192
200
  min_area_m2: float | None = None,
193
201
  max_area_m2: float | None = None,
194
202
  centroid: bool | None = None,
203
+ node_ids: bool | None = None,
204
+ members: bool | None = None,
195
205
  clip_geometry: bool | None = None,
196
206
  geometry: Any = None,
197
207
  accept: str | None = None,
@@ -222,6 +232,8 @@ class OSMFeaturesClient:
222
232
  min_area_m2=min_area_m2,
223
233
  max_area_m2=max_area_m2,
224
234
  centroid=centroid,
235
+ node_ids=node_ids,
236
+ members=members,
225
237
  clip_geometry=clip_geometry,
226
238
  geometry=geometry,
227
239
  accept=accept,
@@ -741,6 +753,71 @@ class OSMFeaturesClient:
741
753
  ),
742
754
  )
743
755
 
756
+ def geocode(self, q: str) -> dict[str, Any]:
757
+ """Top hit for a place name (``GET /geocode/nominatim/search``).
758
+
759
+ Parameters
760
+ ----------
761
+ q:
762
+ Free-text place name or address.
763
+
764
+ Returns
765
+ -------
766
+ dict
767
+ ``{"status": "ok", "place": {label, lon, lat, bbox, osm_type, osm_id}}``
768
+ or ``{"status": "no_results", "reason": ..., "place": None}``.
769
+ ``bbox`` is ``west,south,east,north`` for ``places_search`` and ``query``.
770
+ """
771
+ text = (q or "").strip()
772
+ if not text:
773
+ return {"status": "no_results", "reason": "Empty query.", "place": None}
774
+ payload: Any = self._get_json(
775
+ NOMINATIM_SEARCH_PATH,
776
+ {"q": text, "format": "json", "limit": 1},
777
+ )
778
+ return geocode_result(payload, query=text)
779
+
780
+ def geocode_reverse(
781
+ self,
782
+ lat: float,
783
+ lon: float,
784
+ *,
785
+ zoom: int | None = None,
786
+ ) -> dict[str, Any]:
787
+ """Place at a point (``GET /geocode/nominatim/reverse``).
788
+
789
+ Parameters
790
+ ----------
791
+ lat, lon:
792
+ Point to reverse-geocode.
793
+ zoom:
794
+ Nominatim detail 0..18 (omit for the API default, 18).
795
+
796
+ Returns
797
+ -------
798
+ dict
799
+ Same ``{status, place}`` shape as :meth:`geocode`, or
800
+ ``{"status": "no_results", "reason": ..., "place": None}``.
801
+ """
802
+ params: dict[str, Any] = {"lat": lat, "lon": lon, "format": "json"}
803
+ if zoom is not None:
804
+ params["zoom"] = zoom
805
+ payload: Any = self._get_json(NOMINATIM_REVERSE_PATH, params)
806
+ return geocode_reverse_result(payload, query=f"{lat},{lon}")
807
+
808
+ def geocode_status(self) -> dict[str, Any]:
809
+ """Geocoder health (``GET /geocode/nominatim/status?format=json``).
810
+
811
+ Returns
812
+ -------
813
+ dict
814
+ ``{"status": "ok", "message": "OK", "data_updated": ...}`` when
815
+ the geocoder is up. HTTP 503 raises
816
+ :class:`~osmfeatures.OSMFeaturesAPIError`.
817
+ """
818
+ payload: Any = self._get_json(NOMINATIM_STATUS_PATH, {"format": "json"})
819
+ return geocode_status_result(payload)
820
+
744
821
  def close(self) -> None:
745
822
  """Close the underlying HTTP session."""
746
823
  self._session.close()
@@ -12,6 +12,8 @@ first and use the returned bbox (or lat/lng + radius when bbox is null). If they
12
12
  said "me", "here", "near me", or similar and you have no viewport bbox or
13
13
  location+radius, stop and ask for a specific place. Do not geocode "me". Do not
14
14
  invent a lon/lat. query location is numeric "lat,lng", not a place name.
15
+ A known point to a place name is geocode_reverse, not geocode. Do not call
16
+ geocode_status unless asked whether the geocoder is up.
15
17
 
16
18
  Tag filters: list items AND together (sent as one tags value joined by commas). Inside one item,
17
19
  | is OR and a leading ! excludes. Key only (bare key) matches any value.
@@ -87,7 +89,7 @@ Do not invent places_near_to or places_open_after.
87
89
 
88
90
  Choose a tool:
89
91
  - Named POI (cafe, bar, shop) in a named place: geocode, then places_search.
90
- Point ranking: places_nearby.
92
+ Point ranking: places_nearby. A lon/lat to a place: geocode_reverse.
91
93
  - Open at / after a clock: places_search with as_of and no open_now, then
92
94
  filter_open.
93
95
  - How many or a breakdown (cuisine): count. Neighborhood name lists stay
@@ -9,7 +9,6 @@ omit coordinate arrays.
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
- import asyncio
13
12
  import hashlib
14
13
  import inspect
15
14
  import json
@@ -22,7 +21,6 @@ from .._geo_agent import normalize_travel_mode
22
21
  from ..geometry import point_in_geometry
23
22
  from ..models import DensityFeatureCollection, OSMFeatureCollection
24
23
  from ..nearest import MAX_COMPARISONS, nearest_within, pairs_within
25
- from ._geocode import nominatim_geocode
26
24
  from ._preview import is_density_grid, normalize_save_as, validate_collection_id
27
25
 
28
26
  # Planner summaries list at most this many items; ``count`` is still the full total.
@@ -756,8 +754,26 @@ class GeoAgentSession:
756
754
  return out
757
755
 
758
756
  async def geocode(self, q: str) -> dict[str, Any]:
759
- """Place name to lon/lat + bbox. Nominatim until MapLark geocode ships."""
760
- return await asyncio.to_thread(nominatim_geocode, q)
757
+ """Place name to lon/lat and bbox (``GET /geocode/nominatim/search``)."""
758
+ return await invoke_client(self._client, "geocode", q)
759
+
760
+ async def geocode_reverse(
761
+ self,
762
+ lat: float,
763
+ lon: float,
764
+ zoom: int | None = None,
765
+ ) -> dict[str, Any]:
766
+ """Point to lon/lat and bbox (``GET /geocode/nominatim/reverse``)."""
767
+ kwargs: dict[str, Any] = {}
768
+ if zoom is not None:
769
+ kwargs["zoom"] = zoom
770
+ return await invoke_client(
771
+ self._client, "geocode_reverse", lat, lon, **kwargs
772
+ )
773
+
774
+ async def geocode_status(self) -> dict[str, Any]:
775
+ """Geocoder health (``GET /geocode/nominatim/status``)."""
776
+ return await invoke_client(self._client, "geocode_status")
761
777
 
762
778
  async def routes_isochrone(
763
779
  self,
@@ -863,6 +879,8 @@ class GeoAgentSession:
863
879
  within=within,
864
880
  zoom=zoom,
865
881
  centroid=True,
882
+ node_ids=False, # way node IDs bloat agent context
883
+ members=False, # so do relation member lists
866
884
  limit=limit,
867
885
  auto_split=auto_split,
868
886
  auto_split_skip_count=auto_split_skip_count,
@@ -195,9 +195,23 @@ def build_server(
195
195
 
196
196
  @mcp.tool()
197
197
  async def geocode(q: str) -> dict[str, Any]:
198
- """Place name to lon/lat and bbox (Nominatim until MapLark geocode ships). Use bbox for places_search."""
198
+ """Place name to lon/lat and bbox. Use bbox for places_search."""
199
199
  return await get_session().geocode(q)
200
200
 
201
+ @mcp.tool()
202
+ async def geocode_reverse(
203
+ lat: float,
204
+ lon: float,
205
+ zoom: int | None = None,
206
+ ) -> dict[str, Any]:
207
+ """Point to lon/lat and bbox. Use bbox for places_search. zoom is Nominatim detail 0..18."""
208
+ return await get_session().geocode_reverse(lat, lon, zoom=zoom)
209
+
210
+ @mcp.tool()
211
+ async def geocode_status() -> dict[str, Any]:
212
+ """Nominatim geocoder health. Not a place lookup."""
213
+ return await get_session().geocode_status()
214
+
201
215
  @mcp.tool()
202
216
  async def routes_isochrone(
203
217
  lon: float,
@@ -42,7 +42,7 @@ python3 -m pytest tests/test_client.py::test_query_returns_feature_collection -v
42
42
  | `mcp/test_mcp_server.py` | `build_server()` tool names, `instructions`, FastMCP `call_tool` wiring |
43
43
  | `mcp/test_mcp_http.py` | Streamable HTTP Bearer 401, initialize + tools/list, per-session `fc_N` isolation |
44
44
  | `mcp/test_preview.py` | Local MapLibre preview HTTP (OpenFreeMap, no geometry in planner payload) |
45
- | `mcp/test_geocode.py` | Nominatim geocode tool (bbox remap, empty query, session does not store a collection) |
45
+ | `mcp/test_geocode.py` | MapLark geocode (`/geocode/nominatim/search`, `/reverse`, `/status`: bbox remap, empty query, session does not store a collection) |
46
46
  | `test_retry.py` | Retry + backoff: 429->200, exhausted retries, monthly limit, `Retry-After` header |
47
47
  | `test_pagination.py` | `query` / `query_all` on `/v3/osm_features`, `bbox_tiles`, `auto_split` |
48
48
  | `test_geo_agent_client.py` | Places/routes SDK methods, `places_search` `bbox_tiles` / `auto_split` |
@@ -2,12 +2,12 @@
2
2
  App idea: deterministic geo-agent tool chains (no LLM planner).
3
3
 
4
4
  Scenario 1 — "find a bar crawl in Södermalm in Stockholm"
5
- 1. hardcoded Södermalm origin (geocode skipped until Photon is wired)
5
+ 1. hardcoded Södermalm origin
6
6
  2. client.places_search — bars/pubs (optional openNow+asOf for evening)
7
7
  3. client.routes_optimized_path — walkable loop through 10 stops
8
8
 
9
9
  Scenario 2 — "bike through parks in Stockholm with a cafe open at 3pm"
10
- 1. hardcoded Djurgården origin (geocode skipped until Photon is wired)
10
+ 1. hardcoded Djurgården origin
11
11
  2. client.places_nearby — cafes/restaurants/bars openNow at 15:00, nearest first
12
12
  3. client.routes_optimized_path — bicycle loop through the stops
13
13
  4. client.query — park polygons; assert route crosses one
@@ -58,14 +58,13 @@ from osmfeatures.chunking import (
58
58
  tile_count_for_corridor,
59
59
  )
60
60
 
61
- # Hardcoded Stockholm anchors. Restore client.geocode via _resolve_place when Photon
62
- # is actually served (public photon.komoot.io 403s / times out from this host).
61
+ # Hardcoded Stockholm anchors so these chains do not depend on geocode.
63
62
  _SODERMALM_BBOX = "18.055,59.308,18.095,59.325"
64
63
  _SODERMALM_CENTER = {"lon": 18.075, "lat": 59.316}
65
64
  _WALK_RADIUS_M = 1200
66
65
  _TARGET_BARS = 10
67
66
 
68
- # Hardcoded Djurgården (same reason as Södermalm).
67
+ # Hardcoded Djurgården.
69
68
  _DJURGARDEN_BBOX = "18.085,59.318,18.125,59.335"
70
69
  _DJURGARDEN_CENTER = {"lon": 18.105, "lat": 59.3265}
71
70
  _BIKE_RADIUS_M = 1500