catastrogps 2.1.0__tar.gz → 2.3.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 (24) hide show
  1. {catastrogps-2.1.0 → catastrogps-2.3.0}/CHANGELOG.md +11 -0
  2. {catastrogps-2.1.0 → catastrogps-2.3.0}/PKG-INFO +21 -5
  3. {catastrogps-2.1.0 → catastrogps-2.3.0}/README.md +20 -4
  4. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/__init__.py +9 -0
  5. catastrogps-2.3.0/catastrogps/_version.py +1 -0
  6. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/client.py +3 -0
  7. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/errors.py +12 -0
  8. catastrogps-2.3.0/catastrogps/monitoring.py +110 -0
  9. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/parcels.py +48 -0
  10. catastrogps-2.3.0/tests/test_sigpac.py +221 -0
  11. catastrogps-2.3.0/tests/test_startup.py +165 -0
  12. catastrogps-2.1.0/catastrogps/_version.py +0 -1
  13. {catastrogps-2.1.0 → catastrogps-2.3.0}/.gitignore +0 -0
  14. {catastrogps-2.1.0 → catastrogps-2.3.0}/LICENSE +0 -0
  15. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/export.py +0 -0
  16. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/fincas.py +0 -0
  17. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/locations.py +0 -0
  18. {catastrogps-2.1.0 → catastrogps-2.3.0}/catastrogps/py.typed +0 -0
  19. {catastrogps-2.1.0 → catastrogps-2.3.0}/pyproject.toml +0 -0
  20. {catastrogps-2.1.0 → catastrogps-2.3.0}/tests/__init__.py +0 -0
  21. {catastrogps-2.1.0 → catastrogps-2.3.0}/tests/test_analysis.py +0 -0
  22. {catastrogps-2.1.0 → catastrogps-2.3.0}/tests/test_client.py +0 -0
  23. {catastrogps-2.1.0 → catastrogps-2.3.0}/tests/test_fincas.py +0 -0
  24. {catastrogps-2.1.0 → catastrogps-2.3.0}/tests/test_subparcels_and_locations.py +0 -0
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.0 (2026-12-01)
4
+
5
+ - Startup plan endpoints: `parcels.notices(ref)`, `notices.search(...)` / `notices.iter_pages(...)`, `parcels.changes(ref, since=)`, report layers `parcels.risks|water|soil|protections|services(ref)` and `parcels.layer(ref, name)`, and batch jobs `batch.submit(references, layers=, country=)`, `batch.get(id)`, `batch.wait(id)`, `batch.csv(id)`.
6
+ - New errors: `PlanRequiredError` (`403 KEY_PLAN_001`, a `ForbiddenError`) and `PlanLimitError` (`429 KEY_LAYER_001`, `429 BAT_015`); neither is retried.
7
+
8
+ ## 2.2.0 (2026-10-23)
9
+
10
+ - `parcels.sigpac(ref, country=, lang=)`: `GET /v1/parcels/{ref}/sigpac`, every SIGPAC enclosure of a Spanish parcel (ES, PV, NA) with land use, irrigation, slope, altitude, CAP eligibility and region, incidents and outline. 1 unit, 0 when empty; `SIG_001` raises `ServiceUnavailableError`, retried and not charged.
11
+ - `parcels.sigpac_geojson(ref, country=, lang=)`: the same with `format=geojson`, parsed into a GeoJSON FeatureCollection dict.
12
+ - README: subparcels coverage lists every country the API answers (adds DE, CZ, NL, FR, PT, SE, CH, FI, BE, IE, SI).
13
+
3
14
  ## 2.1.0 (2026-10-21)
4
15
 
5
16
  - `parcels.subparcels(ref, country=, lang=)`: `GET /v1/parcels/{ref}/subparcels`, crops and land use of each part of the parcel (`cropCode`, `crop`, `cropOriginal`, `intensity`, `area`, `landType`, `landClass`, `kind`, `useClass`, `useClassName`, `source`, `geometry`). Paid (1 unit, 0 when empty); a source failure raises `ServiceUnavailableError` with code `SUB_001` and is not charged.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: catastrogps
3
- Version: 2.1.0
3
+ Version: 2.3.0
4
4
  Summary: Official Python client for the Catastro GPS API: parcels from 29 European countries (including the Basque Country and Navarre foral cadastres) by reference, coordinates or address; building units, terrain, ground motion, solar and more
5
5
  Project-URL: Homepage, https://www.parcelgps.com/developers
6
6
  Project-URL: Documentation, https://www.parcelgps.com/developers
