Skip to content

Commit bb97f98

Browse files
fatwang2claude
andauthored
Add maps() for the Maps API, release 0.5.0 (#5)
Sync the OpenAPI snapshot with the live contract (adds POST /maps and the 50-item batch limit) and add maps() to the sync and async clients with country, language, location, page and max_results. Claude-Session: https://claude.ai/code/session_01DuYf7vcVyyiBvDBCtA6mHH Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0d306f9 commit bb97f98

8 files changed

Lines changed: 644 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.5.0 - 2026-11-03
4+
5+
Adds `maps(query, ...)` on `Search1API` and `AsyncSearch1API` for `POST /maps`: one Google Maps page of up to 20 places with name, place ID and Maps link, plus address, phone, website, rating, review count, coordinates and opening hours when available. Keyword arguments: `country`, `language`, `location` (`latitude`, `longitude`, optional `zoom`), `page` (1-6, pages after the first need `location`) and `max_results`. 3 credits per completed page; API key or OAuth only. The bundled OpenAPI snapshot also records the 50-item batch limit for search, news and crawl.
6+
37
## 0.4.0 - 2026-10-12
48

59
Breaking: search/news engine-specific fields move from each result's top level to optional `metadata` (`kind`, `stars`, `language`, `num_comments`, `points`, `story_url`). Read e.g. `result.metadata.stars` instead of `result.stars`. `published_date` stays at the top level. No legacy field aliases.

‎README.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ A completed request costs 5 credits. Ask is not available with pay-per-request
7070
payments, and its default timeout is 45 seconds. Use `search` when you already
7171
know which engine and keywords you want.
7272

73+
## Maps
74+
75+
`maps` searches Google Maps and returns one page of up to 20 places. Each place
76+
has a name, place ID and Maps link, plus address, phone, website, rating,
77+
review count, coordinates and opening hours when available:
78+
79+
```python
80+
places = client.maps(
81+
"coffee shops",
82+
location={"latitude": 40.7455, "longitude": -74.0083, "zoom": 15},
83+
max_results=10,
84+
)
85+
86+
for place in places["results"]:
87+
print(place["name"], place.get("rating"), place.get("address"))
88+
```
89+
90+
A completed page costs 3 credits, including a confirmed empty page.
91+
`max_results` only trims the page and does not lower the price. Request `page`
92+
2-6 with the same query and `location` for more places; each page is billed
93+
separately. Maps is not available with pay-per-request payments.
94+
7395
## Deepcrawl
7496

7597
`deepcrawl` starts a task and waits for it to finish:

‎openapi/search1api.openapi.json‎

Lines changed: 398 additions & 6 deletions
Large diffs are not rendered by default.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "search1api"
7-
version = "0.4.0"
7+
version = "0.5.0"
88
description = "Official Python client for Search1API"
99
readme = "README.md"
1010
license = { file = "LICENSE" }

‎src/search1api/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
"UnprocessableEntityError",
3636
]
3737

38-
__version__ = "0.4.0"
38+
__version__ = "0.5.0"

‎src/search1api/client.py‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
FeedbackCategory,
3434
FeedbackResponse,
3535
HealthResponse,
36+
MapsLocation,
37+
MapsResponse,
3638
NewsEngine,
3739
NewsRequest,
3840
NewsResponse,
@@ -64,6 +66,27 @@ def _compact(payload: Mapping[str, Any]) -> Dict[str, Any]:
6466
return {key: value for key, value in payload.items() if value is not None}
6567

6668

69+
def _maps_payload(
70+
query: str,
71+
*,
72+
country: Optional[str],
73+
language: Optional[str],
74+
location: Optional[MapsLocation],
75+
page: Optional[int],
76+
max_results: Optional[int],
77+
) -> Dict[str, Any]:
78+
return _compact(
79+
{
80+
"query": query,
81+
"country": country,
82+
"language": language,
83+
"location": dict(location) if location is not None else None,
84+
"page": page,
85+
"max_results": max_results,
86+
}
87+
)
88+
89+
6790
def _search_payload(
6891
query: str,
6992
*,
@@ -321,6 +344,30 @@ def ask(self, query: str, *, timeout: float = DEFAULT_ASK_TIMEOUT) -> AskRespons
321344
self._request_json("POST", "/ask", json={"query": query}, timeout=timeout),
322345
)
323346

347+
def maps(
348+
self,
349+
query: str,
350+
*,
351+
country: Optional[str] = None,
352+
language: Optional[str] = None,
353+
location: Optional[MapsLocation] = None,
354+
page: Optional[int] = None,
355+
max_results: Optional[int] = None,
356+
) -> MapsResponse:
357+
"""Google Maps place search: one page of up to 20 places.
358+
359+
A completed page costs 3 credits. Pages after the first need ``location``.
360+
"""
361+
payload = _maps_payload(
362+
query,
363+
country=country,
364+
language=language,
365+
location=location,
366+
page=page,
367+
max_results=max_results,
368+
)
369+
return cast(MapsResponse, self._request_json("POST", "/maps", json=payload))
370+
324371
def crawl(
325372
self, url: str, *, enable_fallback: Optional[bool] = None
326373
) -> CrawlResponse:
@@ -683,6 +730,36 @@ async def ask(
683730
),
684731
)
685732

