scrapemapsapi 0.1.0__py3-none-any.whl
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.
- scrapemapsapi/__init__.py +95 -0
- scrapemapsapi/_async_client.py +90 -0
- scrapemapsapi/_base.py +141 -0
- scrapemapsapi/_client.py +91 -0
- scrapemapsapi/errors.py +197 -0
- scrapemapsapi/models.py +489 -0
- scrapemapsapi/places.py +309 -0
- scrapemapsapi/py.typed +0 -0
- scrapemapsapi-0.1.0.dist-info/METADATA +209 -0
- scrapemapsapi-0.1.0.dist-info/RECORD +12 -0
- scrapemapsapi-0.1.0.dist-info/WHEEL +4 -0
- scrapemapsapi-0.1.0.dist-info/licenses/LICENSE +21 -0
scrapemapsapi/places.py
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"""The ``places`` resource: search, details, reviews, resolve, plus auto-paginating iterators."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING, Any, AsyncIterator, Iterator, Optional
|
|
6
|
+
|
|
7
|
+
from ._base import REVIEWS_MAX_LIMIT, SEARCH_MAX_LIMIT, page_limit, place_path
|
|
8
|
+
from .models import (
|
|
9
|
+
PlaceResponse,
|
|
10
|
+
PlaceSummary,
|
|
11
|
+
ResolveResponse,
|
|
12
|
+
Review,
|
|
13
|
+
ReviewSort,
|
|
14
|
+
ReviewsResponse,
|
|
15
|
+
SearchResponse,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from ._async_client import AsyncScrapeMapsAPI
|
|
20
|
+
from ._client import ScrapeMapsAPI
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _search_params(
|
|
24
|
+
q: str,
|
|
25
|
+
language: Optional[str],
|
|
26
|
+
region: Optional[str],
|
|
27
|
+
lat: Optional[float],
|
|
28
|
+
lng: Optional[float],
|
|
29
|
+
radius_km: Optional[float],
|
|
30
|
+
limit: Optional[int],
|
|
31
|
+
cursor: Optional[str],
|
|
32
|
+
) -> dict[str, Any]:
|
|
33
|
+
if (lat is None) != (lng is None):
|
|
34
|
+
raise ValueError("Provide both lat and lng, or neither.")
|
|
35
|
+
return {
|
|
36
|
+
"q": q,
|
|
37
|
+
"language": language,
|
|
38
|
+
"region": region,
|
|
39
|
+
"lat": lat,
|
|
40
|
+
"lng": lng,
|
|
41
|
+
"radius_km": radius_km,
|
|
42
|
+
"limit": limit,
|
|
43
|
+
"cursor": cursor,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _reviews_params(
|
|
48
|
+
sort: Optional[ReviewSort],
|
|
49
|
+
language: Optional[str],
|
|
50
|
+
original_language: Optional[str],
|
|
51
|
+
limit: Optional[int],
|
|
52
|
+
cursor: Optional[str],
|
|
53
|
+
) -> dict[str, Any]:
|
|
54
|
+
return {
|
|
55
|
+
"sort": sort,
|
|
56
|
+
"language": language,
|
|
57
|
+
"original_language": original_language,
|
|
58
|
+
"limit": limit,
|
|
59
|
+
"cursor": cursor,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _next(cursor: Optional[str], has_more: bool, previous: Optional[str]) -> Optional[str]:
|
|
64
|
+
"""Cursor of the next page, or None to stop (also guards against a repeated cursor)."""
|
|
65
|
+
if not has_more or not cursor or cursor == previous:
|
|
66
|
+
return None
|
|
67
|
+
return cursor
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Places:
|
|
71
|
+
"""Synchronous ``client.places``."""
|
|
72
|
+
|
|
73
|
+
def __init__(self, client: ScrapeMapsAPI) -> None:
|
|
74
|
+
self._client = client
|
|
75
|
+
|
|
76
|
+
def search(
|
|
77
|
+
self,
|
|
78
|
+
q: str,
|
|
79
|
+
*,
|
|
80
|
+
language: Optional[str] = None,
|
|
81
|
+
region: Optional[str] = None,
|
|
82
|
+
lat: Optional[float] = None,
|
|
83
|
+
lng: Optional[float] = None,
|
|
84
|
+
radius_km: Optional[float] = None,
|
|
85
|
+
limit: Optional[int] = None,
|
|
86
|
+
cursor: Optional[str] = None,
|
|
87
|
+
) -> SearchResponse:
|
|
88
|
+
"""Text search, optionally biased to an area (``lat``+``lng``, ``radius_km``).
|
|
89
|
+
|
|
90
|
+
``limit`` is 1-20 places per page (default 20). 1 credit per call.
|
|
91
|
+
Pass ``response.next_cursor`` as ``cursor`` for the next page, or use ``iter_search``.
|
|
92
|
+
"""
|
|
93
|
+
params = _search_params(q, language, region, lat, lng, radius_km, limit, cursor)
|
|
94
|
+
body, headers = self._client._get("/v1/places/search", params)
|
|
95
|
+
return SearchResponse.from_dict(body, headers)
|
|
96
|
+
|
|
97
|
+
def get(self, place: str, *, language: Optional[str] = None, region: Optional[str] = None) -> PlaceResponse:
|
|
98
|
+
"""Full details of a place. ``place`` is a place ID (ChIJ...), CID or feature ID (0x...:0x...).
|
|
99
|
+
1 credit."""
|
|
100
|
+
body, headers = self._client._get(place_path(place), {"language": language, "region": region})
|
|
101
|
+
return PlaceResponse.from_dict(body, headers)
|
|
102
|
+
|
|
103
|
+
def reviews(
|
|
104
|
+
self,
|
|
105
|
+
place: str,
|
|
106
|
+
*,
|
|
107
|
+
sort: Optional[ReviewSort] = None,
|
|
108
|
+
language: Optional[str] = None,
|
|
109
|
+
original_language: Optional[str] = None,
|
|
110
|
+
limit: Optional[int] = None,
|
|
111
|
+
cursor: Optional[str] = None,
|
|
112
|
+
) -> ReviewsResponse:
|
|
113
|
+
"""One page of reviews. ``sort``: relevant (default), newest, highest, lowest.
|
|
114
|
+
``language`` is also the translation target; ``original_language`` keeps only reviews
|
|
115
|
+
written in that language. ``limit`` 1-20 (default 20). 1 credit per call."""
|
|
116
|
+
params = _reviews_params(sort, language, original_language, limit, cursor)
|
|
117
|
+
body, headers = self._client._get(place_path(place, "/reviews"), params)
|
|
118
|
+
return ReviewsResponse.from_dict(body, headers)
|
|
119
|
+
|
|
120
|
+
def resolve(self, input: str) -> ResolveResponse:
|
|
121
|
+
"""Convert a place ID, CID, feature ID or Google Maps URL (short links too) into every
|
|
122
|
+
identifier. 1 credit."""
|
|
123
|
+
body, headers = self._client._get("/v1/places/resolve", {"input": input})
|
|
124
|
+
return ResolveResponse.from_dict(body, headers)
|
|
125
|
+
|
|
126
|
+
def iter_search(
|
|
127
|
+
self,
|
|
128
|
+
q: str,
|
|
129
|
+
*,
|
|
130
|
+
language: Optional[str] = None,
|
|
131
|
+
region: Optional[str] = None,
|
|
132
|
+
lat: Optional[float] = None,
|
|
133
|
+
lng: Optional[float] = None,
|
|
134
|
+
radius_km: Optional[float] = None,
|
|
135
|
+
page_size: Optional[int] = None,
|
|
136
|
+
max_items: Optional[int] = None,
|
|
137
|
+
) -> Iterator[PlaceSummary]:
|
|
138
|
+
"""Yield every place of a search, following ``next_cursor`` until the end or ``max_items``."""
|
|
139
|
+
seen = 0
|
|
140
|
+
cursor: Optional[str] = None
|
|
141
|
+
while max_items is None or seen < max_items:
|
|
142
|
+
limit = page_limit(page_size, max_items, seen, SEARCH_MAX_LIMIT)
|
|
143
|
+
page = self.search(
|
|
144
|
+
q,
|
|
145
|
+
language=language,
|
|
146
|
+
region=region,
|
|
147
|
+
lat=lat,
|
|
148
|
+
lng=lng,
|
|
149
|
+
radius_km=radius_km,
|
|
150
|
+
limit=limit,
|
|
151
|
+
cursor=cursor,
|
|
152
|
+
)
|
|
153
|
+
for place in page.data:
|
|
154
|
+
yield place
|
|
155
|
+
seen += 1
|
|
156
|
+
if max_items is not None and seen >= max_items:
|
|
157
|
+
return
|
|
158
|
+
cursor = _next(page.next_cursor, page.has_more and bool(page.data), cursor)
|
|
159
|
+
if cursor is None:
|
|
160
|
+
return
|
|
161
|
+
|
|
162
|
+
def iter_reviews(
|
|
163
|
+
self,
|
|
164
|
+
place: str,
|
|
165
|
+
*,
|
|
166
|
+
sort: Optional[ReviewSort] = None,
|
|
167
|
+
language: Optional[str] = None,
|
|
168
|
+
original_language: Optional[str] = None,
|
|
169
|
+
page_size: Optional[int] = None,
|
|
170
|
+
max_items: Optional[int] = None,
|
|
171
|
+
) -> Iterator[Review]:
|
|
172
|
+
"""Yield every review of a place, following ``next_cursor`` until the end or ``max_items``."""
|
|
173
|
+
seen = 0
|
|
174
|
+
cursor: Optional[str] = None
|
|
175
|
+
while max_items is None or seen < max_items:
|
|
176
|
+
limit = page_limit(page_size, max_items, seen, REVIEWS_MAX_LIMIT)
|
|
177
|
+
page = self.reviews(
|
|
178
|
+
place,
|
|
179
|
+
sort=sort,
|
|
180
|
+
language=language,
|
|
181
|
+
original_language=original_language,
|
|
182
|
+
limit=limit,
|
|
183
|
+
cursor=cursor,
|
|
184
|
+
)
|
|
185
|
+
for review in page.data:
|
|
186
|
+
yield review
|
|
187
|
+
seen += 1
|
|
188
|
+
if max_items is not None and seen >= max_items:
|
|
189
|
+
return
|
|
190
|
+
cursor = _next(page.next_cursor, page.has_more and bool(page.data), cursor)
|
|
191
|
+
if cursor is None:
|
|
192
|
+
return
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class AsyncPlaces:
|
|
196
|
+
"""Asynchronous ``client.places``. Same methods as :class:`Places`, awaitable."""
|
|
197
|
+
|
|
198
|
+
def __init__(self, client: AsyncScrapeMapsAPI) -> None:
|
|
199
|
+
self._client = client
|
|
200
|
+
|
|
201
|
+
async def search(
|
|
202
|
+
self,
|
|
203
|
+
q: str,
|
|
204
|
+
*,
|
|
205
|
+
language: Optional[str] = None,
|
|
206
|
+
region: Optional[str] = None,
|
|
207
|
+
lat: Optional[float] = None,
|
|
208
|
+
lng: Optional[float] = None,
|
|
209
|
+
radius_km: Optional[float] = None,
|
|
210
|
+
limit: Optional[int] = None,
|
|
211
|
+
cursor: Optional[str] = None,
|
|
212
|
+
) -> SearchResponse:
|
|
213
|
+
"""See :meth:`Places.search`."""
|
|
214
|
+
params = _search_params(q, language, region, lat, lng, radius_km, limit, cursor)
|
|
215
|
+
body, headers = await self._client._get("/v1/places/search", params)
|
|
216
|
+
return SearchResponse.from_dict(body, headers)
|
|
217
|
+
|
|
218
|
+
async def get(self, place: str, *, language: Optional[str] = None, region: Optional[str] = None) -> PlaceResponse:
|
|
219
|
+
"""See :meth:`Places.get`."""
|
|
220
|
+
body, headers = await self._client._get(place_path(place), {"language": language, "region": region})
|
|
221
|
+
return PlaceResponse.from_dict(body, headers)
|
|
222
|
+
|
|
223
|
+
async def reviews(
|
|
224
|
+
self,
|
|
225
|
+
place: str,
|
|
226
|
+
*,
|
|
227
|
+
sort: Optional[ReviewSort] = None,
|
|
228
|
+
language: Optional[str] = None,
|
|
229
|
+
original_language: Optional[str] = None,
|
|
230
|
+
limit: Optional[int] = None,
|
|
231
|
+
cursor: Optional[str] = None,
|
|
232
|
+
) -> ReviewsResponse:
|
|
233
|
+
"""See :meth:`Places.reviews`."""
|
|
234
|
+
params = _reviews_params(sort, language, original_language, limit, cursor)
|
|
235
|
+
body, headers = await self._client._get(place_path(place, "/reviews"), params)
|
|
236
|
+
return ReviewsResponse.from_dict(body, headers)
|
|
237
|
+
|
|
238
|
+
async def resolve(self, input: str) -> ResolveResponse:
|
|
239
|
+
"""See :meth:`Places.resolve`."""
|
|
240
|
+
body, headers = await self._client._get("/v1/places/resolve", {"input": input})
|
|
241
|
+
return ResolveResponse.from_dict(body, headers)
|
|
242
|
+
|
|
243
|
+
async def iter_search(
|
|
244
|
+
self,
|
|
245
|
+
q: str,
|
|
246
|
+
*,
|
|
247
|
+
language: Optional[str] = None,
|
|
248
|
+
region: Optional[str] = None,
|
|
249
|
+
lat: Optional[float] = None,
|
|
250
|
+
lng: Optional[float] = None,
|
|
251
|
+
radius_km: Optional[float] = None,
|
|
252
|
+
page_size: Optional[int] = None,
|
|
253
|
+
max_items: Optional[int] = None,
|
|
254
|
+
) -> AsyncIterator[PlaceSummary]:
|
|
255
|
+
"""See :meth:`Places.iter_search`. Use with ``async for``."""
|
|
256
|
+
seen = 0
|
|
257
|
+
cursor: Optional[str] = None
|
|
258
|
+
while max_items is None or seen < max_items:
|
|
259
|
+
limit = page_limit(page_size, max_items, seen, SEARCH_MAX_LIMIT)
|
|
260
|
+
page = await self.search(
|
|
261
|
+
q,
|
|
262
|
+
language=language,
|
|
263
|
+
region=region,
|
|
264
|
+
lat=lat,
|
|
265
|
+
lng=lng,
|
|
266
|
+
radius_km=radius_km,
|
|
267
|
+
limit=limit,
|
|
268
|
+
cursor=cursor,
|
|
269
|
+
)
|
|
270
|
+
for place in page.data:
|
|
271
|
+
yield place
|
|
272
|
+
seen += 1
|
|
273
|
+
if max_items is not None and seen >= max_items:
|
|
274
|
+
return
|
|
275
|
+
cursor = _next(page.next_cursor, page.has_more and bool(page.data), cursor)
|
|
276
|
+
if cursor is None:
|
|
277
|
+
return
|
|
278
|
+
|
|
279
|
+
async def iter_reviews(
|
|
280
|
+
self,
|
|
281
|
+
place: str,
|
|
282
|
+
*,
|
|
283
|
+
sort: Optional[ReviewSort] = None,
|
|
284
|
+
language: Optional[str] = None,
|
|
285
|
+
original_language: Optional[str] = None,
|
|
286
|
+
page_size: Optional[int] = None,
|
|
287
|
+
max_items: Optional[int] = None,
|
|
288
|
+
) -> AsyncIterator[Review]:
|
|
289
|
+
"""See :meth:`Places.iter_reviews`. Use with ``async for``."""
|
|
290
|
+
seen = 0
|
|
291
|
+
cursor: Optional[str] = None
|
|
292
|
+
while max_items is None or seen < max_items:
|
|
293
|
+
limit = page_limit(page_size, max_items, seen, REVIEWS_MAX_LIMIT)
|
|
294
|
+
page = await self.reviews(
|
|
295
|
+
place,
|
|
296
|
+
sort=sort,
|
|
297
|
+
language=language,
|
|
298
|
+
original_language=original_language,
|
|
299
|
+
limit=limit,
|
|
300
|
+
cursor=cursor,
|
|
301
|
+
)
|
|
302
|
+
for review in page.data:
|
|
303
|
+
yield review
|
|
304
|
+
seen += 1
|
|
305
|
+
if max_items is not None and seen >= max_items:
|
|
306
|
+
return
|
|
307
|
+
cursor = _next(page.next_cursor, page.has_more and bool(page.data), cursor)
|
|
308
|
+
if cursor is None:
|
|
309
|
+
return
|
scrapemapsapi/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: scrapemapsapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the ScrapeMapsAPI API: Google Maps places, details and reviews
|
|
5
|
+
Project-URL: Homepage, https://scrapemapsapi.com
|
|
6
|
+
Project-URL: Repository, https://github.com/scrapemapsapi/python-sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/scrapemapsapi/python-sdk/issues
|
|
8
|
+
Project-URL: Documentation, https://scrapemapsapi.com/docs
|
|
9
|
+
Author: ScrapeMapsAPI
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,google-maps,local-business,maps,places,reviews,sdk
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: httpx>=0.27.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.6.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# ScrapeMapsAPI Python SDK
|
|
32
|
+
|
|
33
|
+
Official Python SDK for the [ScrapeMapsAPI](https://scrapemapsapi.com) API: search Google Maps places, get full place details and page through **all** the reviews of a place.
|
|
34
|
+
|
|
35
|
+
- Sync (`ScrapeMapsAPI`) and async (`AsyncScrapeMapsAPI`) clients
|
|
36
|
+
- Typed models (dataclasses) that match the API's JSON field by field
|
|
37
|
+
- Auto-paginating iterators: `iter_search` and `iter_reviews`
|
|
38
|
+
- Typed exceptions per error code, automatic retries on 429/502/503
|
|
39
|
+
- Credits used/remaining on every result
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install scrapemapsapi
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Python 3.9+. The only dependency is `httpx`.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from scrapemapsapi import ScrapeMapsAPI
|
|
53
|
+
|
|
54
|
+
client = ScrapeMapsAPI(api_key="your_api_key") # or set SCRAPEMAPSAPI_API_KEY
|
|
55
|
+
|
|
56
|
+
# Search
|
|
57
|
+
page = client.places.search("pizzeria in Naples", language="it", region="it", limit=5)
|
|
58
|
+
for place in page.data:
|
|
59
|
+
print(place.name, place.rating, place.review_count, place.address.formatted)
|
|
60
|
+
|
|
61
|
+
# Details (1 credit)
|
|
62
|
+
place = client.places.get(page.data[0].ref).data
|
|
63
|
+
print(place.phone_international, place.website, place.timezone)
|
|
64
|
+
if place.opening_hours:
|
|
65
|
+
for day in place.opening_hours.weekly:
|
|
66
|
+
print(day.day, "closed" if day.closed else day.text)
|
|
67
|
+
|
|
68
|
+
# One page of reviews
|
|
69
|
+
reviews = client.places.reviews(place.ref, sort="newest", limit=20)
|
|
70
|
+
for review in reviews.data:
|
|
71
|
+
print(review.rating, review.published_at, review.translated_text or review.text)
|
|
72
|
+
|
|
73
|
+
print("credits used:", reviews.credits_used, "remaining:", reviews.credits_remaining)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`place` can be a place ID (`ChIJ...`), a CID (`10281119596374313554`) or a feature ID (`0x...:0x...`). `PlaceSummary.ref` gives the best one for a result (`id`, else `ids.cid`).
|
|
77
|
+
|
|
78
|
+
## Auto-pagination
|
|
79
|
+
|
|
80
|
+
The iterators follow `next_cursor` for you and stop at the end or at `max_items`. They request only what is still needed, so `max_items` also caps what you pay.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# Every review written in Italian, newest first, translated to English
|
|
84
|
+
for review in client.places.iter_reviews(place_id, sort="newest", original_language="it", language="en"):
|
|
85
|
+
print(review.rating, review.text)
|
|
86
|
+
|
|
87
|
+
# At most 50 places for a query in an area
|
|
88
|
+
for place in client.places.iter_search("coffee", lat=45.4642, lng=9.19, radius_km=2, max_items=50):
|
|
89
|
+
print(place.name)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Optional `page_size` sets the page size (search 1–20, reviews 1–20). Every page is one call (1 credit), so keep the default full page.
|
|
93
|
+
|
|
94
|
+
Manual paging is available too:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
page = client.places.reviews(place_id, limit=20)
|
|
98
|
+
while page.has_more:
|
|
99
|
+
page = client.places.reviews(place_id, limit=20, cursor=page.next_cursor)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Resolve identifiers and Google Maps URLs
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
ids = client.places.resolve("https://maps.app.goo.gl/xxxx").data
|
|
106
|
+
print(ids.place_id, ids.cid, ids.feature_id, ids.google_maps_url)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
1 credit per call.
|
|
110
|
+
|
|
111
|
+
## Async
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import asyncio
|
|
115
|
+
from scrapemapsapi import AsyncScrapeMapsAPI
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def main():
|
|
119
|
+
async with AsyncScrapeMapsAPI() as client:
|
|
120
|
+
page = await client.places.search("ramen in Tokyo", language="ja", region="jp")
|
|
121
|
+
async for review in client.places.iter_reviews(page.data[0].ref, max_items=200):
|
|
122
|
+
print(review.rating, review.text)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
asyncio.run(main())
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Configuration
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
client = ScrapeMapsAPI(
|
|
132
|
+
api_key="...", # default: SCRAPEMAPSAPI_API_KEY
|
|
133
|
+
base_url="http://localhost:8000", # default: SCRAPEMAPSAPI_BASE_URL or https://api.scrapemapsapi.com
|
|
134
|
+
timeout=60.0, # seconds per request
|
|
135
|
+
max_retries=2, # retries on 429/502/503 and connection errors; 0 disables
|
|
136
|
+
retry_backoff=0.5, # base of the exponential backoff (with jitter)
|
|
137
|
+
max_retry_wait=30.0, # never sleep longer than this; a longer Retry-After raises
|
|
138
|
+
http_client=None, # your own httpx.Client (proxies, custom transports)
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Retries honour the `Retry-After` header. A `429 insufficient_credits_retry_later` (key in a no-credit cooldown) is never retried: top up instead.
|
|
143
|
+
|
|
144
|
+
## Credits
|
|
145
|
+
|
|
146
|
+
Every result exposes the billing headers:
|
|
147
|
+
|
|
148
|
+
| Attribute | Source |
|
|
149
|
+
|---|---|
|
|
150
|
+
| `result.credits_used` | `X-Credits-Used` (falls back to `meta.credits_used`) |
|
|
151
|
+
| `result.credits_remaining` | `X-Credits-Remaining` |
|
|
152
|
+
| `result.info.cache` | `X-Cache` (`HIT` / `MISS`) |
|
|
153
|
+
| `client.credits_remaining` | from the last successful call (handy with iterators) |
|
|
154
|
+
|
|
155
|
+
Costs: every successful call is 1 credit, whatever it returns (a page of up to 20 places or 20 reviews, one place, one conversion); the next page is a new call. Errors are free.
|
|
156
|
+
|
|
157
|
+
## Errors
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from scrapemapsapi import (
|
|
161
|
+
ScrapeMapsAPIError,
|
|
162
|
+
NotFoundError,
|
|
163
|
+
InsufficientCreditsError,
|
|
164
|
+
RateLimitError,
|
|
165
|
+
InvalidRequestError,
|
|
166
|
+
AuthenticationError,
|
|
167
|
+
UpstreamError,
|
|
168
|
+
ServiceUnavailableError,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
try:
|
|
172
|
+
client.places.get("ChIJ...")
|
|
173
|
+
except NotFoundError:
|
|
174
|
+
...
|
|
175
|
+
except RateLimitError as e:
|
|
176
|
+
print("retry in", e.retry_after, "s")
|
|
177
|
+
except ScrapeMapsAPIError as e:
|
|
178
|
+
print(e.status_code, e.code, e.message)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
| Exception | HTTP | Codes |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `InvalidRequestError` | 400, 422 | `invalid_place_id`, `invalid_cursor`, `invalid_location`, `validation_error` |
|
|
184
|
+
| `AuthenticationError` | 401 | `missing_api_key`, `invalid_api_key` (also raised when no key is configured) |
|
|
185
|
+
| `InsufficientCreditsError` | 402 | `insufficient_credits` (`.available`, `.required`) |
|
|
186
|
+
| `NotFoundError` (alias `PlaceNotFoundError`) | 404 | `place_not_found` |
|
|
187
|
+
| `RateLimitError` | 429 | `rate_limit_exceeded`, or no code on a plain-text 429 from the edge proxy (`.retry_after`) |
|
|
188
|
+
| `CreditsCooldownError` (both `RateLimitError` and `InsufficientCreditsError`) | 429 | `insufficient_credits_retry_later` |
|
|
189
|
+
| `UpstreamError` | 502 | `upstream_error`, `proxy_error` (short link could not be followed) |
|
|
190
|
+
| `ServiceUnavailableError` (subclass of `UpstreamError`) | 503 | `upstream_unavailable` |
|
|
191
|
+
| `InternalServerError` | 500, other 5xx | `internal_server_error` |
|
|
192
|
+
| `APIConnectionError` / `APITimeoutError` | none | network failure / timeout |
|
|
193
|
+
|
|
194
|
+
All inherit from `ScrapeMapsAPIError`.
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
uv venv && uv pip install -e ".[dev]"
|
|
200
|
+
.venv/bin/pytest
|
|
201
|
+
.venv/bin/ruff check .
|
|
202
|
+
|
|
203
|
+
# Against a real server (spends a few credits; skipped when the key is unset)
|
|
204
|
+
SCRAPEMAPSAPI_API_KEY=... SCRAPEMAPSAPI_BASE_URL=http://localhost:8000 .venv/bin/python examples/live_check.py
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
scrapemapsapi/__init__.py,sha256=cxZbeTHPVRWi3JwH-NSTc6M6DaD-0mUkNZCUjpwclwE,1891
|
|
2
|
+
scrapemapsapi/_async_client.py,sha256=r85W9J366lHNVkQBts3hmcDctzbxxi7Zd15smpxSF9U,3380
|
|
3
|
+
scrapemapsapi/_base.py,sha256=cMAcdPmvL6pyo_C4sugMCSGeQT4K-dZexdt1UGP8LoM,5343
|
|
4
|
+
scrapemapsapi/_client.py,sha256=u0r8zfBflAxrFUF78-1R-QmljCxHs9azmBdPG0fmEws,3291
|
|
5
|
+
scrapemapsapi/errors.py,sha256=bkszQQ97A_q1Brayf6dGouBgEOAaLcddCjg234KLzTw,6586
|
|
6
|
+
scrapemapsapi/models.py,sha256=9d1E7qKkYmgovT7hzfXYCQQ6uzODaz3Tnf0s3dNLrgs,14843
|
|
7
|
+
scrapemapsapi/places.py,sha256=CqRpgIboaVKaF06SCds7xYs2D8neeHLoowXVd7W06r0,11021
|
|
8
|
+
scrapemapsapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
scrapemapsapi-0.1.0.dist-info/METADATA,sha256=Kq23PEQiFQMc--E8GsNE8nSsLR06CJZ8IeEjG1WG4y0,7573
|
|
10
|
+
scrapemapsapi-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
11
|
+
scrapemapsapi-0.1.0.dist-info/licenses/LICENSE,sha256=1dsbsVLHmXs6w1JpPokMVYINQM44XsRS5V0lhJqYCd0,1070
|
|
12
|
+
scrapemapsapi-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ScrapeMapsAPI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|