@@ -44,7 +44,7 @@ Official Python client for the [Catastro GPS API](https://www.parcelgps.com/deve
44
44
  - Quota, prepaid balance and per-minute limit of every response, typed exceptions for every API code.
45
45
  - Two small dependencies (`httpx`, `typing_extensions`), typed, Python 3.9+.
46
46
 
47
- **Free tier: 250 calls a month, forever. Failed lookups are not charged.** Get a key at [parcelgps.com/developers](https://www.parcelgps.com/developers).
47
+ **Free tier: 25 calls a month, forever. Failed lookups are not charged.** Get a key at [parcelgps.com/developers](https://www.parcelgps.com/developers).
48
48
 
49
49
  ## Install
50
50
 
@@ -75,7 +75,9 @@ with CatastroGPS() as client:
75
75
  | Method | Endpoint | Countries |
76
76
  |--------|----------|-----------|
77
77
  | `parcels.get(ref, country=, lang=)` | `GET /v1/parcels/{ref}` | All references (see coverage). Carries `subparcelCount` and `cropSummary` |
78
- | `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, EE, GR. 1 unit; 0 when the parcel has none |
78
+ | `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, DE, CZ, NL, FR, PT, SE, CH, FI, BE, IE, SI, EE, GR. 1 unit; 0 when the parcel has none |
79
+ | `parcels.sigpac(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac` | ES, PV, NA. SIGPAC enclosures with land use, irrigation, slope, CAP eligibility, incidents and outline. 1 unit; 0 when there are none; `SIG_001` is not charged |
80
+ | `parcels.sigpac_geojson(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac?format=geojson` | The same as a GeoJSON FeatureCollection (dict) |
79
81
  | `parcels.neighbors(ref, country=)` | `GET /v1/parcels/{ref}/neighbors` | Spain, and countries where we hold a copy; `supported: false` (free) elsewhere |
80
82
  | `parcels.at_point(lat, lng, country=)` | `GET /v1/search/coordinates` | All, including HR, SE and UK (Scotland) |
81
83
  | `search_address_candidates(q, street=, number=, municipality=, postcode=, country=, limit=)` | `GET /v1/search/address/candidates` | Spain (with Basque Country and Navarre) and 26 more; not SE or HR |
@@ -92,6 +94,11 @@ with CatastroGPS() as client:
92
94
  | `resolve(text, hint=)` | `GET /v1/resolve` | Free, no quota: which country and kind a text is |
93
95
  | `crop_catalog(lang=)` | `GET /v1/reference/crops` | Free, no quota: every `cropCode` with its name in the 10 languages |
94
96
  | `locations.provinces()`, `locations.municipalities(region)`, `locations.streets(region, municipality, name=)` | `GET /v1/locations/...` | Spain, common territory |
97
+ | `parcels.notices(ref, limit=)` | `GET /v1/parcels/{ref}/notices` | **Startup plan and above.** Official notices that cite the parcel, 19 countries |
98
+ | `notices.search(country=, municipality_code=, municipality=, kind=, date_from=, date_to=, has_parcels=, cursor=, limit=)`, `notices.iter_pages(...)` | `GET /v1/notices` | **Startup.** Search official notices; `iter_pages` follows `nextCursor` |
99
+ | `parcels.changes(ref, since=, country=)` | `GET /v1/parcels/{ref}/changes` | **Startup.** ES only (surface, use, outline); `monitored` says whether we keep snapshots |
100
+ | `parcels.risks`, `water`, `soil`, `protections`, `services` (or `parcels.layer(ref, name)`) | `GET /v1/parcels/{ref}/{layer}` | **Startup.** Level and one sentence per item; limited in different parcels per month (Startup 2,000, Growth 10,000); show `attribution` ("Source: Catastro GPS") |
101
+ | `batch.submit(references, layers=, country=)`, `batch.get(id)`, `batch.wait(id)`, `batch.csv(id)` | `POST /v1/batch`, `GET /v1/batch/{id}` | **Startup.** Up to 1,000 references; one unit per reference and layer, charged on acceptance; reading is free |
95
102
 
96
103
  ## Examples
97
104
 
@@ -121,6 +128,11 @@ crops = client.parcels.subparcels("46063A00100121", lang="en")
121
128
  for row in crops["subparcels"]:
122
129
  print(row["cropCode"], row.get("crop"), row.get("cropOriginal"), row["area"], row.get("useClass"))
123
130
 
131
+ sigpac = client.parcels.sigpac("46063A00100121", lang="en")
132
+ for enclosure in sigpac["enclosures"]:
133
+ print(enclosure["id"], enclosure["landUseCode"], enclosure.get("landUse"), enclosure["areaHa"], enclosure["irrigationPct"])
134
+ collection = client.parcels.sigpac_geojson("46063A00100121")
135
+
124
136
  catalog = client.crop_catalog(lang="en")
125
137
  names = {crop["code"]: crop["name"] for crop in catalog["crops"]}
126
138
 
@@ -207,10 +219,12 @@ except QuotaExceededError as error:
207
219
  | `PlaceNameError` (a `ValidationError`) | `422 CNV_PLACE_NAME`: a place name, with the geocoded `location` when found |
208
220
  | `ValidationError` | `400 VALIDATION_ERROR`, other `422` |
209
221
  | `AuthenticationError` / `ForbiddenError` | `401 KEY_AUTH_001..003`, `403` |
222
+ | `PlanRequiredError` (a `ForbiddenError`) | `403 KEY_PLAN_001`: the key's plan does not include the endpoint; not charged, not retried |
223
+ | `PlanLimitError` | `429 KEY_LAYER_001` (different parcels per month of report layers used up) or `429 BAT_015` (not enough units for the batch); not retried |
210
224
  | `NotFoundError` | `404 NOT_FOUND` |
211
225
  | `QuotaExceededError` | `429 KEY_AUTH_004` |
212
226
  | `RateLimitError` | `429 KEY_RATE_002`, `RATE_LIMIT_EXCEEDED`; `retry_after` |
213
- | `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` (subparcels source down, not charged); `retry_after` |
227
+ | `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` / `SIG_001` (subparcels or SIGPAC source down, not charged); `retry_after` |
214
228
  | `ServerError`, `TimeoutError`, `NetworkError` | `5xx`, client timeout, network failure |
215
229
 
216
230
  Timeouts, network errors, per-minute 429s and 502/503/504 are retried up to `max_retries` times (default 2) with exponential backoff, waiting `Retry-After` when the API sends it (up to 60 s). An exhausted monthly quota is never retried.
@@ -251,11 +265,13 @@ Not covered: Hungary, Romania and the rest (`CoverageError`). Terrain and ground
251
265
 
252
266
  | Plan | Price | Calls / month | Prepaid overage per 1,000 |
253
267
  |------|-------|---------------|---------------------------|
254
- | Free | €0, forever | 250 | €10 |
268
+ | Free | €0, forever | 25 | €10 |
255
269
  | Developer | €19 / month | 5,000 | €5 |
256
270
  | Startup | €49 / month | 15,000 | €4 |
257
271
  | Growth | €99 / month | 50,000 | €2.50 |
258
272
 
273
+ Developer adds price data (`/market`, `/value-history`, price fields). Startup adds official notices, batch, cadastral changes and report layers. The full table is at https://parcelgps.com/developers#plans and in `x-plan-matrix` of the OpenAPI spec.
274
+
259
275
  Overage prices are net (VAT apart) and are charged from a prepaid balance you top up in the portal; with the balance at zero the API answers `429`, never debt.
260
276
 
261
277
  The same key works with the JavaScript SDK (`npm install catastrogps`), the Go SDK and the MCP server for AI agents ([`catastro-gps-mcp`](https://www.npmjs.com/package/catastro-gps-mcp)).
@@ -13,7 +13,7 @@ Official Python client for the [Catastro GPS API](https://www.parcelgps.com/deve
13
13
  - Quota, prepaid balance and per-minute limit of every response, typed exceptions for every API code.
14
14
  - Two small dependencies (`httpx`, `typing_extensions`), typed, Python 3.9+.
15
15
 
16
- **Free tier: 250 calls a month, forever. Failed lookups are not charged.** Get a key at [parcelgps.com/developers](https://www.parcelgps.com/developers).
16
+ **Free tier: 25 calls a month, forever. Failed lookups are not charged.** Get a key at [parcelgps.com/developers](https://www.parcelgps.com/developers).
17
17
 
18
18
  ## Install
19
19
 
@@ -44,7 +44,9 @@ with CatastroGPS() as client:
44
44
  | Method | Endpoint | Countries |
45
45
  |--------|----------|-----------|
46
46
  | `parcels.get(ref, country=, lang=)` | `GET /v1/parcels/{ref}` | All references (see coverage). Carries `subparcelCount` and `cropSummary` |
47
- | `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, EE, GR. 1 unit; 0 when the parcel has none |
47
+ | `parcels.subparcels(ref, country=, lang=)` | `GET /v1/parcels/{ref}/subparcels` | ES (with PV/NA), AT, DE, CZ, NL, FR, PT, SE, CH, FI, BE, IE, SI, EE, GR. 1 unit; 0 when the parcel has none |
48
+ | `parcels.sigpac(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac` | ES, PV, NA. SIGPAC enclosures with land use, irrigation, slope, CAP eligibility, incidents and outline. 1 unit; 0 when there are none; `SIG_001` is not charged |
49
+ | `parcels.sigpac_geojson(ref, country=, lang=)` | `GET /v1/parcels/{ref}/sigpac?format=geojson` | The same as a GeoJSON FeatureCollection (dict) |
48
50
  | `parcels.neighbors(ref, country=)` | `GET /v1/parcels/{ref}/neighbors` | Spain, and countries where we hold a copy; `supported: false` (free) elsewhere |
49
51
  | `parcels.at_point(lat, lng, country=)` | `GET /v1/search/coordinates` | All, including HR, SE and UK (Scotland) |
50
52
  | `search_address_candidates(q, street=, number=, municipality=, postcode=, country=, limit=)` | `GET /v1/search/address/candidates` | Spain (with Basque Country and Navarre) and 26 more; not SE or HR |
@@ -61,6 +63,11 @@ with CatastroGPS() as client:
61
63
  | `resolve(text, hint=)` | `GET /v1/resolve` | Free, no quota: which country and kind a text is |
62
64
  | `crop_catalog(lang=)` | `GET /v1/reference/crops` | Free, no quota: every `cropCode` with its name in the 10 languages |
63
65
  | `locations.provinces()`, `locations.municipalities(region)`, `locations.streets(region, municipality, name=)` | `GET /v1/locations/...` | Spain, common territory |
66
+ | `parcels.notices(ref, limit=)` | `GET /v1/parcels/{ref}/notices` | **Startup plan and above.** Official notices that cite the parcel, 19 countries |
67
+ | `notices.search(country=, municipality_code=, municipality=, kind=, date_from=, date_to=, has_parcels=, cursor=, limit=)`, `notices.iter_pages(...)` | `GET /v1/notices` | **Startup.** Search official notices; `iter_pages` follows `nextCursor` |
68
+ | `parcels.changes(ref, since=, country=)` | `GET /v1/parcels/{ref}/changes` | **Startup.** ES only (surface, use, outline); `monitored` says whether we keep snapshots |
69
+ | `parcels.risks`, `water`, `soil`, `protections`, `services` (or `parcels.layer(ref, name)`) | `GET /v1/parcels/{ref}/{layer}` | **Startup.** Level and one sentence per item; limited in different parcels per month (Startup 2,000, Growth 10,000); show `attribution` ("Source: Catastro GPS") |
70
+ | `batch.submit(references, layers=, country=)`, `batch.get(id)`, `batch.wait(id)`, `batch.csv(id)` | `POST /v1/batch`, `GET /v1/batch/{id}` | **Startup.** Up to 1,000 references; one unit per reference and layer, charged on acceptance; reading is free |
64
71
 
65
72
  ## Examples
66
73
 
@@ -90,6 +97,11 @@ crops = client.parcels.subparcels("46063A00100121", lang="en")
90
97
  for row in crops["subparcels"]:
91
98
  print(row["cropCode"], row.get("crop"), row.get("cropOriginal"), row["area"], row.get("useClass"))
92
99
 
100
+ sigpac = client.parcels.sigpac("46063A00100121", lang="en")
101
+ for enclosure in sigpac["enclosures"]:
102
+ print(enclosure["id"], enclosure["landUseCode"], enclosure.get("landUse"), enclosure["areaHa"], enclosure["irrigationPct"])
103
+ collection = client.parcels.sigpac_geojson("46063A00100121")
104
+
93
105
  catalog = client.crop_catalog(lang="en")
94
106
  names = {crop["code"]: crop["name"] for crop in catalog["crops"]}
95
107
 
@@ -176,10 +188,12 @@ except QuotaExceededError as error:
176
188
  | `PlaceNameError` (a `ValidationError`) | `422 CNV_PLACE_NAME`: a place name, with the geocoded `location` when found |
177
189
  | `ValidationError` | `400 VALIDATION_ERROR`, other `422` |
178
190
  | `AuthenticationError` / `ForbiddenError` | `401 KEY_AUTH_001..003`, `403` |
191
+ | `PlanRequiredError` (a `ForbiddenError`) | `403 KEY_PLAN_001`: the key's plan does not include the endpoint; not charged, not retried |
192
+ | `PlanLimitError` | `429 KEY_LAYER_001` (different parcels per month of report layers used up) or `429 BAT_015` (not enough units for the batch); not retried |
179
193
  | `NotFoundError` | `404 NOT_FOUND` |
180
194
  | `QuotaExceededError` | `429 KEY_AUTH_004` |
181
195
  | `RateLimitError` | `429 KEY_RATE_002`, `RATE_LIMIT_EXCEEDED`; `retry_after` |
182
- | `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` (subparcels source down, not charged); `retry_after` |
196
+ | `ServiceUnavailableError` | `503 SERVICE_UNAVAILABLE`, `SUB_001` / `SIG_001` (subparcels or SIGPAC source down, not charged); `retry_after` |
183
197
  | `ServerError`, `TimeoutError`, `NetworkError` | `5xx`, client timeout, network failure |
184
198
 
185
199
  Timeouts, network errors, per-minute 429s and 502/503/504 are retried up to `max_retries` times (default 2) with exponential backoff, waiting `Retry-After` when the API sends it (up to 60 s). An exhausted monthly quota is never retried.
@@ -220,11 +234,13 @@ Not covered: Hungary, Romania and the rest (`CoverageError`). Terrain and ground
220
234
 
221
235
  | Plan | Price | Calls / month | Prepaid overage per 1,000 |
222
236
  |------|-------|---------------|---------------------------|
223
- | Free | €0, forever | 250 | €10 |
237
+ | Free | €0, forever | 25 | €10 |
224
238
  | Developer | €19 / month | 5,000 | €5 |
225
239
  | Startup | €49 / month | 15,000 | €4 |
226
240
  | Growth | €99 / month | 50,000 | €2.50 |
227
241
 
242
+ Developer adds price data (`/market`, `/value-history`, price fields). Startup adds official notices, batch, cadastral changes and report layers. The full table is at https://parcelgps.com/developers#plans and in `x-plan-matrix` of the OpenAPI spec.
243
+
228
244
  Overage prices are net (VAT apart) and are charged from a prepaid balance you top up in the portal; with the balance at zero the API answers `429`, never debt.
229
245
 
230
246
  The same key works with the JavaScript SDK (`npm install catastrogps`), the Go SDK and the MCP server for AI agents ([`catastro-gps-mcp`](https://www.npmjs.com/package/catastro-gps-mcp)).
@@ -9,6 +9,8 @@ from catastrogps.errors import (
9
9
  NetworkError,
10
10
  NotFoundError,
11
11
  PlaceNameError,
12
+ PlanLimitError,
13
+ PlanRequiredError,
12
14
  QuotaExceededError,
13
15
  RateLimitError,
14
16
  ServerError,
@@ -17,16 +19,23 @@ from catastrogps.errors import (
17
19
  ValidationError,
18
20
  )
19
21
  from catastrogps.export import EXPORT_FORMATS
22
+ from catastrogps.monitoring import BATCH_LAYERS, MAX_BATCH_REFERENCES
20
23
  from catastrogps.parcels import (
21
24
  ADDRESS_COUNTRY_CODES,
22
25
  COUNTRY_CODES,
23
26
  CROP_LANGUAGES,
24
27
  ENRICHMENT_COUNTRY_CODES,
28
+ REPORT_LAYERS,
25
29
  UNITS_COUNTRY_CODES,
26
30
  )
27
31
 
28
32
  __all__ = [
29
33
  "ADDRESS_COUNTRY_CODES",
34
+ "BATCH_LAYERS",
35
+ "MAX_BATCH_REFERENCES",
36
+ "REPORT_LAYERS",
37
+ "PlanLimitError",
38
+ "PlanRequiredError",
30
39
  "COUNTRY_CODES",
31
40
  "CROP_LANGUAGES",
32
41
  "DEFAULT_BASE_URL",
@@ -0,0 +1 @@
1
+ __version__ = "2.3.0"
@@ -21,6 +21,7 @@ from catastrogps.errors import (
21
21
  from catastrogps.export import ExportResource
22
22
  from catastrogps.fincas import FincasResource
23
23
  from catastrogps.locations import LocationsResource
24
+ from catastrogps.monitoring import BatchResource, NoticesResource
24
25
  from catastrogps.parcels import ParcelsResource, crop_language
25
26
 
26
27
  DEFAULT_BASE_URL = "https://api.parcelgps.com"
@@ -63,6 +64,8 @@ class CatastroGPS:
63
64
  self.export = ExportResource(self)
64
65
  self.fincas = FincasResource(self)
65
66
  self.locations = LocationsResource(self)
67
+ self.notices = NoticesResource(self)
68
+ self.batch = BatchResource(self)
66
69
 
67
70
  def search_address_candidates(
68
71
  self,
@@ -31,6 +31,14 @@ class ForbiddenError(CatastroGPSError):
31
31
  pass
32
32
 
33
33
 
34
+ class PlanRequiredError(ForbiddenError):
35
+ pass
36
+
37
+
38
+ class PlanLimitError(CatastroGPSError):
39
+ pass
40
+
41
+
34
42
  class NotFoundError(CatastroGPSError):
35
43
  pass
36
44
 
@@ -123,6 +131,10 @@ def error_from_response(
123
131
  return CoverageError(message, **kwargs)
124
132
  if code == "CNV_PLACE_NAME":
125
133
  return PlaceNameError(message, **kwargs)
134
+ if code == "KEY_PLAN_001":
135
+ return PlanRequiredError(message, **kwargs)
136
+ if code in ("KEY_LAYER_001", "BAT_015"):
137
+ return PlanLimitError(message, **kwargs)
126
138
  if code == "KEY_AUTH_004":
127
139
  return QuotaExceededError(message, quota=quota, **kwargs)
128
140
  if status == 429:
@@ -0,0 +1,110 @@
1
+ from __future__ import annotations
2
+
3
+ import time
4
+ from collections.abc import Iterator
5
+ from typing import TYPE_CHECKING, Any
6
+ from urllib.parse import quote
7
+
8
+ from catastrogps.errors import CatastroGPSError
9
+
10
+ if TYPE_CHECKING:
11
+ from catastrogps.client import CatastroGPS
12
+
13
+ MAX_BATCH_REFERENCES = 1000
14
+ BATCH_LAYERS = ("parcel", "notices", "changes")
15
+ FINISHED_BATCH_STATUSES = ("completed", "partial_failure", "failed")
16
+ DEFAULT_WAIT_INTERVAL_SECONDS = 5.0
17
+ DEFAULT_WAIT_TIMEOUT_SECONDS = 1800.0
18
+
19
+
20
+ class NoticesResource:
21
+ def __init__(self, client: CatastroGPS) -> None:
22
+ self._client = client
23
+
24
+ def search(
25
+ self,
26
+ *,
27
+ country: str | None = None,
28
+ municipality_code: str | None = None,
29
+ municipality: str | None = None,
30
+ kind: str | None = None,
31
+ date_from: str | None = None,
32
+ date_to: str | None = None,
33
+ has_parcels: bool | None = None,
34
+ cursor: str | None = None,
35
+ limit: int | None = None,
36
+ ) -> dict[str, Any]:
37
+ query = {
38
+ "country": country,
39
+ "municipalityCode": municipality_code,
40
+ "municipality": municipality,
41
+ "kind": kind,
42
+ "from": date_from,
43
+ "to": date_to,
44
+ "hasParcels": None if has_parcels is None else str(has_parcels).lower(),
45
+ "cursor": cursor,
46
+ "limit": limit,
47
+ }
48
+ return self._client.request("GET", "/v1/notices", query=query)
49
+
50
+ def iter_pages(self, **filters: Any) -> Iterator[dict[str, Any]]:
51
+ cursor = filters.pop("cursor", None)
52
+ while True:
53
+ page = self.search(cursor=cursor, **filters)
54
+ yield page
55
+ cursor = page.get("nextCursor")
56
+ if not cursor:
57
+ return
58
+
59
+
60
+ class BatchResource:
61
+ def __init__(self, client: CatastroGPS) -> None:
62
+ self._client = client
63
+
64
+ def submit(
65
+ self, references: list[str], *, layers: list[str] | None = None, country: str | None = None
66
+ ) -> dict[str, Any]:
67
+ cleaned = [reference.strip() for reference in references if reference and reference.strip()]
68
+ if not cleaned:
69
+ raise CatastroGPSError("references must not be empty")
70
+ if len(cleaned) > MAX_BATCH_REFERENCES:
71
+ raise CatastroGPSError(f"a batch takes up to {MAX_BATCH_REFERENCES} references")
72
+ for layer in layers or []:
73
+ if layer not in BATCH_LAYERS:
74
+ raise CatastroGPSError(f"layers must be among {', '.join(BATCH_LAYERS)}")
75
+ body: dict[str, Any] = {"references": cleaned}
76
+ if layers:
77
+ body["layers"] = layers
78
+ if country:
79
+ body["country"] = country
80
+ return self._client.request("POST", "/v1/batch", body=body)
81
+
82
+ def get(self, batch_id: str) -> dict[str, Any]:
83
+ return self._client.request("GET", batch_path(batch_id))
84
+
85
+ def csv(self, batch_id: str) -> str:
86
+ content = self._client.request("GET", batch_path(batch_id), query={"format": "csv"}, raw=True)
87
+ return content.decode("utf-8")
88
+
89
+ def wait(
90
+ self,
91
+ batch_id: str,
92
+ *,
93
+ interval: float = DEFAULT_WAIT_INTERVAL_SECONDS,
94
+ timeout: float = DEFAULT_WAIT_TIMEOUT_SECONDS,
95
+ ) -> dict[str, Any]:
96
+ deadline = time.monotonic() + timeout
97
+ while True:
98
+ batch = self.get(batch_id)
99
+ if batch.get("status") in FINISHED_BATCH_STATUSES:
100
+ return batch
101
+ if time.monotonic() + interval > deadline:
102
+ raise CatastroGPSError(f"batch {batch_id} did not finish in time")
103
+ time.sleep(interval)
104
+
105
+
106
+ def batch_path(batch_id: str) -> str:
107
+ cleaned = (batch_id or "").strip()
108
+ if not cleaned:
109
+ raise CatastroGPSError("batch id must not be empty")
110
+ return f"/v1/batch/{quote(cleaned, safe='')}"
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import json
3
4
  import math
4
5
  from typing import TYPE_CHECKING, Any
5
6
  from urllib.parse import quote
@@ -82,6 +83,8 @@ CROP_LANGUAGES = ("es", "ca", "en", "pt", "fr", "it", "de", "pl", "nl", "cs")
82
83
  MIN_COMPARE = 2
83
84
  MAX_COMPARE = 3
84
85
 
86
+ REPORT_LAYERS = ("risks", "water", "soil", "protections", "services")
87
+
85
88
 
86
89
  def parcel_path(reference: str, suffix: str = "") -> str:
87
90
  cleaned = (reference or "").strip()
@@ -104,6 +107,23 @@ class ParcelsResource:
104
107
  "GET", parcel_path(reference, "/subparcels"), query={"country": country, "lang": crop_language(lang)}
105
108
  )
106
109
 
110
+ def sigpac(self, reference: str, *, country: str | None = None, lang: str | None = None) -> dict[str, Any]:
111
+ return self._client.request(
112
+ "GET", parcel_path(reference, "/sigpac"), query={"country": country, "lang": crop_language(lang)}
113
+ )
114
+
115
+ def sigpac_geojson(self, reference: str, *, country: str | None = None, lang: str | None = None) -> dict[str, Any]:
116
+ content = self._client.request(
117
+ "GET",
118
+ parcel_path(reference, "/sigpac"),
119
+ query={"country": country, "lang": crop_language(lang), "format": "geojson"},
120
+ raw=True,
121
+ )
122
+ try:
123
+ return json.loads(content)
124
+ except ValueError as error:
125
+ raise CatastroGPSError("SIGPAC GeoJSON response is not valid JSON") from error
126
+
107
127
  def neighbors(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
108
128
  return self._client.request("GET", parcel_path(reference, "/neighbors"), query={"country": country})
109
129
 
@@ -149,6 +169,34 @@ class ParcelsResource:
149
169
  def value_history(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
150
170
  return self._client.request("GET", parcel_path(reference, "/value-history"), query={"country": country})
151
171
 
172
+ def notices(self, reference: str, *, limit: int | None = None) -> dict[str, Any]:
173
+ return self._client.request("GET", parcel_path(reference, "/notices"), query={"limit": limit})
174
+
175
+ def changes(self, reference: str, *, since: str | None = None, country: str | None = None) -> dict[str, Any]:
176
+ return self._client.request(
177
+ "GET", parcel_path(reference, "/changes"), query={"since": since, "country": country}
178
+ )
179
+
180
+ def layer(self, reference: str, layer: str, *, country: str | None = None) -> dict[str, Any]:
181
+ if layer not in REPORT_LAYERS:
182
+ raise CatastroGPSError(f"layer must be one of {', '.join(REPORT_LAYERS)}")
183
+ return self._client.request("GET", parcel_path(reference, f"/{layer}"), query={"country": country})
184
+
185
+ def risks(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
186
+ return self.layer(reference, "risks", country=country)
187
+
188
+ def water(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
189
+ return self.layer(reference, "water", country=country)
190
+
191
+ def soil(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
192
+ return self.layer(reference, "soil", country=country)
193
+
194
+ def protections(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
195
+ return self.layer(reference, "protections", country=country)
196
+
197
+ def services(self, reference: str, *, country: str | None = None) -> dict[str, Any]:
198
+ return self.layer(reference, "services", country=country)
199
+
152
200
  def compare(self, parcels: list[tuple[str, str]] | list[dict[str, str]]) -> dict[str, Any]:
153
201
  items = [_compare_item(parcel) for parcel in parcels]
154
202
  if not MIN_COMPARE <= len(items) <= MAX_COMPARE:
@@ -0,0 +1,221 @@
1
+ import json
2
+
3
+ import httpx
4
+ import pytest
5
+
6
+ import catastrogps.client as client_module
7
+ from catastrogps import (
8
+ AuthenticationError,
9
+ CatastroGPS,
10
+ CatastroGPSError,
11
+ CoverageError,
12
+ NotFoundError,
13
+ QuotaExceededError,
14
+ RateLimitError,
15
+ ServerError,
16
+ ServiceUnavailableError,
17
+ TimeoutError,
18
+ )
19
+
20
+
21
+ class Recorder:
22
+ def __init__(self, *responses):
23
+ self.responses = list(responses)
24
+ self.requests = []
25
+
26
+ def __call__(self, request: httpx.Request) -> httpx.Response:
27
+ self.requests.append(request)
28
+ response = self.responses.pop(0)
29
+ if isinstance(response, Exception):
30
+ raise response
31
+ return response
32
+
33
+ @property
34
+ def last(self) -> httpx.Request:
35
+ return self.requests[-1]
36
+
37
+
38
+ @pytest.fixture(autouse=True)
39
+ def no_sleep(monkeypatch):
40
+ monkeypatch.setattr(client_module.time, "sleep", lambda _seconds: None)
41
+
42
+
43
+ def make(*responses, max_retries=0):
44
+ recorder = Recorder(*responses)
45
+ http = httpx.Client(transport=httpx.MockTransport(recorder))
46
+ client = CatastroGPS(
47
+ "pk_test_000000000000", base_url="https://api.example.test", http_client=http, max_retries=max_retries
48
+ )
49
+ return client, recorder
50
+
51
+
52
+ def ok(data, headers=None):
53
+ return httpx.Response(200, json={"success": True, "data": data}, headers=headers)
54
+
55
+
56
+ def fail(status, code, message="error", headers=None, details=None):
57
+ body = {"success": False, "code": code, "message": message}
58
+ if details is not None:
59
+ body["details"] = details
60
+ return httpx.Response(status, json=body, headers=headers)
61
+
62
+
63
+ SIGPAC = {
64
+ "reference": "46063A00100121",
65
+ "country": "ES",
66
+ "sigpacParcel": {"province": 46, "municipality": 63, "aggregate": 0, "zone": 0, "polygon": 1, "parcel": 121},
67
+ "match": "reference",
68
+ "count": 2,
69
+ "totalAreaHa": 0.8815,
70
+ "crs": "EPSG:4258 (ETRS89, lon/lat; equal to WGS84 within about 1 m)",
71
+ "retrievedAt": "2026-10-22T13:47:26Z",
72
+ "source": {"name": "SIGPAC", "provider": "FEGA", "license": "Ley 37/2007", "attribution": "Fuente: FEGA — SIGPAC"},
73
+ "enclosures": [
74
+ {
75
+ "id": "46:63:0:0:1:121:2",
76
+ "enclosure": 2,
77
+ "landUseCode": "FY",
78
+ "landUse": "Fruit trees",
79
+ "cropCode": "SIGPAC:FY",
80
+ "useClass": "orchard",
81
+ "areaHa": 0.0513,
82
+ "irrigationPct": 0,
83
+ "meanSlopePct": 7.6,
84
+ "altitudeM": 117,
85
+ "pastureEligibilityPct": None,
86
+ "capRegion": 12,
87
+ "incidents": [{"code": 199, "description": "Recinto inactivo"}],
88
+ "geometry": {"type": "Polygon", "coordinates": []},
89
+ },
90
+ {
91
+ "id": "46:63:0:0:1:121:9",
92
+ "enclosure": 9,
93
+ "landUseCode": "ZZ",
94
+ "areaHa": 0.0039,
95
+ "irrigationPct": None,
96
+ "meanSlopePct": None,
97
+ "altitudeM": None,
98
+ "pastureEligibilityPct": None,
99
+ "capRegion": None,
100
+ "incidents": [],
101
+ "geometry": None,
102
+ },
103
+ ],
104
+ }
105
+
106
+ GEOJSON = {
107
+ "type": "FeatureCollection",
108
+ "reference": "46063A00100121",
109
+ "count": 1,
110
+ "features": [{"type": "Feature", "properties": {"landUseCode": "FY"}, "geometry": None}],
111
+ }
112
+
113
+
114
+ def test_sigpac_sends_country_and_lang_and_returns_data():
115
+ client, rec = make(ok(SIGPAC, headers={"X-Quota-Remaining": "41"}))
116
+ out = client.parcels.sigpac(" 46063A00100121 ", country="ES", lang="EN")
117
+ assert rec.last.method == "GET"
118
+ assert rec.last.url.path == "/v1/parcels/46063A00100121/sigpac"
119
+ assert dict(rec.last.url.params) == {"country": "ES", "lang": "en"}
120
+ assert rec.last.headers["Accept"] == "application/json"
121
+ assert out["count"] == 2
122
+ assert out["sigpacParcel"]["parcel"] == 121
123
+ assert out["enclosures"][0]["incidents"][0]["code"] == 199
124
+ assert out["enclosures"][1]["irrigationPct"] is None
125
+ assert out["enclosures"][1]["geometry"] is None
126
+ assert client.last_quota["remaining"] == 41
127
+
128
+
129
+ def test_sigpac_without_options_sends_no_query():
130
+ client, rec = make(ok(SIGPAC))
131
+ client.parcels.sigpac("46063A00100121")
132
+ assert dict(rec.last.url.params) == {}
133
+
134
+
135
+ def test_sigpac_no_enclosures():
136
+ empty = {**SIGPAC, "sigpacParcel": None, "match": "point", "count": 0, "totalAreaHa": 0, "enclosures": []}
137
+ client, _ = make(ok(empty))
138
+ out = client.parcels.sigpac("9872023VH5797S0001WX")
139
+ assert out["sigpacParcel"] is None
140
+ assert out["enclosures"] == []
141
+
142
+
143
+ @pytest.mark.parametrize("call", ["sigpac", "sigpac_geojson"])
144
+ def test_sigpac_validates_before_request(call):
145
+ client, rec = make()
146
+ with pytest.raises(CatastroGPSError):
147
+ getattr(client.parcels, call)(" ")
148
+ with pytest.raises(CatastroGPSError):
149
+ getattr(client.parcels, call)("46063A00100121", lang="ja")
150
+ assert rec.requests == []
151
+
152
+
153
+ def test_sigpac_geojson_parses_feature_collection():
154
+ response = httpx.Response(
155
+ 200,
156
+ content=json.dumps(GEOJSON).encode(),
157
+ headers={
158
+ "Content-Type": "application/geo+json",
159
+ "Content-Disposition": 'attachment; filename="sigpac.geojson"',
160
+ "X-Quota-Remaining": "40",
161
+ },
162
+ )
163
+ client, rec = make(response)
164
+ out = client.parcels.sigpac_geojson("46063A00100121", country="NA", lang="de")
165
+ assert dict(rec.last.url.params) == {"country": "NA", "lang": "de", "format": "geojson"}
166
+ assert rec.last.headers["Accept"] == "*/*"
167
+ assert out == GEOJSON
168
+ assert client.last_quota["remaining"] == 40
169
+
170
+
171
+ def test_sigpac_geojson_invalid_body():
172
+ client, _ = make(httpx.Response(200, content=b"<html>", headers={"Content-Type": "text/html"}))
173
+ with pytest.raises(CatastroGPSError, match="not valid JSON"):
174
+ client.parcels.sigpac_geojson("46063A00100121")
175
+
176
+
177
+ @pytest.mark.parametrize(
178
+ "status,code,error",
179
+ [
180
+ (401, "KEY_AUTH_002", AuthenticationError),
181
+ (404, "NOT_FOUND", NotFoundError),
182
+ (422, "CNV_COVERAGE", CoverageError),
183
+ (429, "KEY_AUTH_004", QuotaExceededError),
184
+ (429, "KEY_RATE_002", RateLimitError),
185
+ (500, "INTERNAL", ServerError),
186
+ (503, "SIG_001", ServiceUnavailableError),
187
+ ],
188
+ )
189
+ @pytest.mark.parametrize("call", ["sigpac", "sigpac_geojson"])
190
+ def test_sigpac_errors(call, status, code, error):
191
+ details = {"feature": "sigpac", "supportedCountries": ["ES", "PV", "NA"]}
192
+ client, rec = make(fail(status, code, details=details, headers={"Retry-After": "3"}))
193
+ with pytest.raises(error) as caught:
194
+ getattr(client.parcels, call)("CH119192997709")
195
+ assert caught.value.code == code
196
+ assert caught.value.status == status
197
+ assert len(rec.requests) == 1
198
+
199
+
200
+ def test_sigpac_down_is_retried_then_succeeds():
201
+ client, rec = make(
202
+ fail(503, "SIG_001", "The SIGPAC enclosures could not be read right now.", headers={"Retry-After": "2"}),
203
+ ok(SIGPAC),
204
+ max_retries=1,
205
+ )
206
+ assert client.parcels.sigpac("46063A00100121")["count"] == 2
207
+ assert len(rec.requests) == 2
208
+
209
+
210
+ def test_sigpac_quota_exceeded_not_retried():
211
+ client, rec = make(fail(429, "KEY_AUTH_004"), max_retries=3)
212
+ with pytest.raises(QuotaExceededError):
213
+ client.parcels.sigpac("46063A00100121")
214
+ assert len(rec.requests) == 1
215
+
216
+
217
+ def test_sigpac_timeout():
218
+ client, rec = make(httpx.ReadTimeout("slow"), httpx.ReadTimeout("slow"), max_retries=1)
219
+ with pytest.raises(TimeoutError):
220
+ client.parcels.sigpac("46063A00100121")
221
+ assert len(rec.requests) == 2
@@ -0,0 +1,165 @@
1
+ import json
2
+
3
+ import httpx
4
+ import pytest
5
+
6
+ import catastrogps.client as client_module
7
+ import catastrogps.monitoring as monitoring_module
8
+ from catastrogps import (
9
+ MAX_BATCH_REFERENCES,
10
+ CatastroGPS,
11
+ CatastroGPSError,
12
+ ForbiddenError,
13
+ PlanLimitError,
14
+ PlanRequiredError,
15
+ )
16
+
17
+
18
+ class Recorder:
19
+ def __init__(self, *responses):
20
+ self.responses = list(responses)
21
+ self.requests = []
22
+
23
+ def __call__(self, request: httpx.Request) -> httpx.Response:
24
+ self.requests.append(request)
25
+ return self.responses.pop(0)
26
+
27
+
28
+ @pytest.fixture(autouse=True)
29
+ def no_sleep(monkeypatch):
30
+ monkeypatch.setattr(client_module.time, "sleep", lambda _seconds: None)
31
+ monkeypatch.setattr(monitoring_module.time, "sleep", lambda _seconds: None)
32
+
33
+
34
+ def make(*responses, max_retries=2):
35
+ recorder = Recorder(*responses)
36
+ http = httpx.Client(transport=httpx.MockTransport(recorder))
37
+ client = CatastroGPS(
38
+ "pk_test_000000000000", base_url="https://api.example.test", http_client=http, max_retries=max_retries
39
+ )
40
+ return client, recorder
41
+
42
+
43
+ def ok(data, status=200):
44
+ return httpx.Response(status, json={"success": True, "data": data})
45
+
46
+
47
+ NOTICE = {"id": "n1", "country": "ES", "source": "boe_es", "kind": "expropriation", "publishedAt": "2026-11-30",
48
+ "title": "Anuncio", "url": "https://www.boe.es/x", "municipalities": [], "municipalityCodes": []}
49
+ BATCH = {"id": "b1", "status": "pending", "layers": ["parcel"], "referenceCount": 2, "processed": 0, "succeeded": 0,
50
+ "failed": 0, "unitsCharged": 2, "createdAt": "2026-12-01T10:00:00Z", "results": []}
51
+
52
+
53
+ def test_parcel_notices_and_limit():
54
+ client, recorder = make(ok({"reference": "R1", "count": 1, "items": [NOTICE]}))
55
+ result = client.parcels.notices(" R1 ", limit=5)
56
+ assert result["items"][0]["kind"] == "expropriation"
57
+ request = recorder.requests[0]
58
+ assert request.url.path == "/v1/parcels/R1/notices"
59
+ assert request.url.params["limit"] == "5"
60
+
61
+
62
+ def test_notice_search_maps_filters_and_pages():
63
+ client, recorder = make(
64
+ ok({"count": 1, "items": [NOTICE], "nextCursor": "c2"}),
65
+ ok({"count": 1, "items": [NOTICE]}),
66
+ )
67
+ pages = list(client.notices.iter_pages(country="ES", kind="planning", date_from="2026-01-01",
68
+ date_to="2026-02-01", has_parcels=True, municipality_code="33024",
69
+ municipality="GIJON", limit=1))
70
+ assert len(pages) == 2
71
+ first = recorder.requests[0].url.params
72
+ assert first["from"] == "2026-01-01"
73
+ assert first["to"] == "2026-02-01"
74
+ assert first["hasParcels"] == "true"
75
+ assert first["municipalityCode"] == "33024"
76
+ assert "cursor" not in first
77
+ assert recorder.requests[1].url.params["cursor"] == "c2"
78
+
79
+
80
+ def test_notice_search_without_filters():
81
+ client, recorder = make(ok({"count": 0, "items": []}))
82
+ client.notices.search(has_parcels=False)
83
+ assert dict(recorder.requests[0].url.params) == {"hasParcels": "false"}
84
+
85
+
86
+ def test_changes_since():
87
+ client, recorder = make(ok({"reference": "R", "country": "ES", "monitored": False, "count": 0, "items": []}))
88
+ assert client.parcels.changes("R", since="2026-01-01", country="ES")["monitored"] is False
89
+ assert recorder.requests[0].url.path == "/v1/parcels/R/changes"
90
+ assert recorder.requests[0].url.params["since"] == "2026-01-01"
91
+
92
+
93
+ @pytest.mark.parametrize("layer", ["risks", "water", "soil", "protections", "services"])
94
+ def test_report_layers(layer):
95
+ client, recorder = make(ok({"reference": "R", "country": "ES", "layer": layer, "items": [],
96
+ "attribution": "Source: Catastro GPS"}))
97
+ assert getattr(client.parcels, layer)("R", country="ES")["attribution"] == "Source: Catastro GPS"
98
+ assert recorder.requests[0].url.path == f"/v1/parcels/R/{layer}"
99
+
100
+
101
+ def test_unknown_layer_is_refused_locally():
102
+ client, recorder = make()
103
+ with pytest.raises(CatastroGPSError, match="layer must be one of"):
104
+ client.parcels.layer("R", "market")
105
+ assert recorder.requests == []
106
+
107
+
108
+ def test_plan_errors_are_typed_and_not_retried():
109
+ client, recorder = make(httpx.Response(403, json={"success": False, "code": "KEY_PLAN_001", "message": "Startup"}))
110
+ with pytest.raises(PlanRequiredError) as raised:
111
+ client.parcels.risks("R")
112
+ assert isinstance(raised.value, ForbiddenError)
113
+ assert len(recorder.requests) == 1
114
+
115
+ client, recorder = make(httpx.Response(429, json={"success": False, "code": "KEY_LAYER_001", "message": "cap"},
116
+ headers={"Retry-After": "1"}))
117
+ with pytest.raises(PlanLimitError):
118
+ client.parcels.water("R")
119
+ assert len(recorder.requests) == 1
120
+
121
+
122
+ def test_batch_submit_trims_and_sends_layers():
123
+ client, recorder = make(ok(BATCH, 202), ok(BATCH, 202))
124
+ client.batch.submit([" A1 ", "", "B2"], layers=["parcel", "notices"], country="ES")
125
+ request = recorder.requests[0]
126
+ assert request.method == "POST"
127
+ assert json.loads(request.content) == {"references": ["A1", "B2"], "layers": ["parcel", "notices"], "country": "ES"}
128
+ client.batch.submit(["A1"])
129
+ assert json.loads(recorder.requests[1].content) == {"references": ["A1"]}
130
+
131
+
132
+ def test_batch_validation():
133
+ client, recorder = make()
134
+ with pytest.raises(CatastroGPSError, match="must not be empty"):
135
+ client.batch.submit([" "])
136
+ with pytest.raises(CatastroGPSError, match="up to 1000"):
137
+ client.batch.submit([f"R{i}" for i in range(MAX_BATCH_REFERENCES + 1)])
138
+ with pytest.raises(CatastroGPSError, match="layers must be among"):
139
+ client.batch.submit(["A"], layers=["market"])
140
+ with pytest.raises(CatastroGPSError, match="batch id"):
141
+ client.batch.get(" ")
142
+ assert recorder.requests == []
143
+
144
+
145
+ def test_batch_units_error():
146
+ client, _ = make(httpx.Response(429, json={"success": False, "code": "BAT_015", "message": "units"}))
147
+ with pytest.raises(PlanLimitError):
148
+ client.batch.submit(["A"])
149
+
150
+
151
+ def test_batch_get_csv_and_wait():
152
+ client, recorder = make(
153
+ ok({**BATCH, "status": "processing"}),
154
+ ok({**BATCH, "status": "completed"}),
155
+ httpx.Response(200, content=b"index,reference\n0,A1\n", headers={"Content-Type": "text/csv"}),
156
+ )
157
+ assert client.batch.wait("b1", interval=0.0, timeout=10)["status"] == "completed"
158
+ assert client.batch.csv("b1") == "index,reference\n0,A1\n"
159
+ assert recorder.requests[2].url.params["format"] == "csv"
160
+
161
+
162
+ def test_batch_wait_times_out():
163
+ client, _ = make(ok({**BATCH, "status": "processing"}))
164
+ with pytest.raises(CatastroGPSError, match="did not finish"):
165
+ client.batch.wait("b1", interval=5, timeout=1)
@@ -1 +0,0 @@
1
- __version__ = "2.1.0"
File without changes
File without changes
File without changes