scrapemapsapi 0.1.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.
- scrapemapsapi-0.1.0/.gitignore +33 -0
- scrapemapsapi-0.1.0/LICENSE +21 -0
- scrapemapsapi-0.1.0/PKG-INFO +209 -0
- scrapemapsapi-0.1.0/README.md +179 -0
- scrapemapsapi-0.1.0/examples/live_check.py +66 -0
- scrapemapsapi-0.1.0/pyproject.toml +57 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/__init__.py +95 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/_async_client.py +90 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/_base.py +141 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/_client.py +91 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/errors.py +197 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/models.py +489 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/places.py +309 -0
- scrapemapsapi-0.1.0/src/scrapemapsapi/py.typed +0 -0
- scrapemapsapi-0.1.0/tests/conftest.py +158 -0
- scrapemapsapi-0.1.0/tests/test_async_client.py +86 -0
- scrapemapsapi-0.1.0/tests/test_client.py +242 -0
- scrapemapsapi-0.1.0/tests/test_errors.py +210 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Virtual environment
|
|
2
|
+
.venv/
|
|
3
|
+
venv/
|
|
4
|
+
env/
|
|
5
|
+
|
|
6
|
+
# Environment variables (contains API key)
|
|
7
|
+
.env
|
|
8
|
+
|
|
9
|
+
# Python cache
|
|
10
|
+
__pycache__/
|
|
11
|
+
*.py[cod]
|
|
12
|
+
*$py.class
|
|
13
|
+
*.so
|
|
14
|
+
|
|
15
|
+
# Distribution
|
|
16
|
+
dist/
|
|
17
|
+
build/
|
|
18
|
+
*.egg-info/
|
|
19
|
+
|
|
20
|
+
# IDE
|
|
21
|
+
.idea/
|
|
22
|
+
.vscode/
|
|
23
|
+
*.swp
|
|
24
|
+
*.swo
|
|
25
|
+
|
|
26
|
+
# Test artifacts
|
|
27
|
+
.pytest_cache/
|
|
28
|
+
.coverage
|
|
29
|
+
htmlcov/
|
|
30
|
+
|
|
31
|
+
# Output directory (test results)
|
|
32
|
+
output/
|
|
33
|
+
.ruff_cache/
|
|
@@ -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.
|
|
@@ -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,179 @@
|
|
|
1
|
+
# ScrapeMapsAPI Python SDK
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
- Sync (`ScrapeMapsAPI`) and async (`AsyncScrapeMapsAPI`) clients
|
|
6
|
+
- Typed models (dataclasses) that match the API's JSON field by field
|
|
7
|
+
- Auto-paginating iterators: `iter_search` and `iter_reviews`
|
|
8
|
+
- Typed exceptions per error code, automatic retries on 429/502/503
|
|
9
|
+
- Credits used/remaining on every result
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install scrapemapsapi
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Python 3.9+. The only dependency is `httpx`.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from scrapemapsapi import ScrapeMapsAPI
|
|
23
|
+
|
|
24
|
+
client = ScrapeMapsAPI(api_key="your_api_key") # or set SCRAPEMAPSAPI_API_KEY
|
|
25
|
+
|
|
26
|
+
# Search
|
|
27
|
+
page = client.places.search("pizzeria in Naples", language="it", region="it", limit=5)
|
|
28
|
+
for place in page.data:
|
|
29
|
+
print(place.name, place.rating, place.review_count, place.address.formatted)
|
|
30
|
+
|
|
31
|
+
# Details (1 credit)
|
|
32
|
+
place = client.places.get(page.data[0].ref).data
|
|
33
|
+
print(place.phone_international, place.website, place.timezone)
|
|
34
|
+
if place.opening_hours:
|
|
35
|
+
for day in place.opening_hours.weekly:
|
|
36
|
+
print(day.day, "closed" if day.closed else day.text)
|
|
37
|
+
|
|
38
|
+
# One page of reviews
|
|
39
|
+
reviews = client.places.reviews(place.ref, sort="newest", limit=20)
|
|
40
|
+
for review in reviews.data:
|
|
41
|
+
print(review.rating, review.published_at, review.translated_text or review.text)
|
|
42
|
+
|
|
43
|
+
print("credits used:", reviews.credits_used, "remaining:", reviews.credits_remaining)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`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`).
|
|
47
|
+
|
|
48
|
+
## Auto-pagination
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# Every review written in Italian, newest first, translated to English
|
|
54
|
+
for review in client.places.iter_reviews(place_id, sort="newest", original_language="it", language="en"):
|
|
55
|
+
print(review.rating, review.text)
|
|
56
|
+
|
|
57
|
+
# At most 50 places for a query in an area
|
|
58
|
+
for place in client.places.iter_search("coffee", lat=45.4642, lng=9.19, radius_km=2, max_items=50):
|
|
59
|
+
print(place.name)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
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.
|
|
63
|
+
|
|
64
|
+
Manual paging is available too:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
page = client.places.reviews(place_id, limit=20)
|
|
68
|
+
while page.has_more:
|
|
69
|
+
page = client.places.reviews(place_id, limit=20, cursor=page.next_cursor)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Resolve identifiers and Google Maps URLs
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
ids = client.places.resolve("https://maps.app.goo.gl/xxxx").data
|
|
76
|
+
print(ids.place_id, ids.cid, ids.feature_id, ids.google_maps_url)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
1 credit per call.
|
|
80
|
+
|
|
81
|
+
## Async
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import asyncio
|
|
85
|
+
from scrapemapsapi import AsyncScrapeMapsAPI
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def main():
|
|
89
|
+
async with AsyncScrapeMapsAPI() as client:
|
|
90
|
+
page = await client.places.search("ramen in Tokyo", language="ja", region="jp")
|
|
91
|
+
async for review in client.places.iter_reviews(page.data[0].ref, max_items=200):
|
|
92
|
+
print(review.rating, review.text)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
asyncio.run(main())
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
client = ScrapeMapsAPI(
|
|
102
|
+
api_key="...", # default: SCRAPEMAPSAPI_API_KEY
|
|
103
|
+
base_url="http://localhost:8000", # default: SCRAPEMAPSAPI_BASE_URL or https://api.scrapemapsapi.com
|
|
104
|
+
timeout=60.0, # seconds per request
|
|
105
|
+
max_retries=2, # retries on 429/502/503 and connection errors; 0 disables
|
|
106
|
+
retry_backoff=0.5, # base of the exponential backoff (with jitter)
|
|
107
|
+
max_retry_wait=30.0, # never sleep longer than this; a longer Retry-After raises
|
|
108
|
+
http_client=None, # your own httpx.Client (proxies, custom transports)
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Retries honour the `Retry-After` header. A `429 insufficient_credits_retry_later` (key in a no-credit cooldown) is never retried: top up instead.
|
|
113
|
+
|
|
114
|
+
## Credits
|
|
115
|
+
|
|
116
|
+
Every result exposes the billing headers:
|
|
117
|
+
|
|
118
|
+
| Attribute | Source |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `result.credits_used` | `X-Credits-Used` (falls back to `meta.credits_used`) |
|
|
121
|
+
| `result.credits_remaining` | `X-Credits-Remaining` |
|
|
122
|
+
| `result.info.cache` | `X-Cache` (`HIT` / `MISS`) |
|
|
123
|
+
| `client.credits_remaining` | from the last successful call (handy with iterators) |
|
|
124
|
+
|
|
125
|
+
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.
|
|
126
|
+
|
|
127
|
+
## Errors
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from scrapemapsapi import (
|
|
131
|
+
ScrapeMapsAPIError,
|
|
132
|
+
NotFoundError,
|
|
133
|
+
InsufficientCreditsError,
|
|
134
|
+
RateLimitError,
|
|
135
|
+
InvalidRequestError,
|
|
136
|
+
AuthenticationError,
|
|
137
|
+
UpstreamError,
|
|
138
|
+
ServiceUnavailableError,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
client.places.get("ChIJ...")
|
|
143
|
+
except NotFoundError:
|
|
144
|
+
...
|
|
145
|
+
except RateLimitError as e:
|
|
146
|
+
print("retry in", e.retry_after, "s")
|
|
147
|
+
except ScrapeMapsAPIError as e:
|
|
148
|
+
print(e.status_code, e.code, e.message)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
| Exception | HTTP | Codes |
|
|
152
|
+
|---|---|---|
|
|
153
|
+
| `InvalidRequestError` | 400, 422 | `invalid_place_id`, `invalid_cursor`, `invalid_location`, `validation_error` |
|
|
154
|
+
| `AuthenticationError` | 401 | `missing_api_key`, `invalid_api_key` (also raised when no key is configured) |
|
|
155
|
+
| `InsufficientCreditsError` | 402 | `insufficient_credits` (`.available`, `.required`) |
|
|
156
|
+
| `NotFoundError` (alias `PlaceNotFoundError`) | 404 | `place_not_found` |
|
|
157
|
+
| `RateLimitError` | 429 | `rate_limit_exceeded`, or no code on a plain-text 429 from the edge proxy (`.retry_after`) |
|
|
158
|
+
| `CreditsCooldownError` (both `RateLimitError` and `InsufficientCreditsError`) | 429 | `insufficient_credits_retry_later` |
|
|
159
|
+
| `UpstreamError` | 502 | `upstream_error`, `proxy_error` (short link could not be followed) |
|
|
160
|
+
| `ServiceUnavailableError` (subclass of `UpstreamError`) | 503 | `upstream_unavailable` |
|
|
161
|
+
| `InternalServerError` | 500, other 5xx | `internal_server_error` |
|
|
162
|
+
| `APIConnectionError` / `APITimeoutError` | none | network failure / timeout |
|
|
163
|
+
|
|
164
|
+
All inherit from `ScrapeMapsAPIError`.
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
uv venv && uv pip install -e ".[dev]"
|
|
170
|
+
.venv/bin/pytest
|
|
171
|
+
.venv/bin/ruff check .
|
|
172
|
+
|
|
173
|
+
# Against a real server (spends a few credits; skipped when the key is unset)
|
|
174
|
+
SCRAPEMAPSAPI_API_KEY=... SCRAPEMAPSAPI_BASE_URL=http://localhost:8000 .venv/bin/python examples/live_check.py
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Smoke test against a real ScrapeMapsAPI server. Spends a few credits.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
SCRAPEMAPSAPI_API_KEY=... [SCRAPEMAPSAPI_BASE_URL=http://localhost:8000] python examples/live_check.py
|
|
5
|
+
|
|
6
|
+
Does nothing (exit 0) when SCRAPEMAPSAPI_API_KEY is not set.
|
|
7
|
+
Cost: ~1 search credit + 2 (details) + ~3 (6 reviews) + 0-1 (resolve).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
from scrapemapsapi import NotFoundError, ScrapeMapsAPI, ScrapeMapsAPIError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> int:
|
|
19
|
+
if not os.environ.get("SCRAPEMAPSAPI_API_KEY"):
|
|
20
|
+
print("SCRAPEMAPSAPI_API_KEY not set: skipping live check.")
|
|
21
|
+
return 0
|
|
22
|
+
|
|
23
|
+
query = sys.argv[1] if len(sys.argv) > 1 else "pizzeria in Naples"
|
|
24
|
+
with ScrapeMapsAPI(max_retries=1) as client:
|
|
25
|
+
print(f"Server: {client.base_url}")
|
|
26
|
+
try:
|
|
27
|
+
search = client.places.search(query, limit=1)
|
|
28
|
+
print(
|
|
29
|
+
f"search: {len(search.data)} place(s), credits used {search.credits_used}, "
|
|
30
|
+
f"remaining {search.credits_remaining}"
|
|
31
|
+
)
|
|
32
|
+
if not search.data:
|
|
33
|
+
print("No places found; stopping.")
|
|
34
|
+
return 1
|
|
35
|
+
first = search.data[0]
|
|
36
|
+
print(f" -> {first.name} | {first.address.formatted} | rating {first.rating}")
|
|
37
|
+
|
|
38
|
+
place = client.places.get(first.ref).data
|
|
39
|
+
print(f"get: {place.name}, timezone {place.timezone}, {len(place.photos)} photo(s)")
|
|
40
|
+
if place.opening_hours:
|
|
41
|
+
print(f" hours: {place.opening_hours.status_text}")
|
|
42
|
+
|
|
43
|
+
reviews = list(client.places.iter_reviews(first.ref, sort="newest", page_size=3, max_items=6))
|
|
44
|
+
print(f"iter_reviews: {len(reviews)} review(s)")
|
|
45
|
+
for r in reviews[:3]:
|
|
46
|
+
text = (r.translated_text or r.text or "").replace("\n", " ")[:80]
|
|
47
|
+
print(f" {r.rating}* {r.relative_date}: {text}")
|
|
48
|
+
|
|
49
|
+
resolved = client.places.resolve(first.ids.cid).data
|
|
50
|
+
print(f"resolve: cid {resolved.cid} -> place_id {resolved.place_id}")
|
|
51
|
+
|
|
52
|
+
try:
|
|
53
|
+
client.places.get("0x0:0x1")
|
|
54
|
+
except NotFoundError as e:
|
|
55
|
+
print(f"expected not found: {e}")
|
|
56
|
+
except ScrapeMapsAPIError as e:
|
|
57
|
+
print(f"(unknown place raised {type(e).__name__}: {e})")
|
|
58
|
+
except ScrapeMapsAPIError as e:
|
|
59
|
+
print(f"FAILED: {type(e).__name__}: {e}", file=sys.stderr)
|
|
60
|
+
return 1
|
|
61
|
+
print(f"OK. Credits remaining: {client.credits_remaining}")
|
|
62
|
+
return 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
sys.exit(main())
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scrapemapsapi"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for the ScrapeMapsAPI API: Google Maps places, details and reviews"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "ScrapeMapsAPI" }]
|
|
13
|
+
keywords = ["google-maps", "places", "reviews", "local-business", "maps", "api", "sdk"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"httpx>=0.27.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=8.0.0",
|
|
33
|
+
"pytest-asyncio>=0.23.0",
|
|
34
|
+
"ruff>=0.6.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://scrapemapsapi.com"
|
|
39
|
+
Repository = "https://github.com/scrapemapsapi/python-sdk"
|
|
40
|
+
Issues = "https://github.com/scrapemapsapi/python-sdk/issues"
|
|
41
|
+
Documentation = "https://scrapemapsapi.com/docs"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel]
|
|
44
|
+
packages = ["src/scrapemapsapi"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
asyncio_mode = "auto"
|
|
48
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
49
|
+
testpaths = ["tests"]
|
|
50
|
+
|
|
51
|
+
[tool.ruff]
|
|
52
|
+
line-length = 120
|
|
53
|
+
target-version = "py39"
|
|
54
|
+
|
|
55
|
+
[tool.ruff.lint]
|
|
56
|
+
select = ["E", "F", "I", "B", "UP"]
|
|
57
|
+
ignore = ["UP006", "UP007", "UP035", "UP045", "B008"]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""ScrapeMapsAPI: official Python SDK for the ScrapeMapsAPI API (Google Maps places and reviews)."""
|
|
2
|
+
|
|
3
|
+
from ._async_client import AsyncScrapeMapsAPI
|
|
4
|
+
from ._base import __version__
|
|
5
|
+
from ._client import ScrapeMapsAPI
|
|
6
|
+
from .errors import (
|
|
7
|
+
APIConnectionError,
|
|
8
|
+
APITimeoutError,
|
|
9
|
+
AuthenticationError,
|
|
10
|
+
CreditsCooldownError,
|
|
11
|
+
InsufficientCreditsError,
|
|
12
|
+
InternalServerError,
|
|
13
|
+
InvalidRequestError,
|
|
14
|
+
NotFoundError,
|
|
15
|
+
PlaceNotFoundError,
|
|
16
|
+
RateLimitError,
|
|
17
|
+
ScrapeMapsAPIError,
|
|
18
|
+
ServiceUnavailableError,
|
|
19
|
+
UpstreamError,
|
|
20
|
+
)
|
|
21
|
+
from .models import (
|
|
22
|
+
Address,
|
|
23
|
+
DayHours,
|
|
24
|
+
Link,
|
|
25
|
+
Location,
|
|
26
|
+
Meta,
|
|
27
|
+
OpeningHours,
|
|
28
|
+
OwnerResponse,
|
|
29
|
+
Pagination,
|
|
30
|
+
Photo,
|
|
31
|
+
Place,
|
|
32
|
+
PlaceIds,
|
|
33
|
+
PlaceMeta,
|
|
34
|
+
PlaceResponse,
|
|
35
|
+
PlaceStatus,
|
|
36
|
+
PlaceSummary,
|
|
37
|
+
ResolvedIds,
|
|
38
|
+
ResolveResponse,
|
|
39
|
+
ResponseInfo,
|
|
40
|
+
Review,
|
|
41
|
+
ReviewAuthor,
|
|
42
|
+
ReviewsMeta,
|
|
43
|
+
ReviewSort,
|
|
44
|
+
ReviewsResponse,
|
|
45
|
+
SearchMeta,
|
|
46
|
+
SearchResponse,
|
|
47
|
+
TimePeriod,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
__all__ = [
|
|
51
|
+
"__version__",
|
|
52
|
+
"ScrapeMapsAPI",
|
|
53
|
+
"AsyncScrapeMapsAPI",
|
|
54
|
+
# errors
|
|
55
|
+
"ScrapeMapsAPIError",
|
|
56
|
+
"APIConnectionError",
|
|
57
|
+
"APITimeoutError",
|
|
58
|
+
"AuthenticationError",
|
|
59
|
+
"CreditsCooldownError",
|
|
60
|
+
"InsufficientCreditsError",
|
|
61
|
+
"InternalServerError",
|
|
62
|
+
"InvalidRequestError",
|
|
63
|
+
"NotFoundError",
|
|
64
|
+
"PlaceNotFoundError",
|
|
65
|
+
"RateLimitError",
|
|
66
|
+
"ServiceUnavailableError",
|
|
67
|
+
"UpstreamError",
|
|
68
|
+
# models
|
|
69
|
+
"Address",
|
|
70
|
+
"DayHours",
|
|
71
|
+
"Link",
|
|
72
|
+
"Location",
|
|
73
|
+
"Meta",
|
|
74
|
+
"OpeningHours",
|
|
75
|
+
"OwnerResponse",
|
|
76
|
+
"Pagination",
|
|
77
|
+
"Photo",
|
|
78
|
+
"Place",
|
|
79
|
+
"PlaceIds",
|
|
80
|
+
"PlaceMeta",
|
|
81
|
+
"PlaceResponse",
|
|
82
|
+
"PlaceStatus",
|
|
83
|
+
"PlaceSummary",
|
|
84
|
+
"ResolvedIds",
|
|
85
|
+
"ResolveResponse",
|
|
86
|
+
"ResponseInfo",
|
|
87
|
+
"Review",
|
|
88
|
+
"ReviewAuthor",
|
|
89
|
+
"ReviewSort",
|
|
90
|
+
"ReviewsMeta",
|
|
91
|
+
"ReviewsResponse",
|
|
92
|
+
"SearchMeta",
|
|
93
|
+
"SearchResponse",
|
|
94
|
+
"TimePeriod",
|
|
95
|
+
]
|