733+
async def maps(
734+
self,
735+
query: str,
736+
*,
737+
country: Optional[str] = None,
738+
language: Optional[str] = None,
739+
location: Optional[MapsLocation] = None,
740+
page: Optional[int] = None,
741+
max_results: Optional[int] = None,
742+
) -> MapsResponse:
743+
"""Google Maps place search: one page of up to 20 places.
744+
745+
A completed page costs 3 credits. Pages after the first need ``location``.
746+
"""
747+
return cast(
748+
MapsResponse,
749+
await self._request_json(
750+
"POST",
751+
"/maps",
752+
json=_maps_payload(
753+
query,
754+
country=country,
755+
language=language,
756+
location=location,
757+
page=page,
758+
max_results=max_results,
759+
),
760+
),
761+
)
762+
686763
async def crawl(
687764
self, url: str, *, enable_fallback: Optional[bool] = None
688765
) -> CrawlResponse:

‎src/search1api/types.py‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,70 @@ class AskResponse(TypedDict):
126126
errors: List[AskError]
127127

128128

129+
class MapsLocationRequired(TypedDict):
130+
latitude: float
131+
longitude: float
132+
133+
134+
class MapsLocation(MapsLocationRequired, total=False):
135+
zoom: float
136+
137+
138+
class MapsCoordinates(TypedDict):
139+
latitude: float
140+
longitude: float
141+
142+
143+
class MapsOpeningHours(TypedDict, total=False):
144+
monday: str
145+
tuesday: str
146+
wednesday: str
147+
thursday: str
148+
friday: str
149+
saturday: str
150+
sunday: str
151+
152+
153+
class MapsPlaceRequired(TypedDict):
154+
position: int
155+
name: str
156+
place_id: str
157+
maps_url: str
158+
159+
160+
class MapsPlace(MapsPlaceRequired, total=False):
161+
address: str
162+
phone: str
163+
website: str
164+
thumbnail: str
165+
category: str
166+
categories: List[str]
167+
rating: float
168+
review_count: int
169+
coordinates: MapsCoordinates
170+
opening_hours: MapsOpeningHours
171+
open_state: str
172+
price: str
173+
description: str
174+
175+
176+
class MapsParametersRequired(TypedDict):
177+
query: str
178+
country: str
179+
language: str
180+
page: int
181+
max_results: int
182+
183+
184+
class MapsParameters(MapsParametersRequired, total=False):
185+
location: MapsLocation
186+
187+
188+
class MapsResponse(TypedDict):
189+
searchParameters: MapsParameters
190+
results: List[MapsPlace]
191+
192+
129193
FeedbackCategory = Literal["bug", "feature_request", "docs", "other"]
130194

131195

‎tests/test_client.py‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,82 @@ def handler(request):
305305
http_client.close()
306306

307307

308+
def test_maps_sends_location_and_paging():
309+
seen = []
310+
body = {
311+
"searchParameters": {
312+
"query": "coffee shops",
313+
"country": "us",
314+
"language": "en",
315+
"location": {"latitude": 40.7455, "longitude": -74.0083, "zoom": 15},
316+
"page": 2,
317+
"max_results": 5,
318+
},
319+
"results": [
320+
{
321+
"position": 21,
322+
"name": "Example Coffee",
323+
"place_id": "ChIJ123",
324+
"maps_url": "https://www.google.com/maps/search/?api=1&query=Example",
325+
"rating": 4.6,
326+
}
327+
],
328+
}
329+
330+
def handler(request):
331+
seen.append(request)
332+
return json_response(200, body, request)
333+
334+
http_client = httpx.Client(transport=httpx.MockTransport(handler))
335+
client = Search1API("test-key", client=http_client)
336+
337+
response = client.maps(
338+
"coffee shops",
339+
location={"latitude": 40.7455, "longitude": -74.0083, "zoom": 15},
340+
page=2,
341+
max_results=5,
342+
)
343+
344+
assert response == body
345+
assert str(seen[0].url) == "https://api.search1api.com/maps"
346+
assert json.loads(seen[0].content) == {
347+
"query": "coffee shops",
348+
"location": {"latitude": 40.7455, "longitude": -74.0083, "zoom": 15},
349+
"page": 2,
350+
"max_results": 5,
351+
}
352+
http_client.close()
353+
354+
355+
def test_async_maps():
356+
async def run():
357+
async def handler(request):
358+
assert json.loads(request.content) == {"query": "ramen", "country": "jp"}
359+
return json_response(
360+
200,
361+
{
362+
"searchParameters": {
363+
"query": "ramen",
364+
"country": "jp",
365+
"language": "en",
366+
"page": 1,
367+
"max_results": 20,
368+
},
369+
"results": [],
370+
},
371+
request,
372+
)
373+
374+
http_client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
375+
client = AsyncSearch1API("test-key", client=http_client)
376+
try:
377+
assert (await client.maps("ramen", country="jp"))["results"] == []
378+
finally:
379+
await http_client.aclose()
380+
381+
asyncio.run(run())
382+
383+
308384
def test_feedback_is_sent_once_without_retries():
309385
calls = []
310386

@@ -409,6 +485,7 @@ def test_sdk_covers_every_public_openapi_operation():
409485
"extract": "extract",
410486
"feedback": "feedback",
411487
"health": "health",
488+
"maps": "maps",
412489
"news": "news",
413490
"search": "search",
414491
"screenshot": "screenshot",

0 commit comments

Comments
 (0)