ispra-idrogeo 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.
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.4
2
+ Name: ispra-idrogeo
3
+ Version: 0.1.0
4
+ Summary: Downloads and API client for ISPRA IdroGEO: IFFI landslide inventory, hazard mosaics and events, with a persistent conditional-GET cache
5
+ Keywords: ispra,idrogeo,iffi,landslide,frane,hazard,pai,flood,italy,gis
6
+ Author: Giuseppe Zileni
7
+ Author-email: Giuseppe Zileni <giuseppe.zileni@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: GIS
13
+ Classifier: Framework :: AsyncIO
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: httpx>=0.27
20
+ Requires-Python: >=3.12
21
+ Project-URL: Homepage, https://github.com/agent-engineering-studio/ispra-idrogeo
22
+ Project-URL: Issues, https://github.com/agent-engineering-studio/ispra-idrogeo/issues
23
+ Project-URL: Changelog, https://github.com/agent-engineering-studio/ispra-idrogeo/blob/main/CHANGELOG.md
24
+ Description-Content-Type: text/markdown
25
+
26
+ # ispra-idrogeo
27
+
28
+ <p>
29
+ <a href="https://github.com/agent-engineering-studio/ispra-idrogeo/actions/workflows/ci.yml"><img src="https://github.com/agent-engineering-studio/ispra-idrogeo/actions/workflows/ci.yml/badge.svg" alt="ci"></a>
30
+ <a href="https://pypi.org/project/ispra-idrogeo/"><img src="https://img.shields.io/pypi/v/ispra-idrogeo" alt="PyPI"></a>
31
+ <img src="https://img.shields.io/badge/python-3.12%20%7C%203.13-blue" alt="Python 3.12 | 3.13">
32
+ <img src="https://img.shields.io/badge/typing-mypy%20strict-informational" alt="mypy strict">
33
+ <img src="https://img.shields.io/badge/coverage-100%25-brightgreen" alt="coverage 100%">
34
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green" alt="Apache-2.0"></a>
35
+ </p>
36
+
37
+ **ispra-idrogeo** is a small, typed, async Python library for
38
+ [IdroGEO](https://idrogeo.isprambiente.it/), the ISPRA platform for
39
+ landslides and floods in Italy. It downloads the **IFFI landslide inventory**
40
+ (721,365 landslides in November 2026), the **dated landslide events** and the
41
+ national **PAI landslide and flood hazard mosaics** into a **persistent
42
+ folder**, and asks again only for what changed. It also reads the public
43
+ **REST API**: summaries and risk indicators per region, province and
44
+ municipality, code lists, paged searches.
45
+
46
+ ```python
47
+ async with IdroGEO() as idrogeo:
48
+ folder = await idrogeo.fetch(opendata("frane_poly")) # ~570 MB the first time, a 304 after
49
+ ```
50
+
51
+ No account, no key. One dependency: `httpx`.
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ pip install ispra-idrogeo
57
+ ```
58
+
59
+ ## Quick start
60
+
61
+ ```python
62
+ import asyncio
63
+
64
+ from ispra_idrogeo import IdroGEO, mosaic, opendata
65
+
66
+
67
+ async def main() -> None:
68
+ async with IdroGEO() as idrogeo:
69
+ # IFFI points (one per landslide), for the whole of Italy.
70
+ points = await idrogeo.fetch(opendata("frane_piff"))
71
+ # The same layer as GeoJSON, for one region.
72
+ puglia = await idrogeo.fetch(opendata("frane_piff", "puglia", "geojson"))
73
+ # The national flood hazard mosaic (~750 MB).
74
+ floods = await idrogeo.fetch(mosaic("idraulica"))
75
+ # API: IFFI counts for Puglia (ISTAT region 16).
76
+ summary = await idrogeo.summary("iffi", "regioni", 16)
77
+ print(points, puglia, floods, summary["nome"])
78
+
79
+
80
+ asyncio.run(main())
81
+ ```
82
+
83
+ `fetch` returns the folder the ZIP unpacks to (`<dir>/frane_piff_ispra_opendata/`);
84
+ `download` returns the file and whether this call changed it.
85
+
86
+ ## What there is
87
+
88
+ | Layer | What | Italy, zipped |
89
+ |---|---|---|
90
+ | `frane_piff` | IFFI landslide identification points, one per landslide | 38 MB |
91
+ | `frane_poly` | IFFI landslide polygons | 573 MB |
92
+ | `frane_line` | IFFI landslides too narrow for a polygon | 18 MB |
93
+ | `aree_poly` | areas of diffuse landslides | 236 MB |
94
+ | `dgpv_poly` | deep-seated gravitational slope deformations | 4 MB |
95
+ | `eventi` | dated landslide events (points) | 1 MB |
96
+ | `segnalazioni` | reports | small |
97
+ | `mosaic("pai_frane")` | PAI landslide hazard mosaic 2020-2021 | 1.2 GB |
98
+ | `mosaic("idraulica")` | flood hazard mosaic 2020 | 0.75 GB |
99
+ | `sensor_data()` | monitoring network readings, CSV (bzip2) | |
100
+
101
+ Every `opendata` layer comes as a shapefile (default) or GeoJSON
102
+ (`fmt="geojson"`), for Italy (`area="ispra"`, the default) or for one area:
103
+ the 19 region file names in `REGIONS` (by ISTAT code), and the provinces
104
+ that publish separately in `PROVINCES` (Bolzano, Trento, the Sicilian ones).
105
+ Coordinates are in **EPSG:32632** (WGS 84 / UTM 32N).
106
+
107
+ ## Where downloads are saved
108
+
109
+ In a folder that should survive restarts, because the national files weigh
110
+ hundreds of MB:
111
+
112
+ 1. the `directory` you pass;
113
+ 2. else `IDROGEO_DATA_DIR`;
114
+ 3. else `~/.cache/ispra-idrogeo` (or `$XDG_CACHE_HOME/ispra-idrogeo`).
115
+
116
+ Next to each file, `<file>.meta.json` keeps the `ETag` and `Last-Modified`
117
+ the server sent. ISPRA regenerates the inventory files **every day**, so
118
+ they become a conditional GET: an unchanged file costs one `304 Not
119
+ Modified`, a changed one is downloaded and unpacked again.
120
+
121
+ Downloads stream to `<file>.part` and are renamed when complete; unpacking
122
+ goes to `<folder>.part` and is swapped in whole. A reader never finds half a
123
+ file or half a shapefile, and a ZIP member that would land outside its
124
+ folder is refused.
125
+
126
+ ## The API
127
+
128
+ ```python
129
+ async with IdroGEO() as idrogeo:
130
+ italy = await idrogeo.summary("pir", "italia") # hazard and risk indicators
131
+ bari = await idrogeo.summary("pir", "comuni", 72006) # one municipality
132
+ regions = await idrogeo.summary("iffi", "regioni") # the list of a level
133
+ names = await idrogeo.dictionaries() # the code lists
134
+ causes = await idrogeo.dictionary("cause")
135
+ page = await idrogeo.search_landslides(limit=100, offset=0, select=["id_frana"])
136
+ ```
137
+
138
+ Reading needs no account. Search filters are a JSON object whose syntax is
139
+ in ISPRA's technical manual; an empty one matches everything, so page with
140
+ `limit` and `offset`. Some detail endpoints (`/frana/{id}`) answer 401
141
+ without a login, whatever the OpenAPI document says.
142
+
143
+ ## Errors and retries
144
+
145
+ - A dataset that does not exist (404), an API refusal, or a JSON that is
146
+ not what was asked for raise `IdrogeoError`.
147
+ - Network errors and 429/5xx are retried `retries` times (default 3) with
148
+ exponential backoff, then propagate as `httpx` exceptions. Pass
149
+ `retries=0` to wrap the calls in your own retry policy.
150
+ - Give it your `httpx.AsyncClient` and timeouts, proxies and pooling stay
151
+ yours.
152
+
153
+ ## The traps we already fell into
154
+
155
+ - **The old paths are gone.** `/opendata/iffi/<region>/iffi_<region>_<layer>.zip`
156
+ and `/opendata/iffi/dizionari/*.json` answer 404 in 2026. The files moved
157
+ to `/opendata/frane/`, the dictionaries to the API.
158
+ - **The WFS is not public.** `geoserver/idrogeo/frane/ows` answers 401, and
159
+ the global GeoServer lists no layer to an anonymous user. The downloads
160
+ and the API are the open way in.
161
+ - **Not every IdroGEO area is a region.** Trentino-Alto Adige publishes per
162
+ province (`bolzano`, `trento`), and Sicily also per province, besides its
163
+ regional file.
164
+
165
+ ## Data licence
166
+
167
+ Unless stated otherwise, ISPRA publishes its data under
168
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/legalcode)
169
+ ([note legali](https://www.isprambiente.gov.it/it/note-legali)): credit
170
+ *ISPRA — IdroGEO* when you publish anything derived from them. This library
171
+ only downloads them.
172
+
173
+ ## Development
174
+
175
+ ```bash
176
+ uv sync
177
+ make check
178
+ ```
179
+
180
+ Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
181
+ a multi-hazard risk monitor for Italy.
182
+
183
+ ## License
184
+
185
+ [Apache-2.0](./LICENSE).
@@ -0,0 +1,160 @@
1
+ # ispra-idrogeo
2
+
3
+ <p>
4
+ <a href="https://github.com/agent-engineering-studio/ispra-idrogeo/actions/workflows/ci.yml"><img src="https://github.com/agent-engineering-studio/ispra-idrogeo/actions/workflows/ci.yml/badge.svg" alt="ci"></a>
5
+ <a href="https://pypi.org/project/ispra-idrogeo/"><img src="https://img.shields.io/pypi/v/ispra-idrogeo" alt="PyPI"></a>
6
+ <img src="https://img.shields.io/badge/python-3.12%20%7C%203.13-blue" alt="Python 3.12 | 3.13">
7
+ <img src="https://img.shields.io/badge/typing-mypy%20strict-informational" alt="mypy strict">
8
+ <img src="https://img.shields.io/badge/coverage-100%25-brightgreen" alt="coverage 100%">
9
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green" alt="Apache-2.0"></a>
10
+ </p>
11
+
12
+ **ispra-idrogeo** is a small, typed, async Python library for
13
+ [IdroGEO](https://idrogeo.isprambiente.it/), the ISPRA platform for
14
+ landslides and floods in Italy. It downloads the **IFFI landslide inventory**
15
+ (721,365 landslides in November 2026), the **dated landslide events** and the
16
+ national **PAI landslide and flood hazard mosaics** into a **persistent
17
+ folder**, and asks again only for what changed. It also reads the public
18
+ **REST API**: summaries and risk indicators per region, province and
19
+ municipality, code lists, paged searches.
20
+
21
+ ```python
22
+ async with IdroGEO() as idrogeo:
23
+ folder = await idrogeo.fetch(opendata("frane_poly")) # ~570 MB the first time, a 304 after
24
+ ```
25
+
26
+ No account, no key. One dependency: `httpx`.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ pip install ispra-idrogeo
32
+ ```
33
+
34
+ ## Quick start
35
+
36
+ ```python
37
+ import asyncio
38
+
39
+ from ispra_idrogeo import IdroGEO, mosaic, opendata
40
+
41
+
42
+ async def main() -> None:
43
+ async with IdroGEO() as idrogeo:
44
+ # IFFI points (one per landslide), for the whole of Italy.
45
+ points = await idrogeo.fetch(opendata("frane_piff"))
46
+ # The same layer as GeoJSON, for one region.
47
+ puglia = await idrogeo.fetch(opendata("frane_piff", "puglia", "geojson"))
48
+ # The national flood hazard mosaic (~750 MB).
49
+ floods = await idrogeo.fetch(mosaic("idraulica"))
50
+ # API: IFFI counts for Puglia (ISTAT region 16).
51
+ summary = await idrogeo.summary("iffi", "regioni", 16)
52
+ print(points, puglia, floods, summary["nome"])
53
+
54
+
55
+ asyncio.run(main())
56
+ ```
57
+
58
+ `fetch` returns the folder the ZIP unpacks to (`<dir>/frane_piff_ispra_opendata/`);
59
+ `download` returns the file and whether this call changed it.
60
+
61
+ ## What there is
62
+
63
+ | Layer | What | Italy, zipped |
64
+ |---|---|---|
65
+ | `frane_piff` | IFFI landslide identification points, one per landslide | 38 MB |
66
+ | `frane_poly` | IFFI landslide polygons | 573 MB |
67
+ | `frane_line` | IFFI landslides too narrow for a polygon | 18 MB |
68
+ | `aree_poly` | areas of diffuse landslides | 236 MB |
69
+ | `dgpv_poly` | deep-seated gravitational slope deformations | 4 MB |
70
+ | `eventi` | dated landslide events (points) | 1 MB |
71
+ | `segnalazioni` | reports | small |
72
+ | `mosaic("pai_frane")` | PAI landslide hazard mosaic 2020-2021 | 1.2 GB |
73
+ | `mosaic("idraulica")` | flood hazard mosaic 2020 | 0.75 GB |
74
+ | `sensor_data()` | monitoring network readings, CSV (bzip2) | |
75
+
76
+ Every `opendata` layer comes as a shapefile (default) or GeoJSON
77
+ (`fmt="geojson"`), for Italy (`area="ispra"`, the default) or for one area:
78
+ the 19 region file names in `REGIONS` (by ISTAT code), and the provinces
79
+ that publish separately in `PROVINCES` (Bolzano, Trento, the Sicilian ones).
80
+ Coordinates are in **EPSG:32632** (WGS 84 / UTM 32N).
81
+
82
+ ## Where downloads are saved
83
+
84
+ In a folder that should survive restarts, because the national files weigh
85
+ hundreds of MB:
86
+
87
+ 1. the `directory` you pass;
88
+ 2. else `IDROGEO_DATA_DIR`;
89
+ 3. else `~/.cache/ispra-idrogeo` (or `$XDG_CACHE_HOME/ispra-idrogeo`).
90
+
91
+ Next to each file, `<file>.meta.json` keeps the `ETag` and `Last-Modified`
92
+ the server sent. ISPRA regenerates the inventory files **every day**, so
93
+ they become a conditional GET: an unchanged file costs one `304 Not
94
+ Modified`, a changed one is downloaded and unpacked again.
95
+
96
+ Downloads stream to `<file>.part` and are renamed when complete; unpacking
97
+ goes to `<folder>.part` and is swapped in whole. A reader never finds half a
98
+ file or half a shapefile, and a ZIP member that would land outside its
99
+ folder is refused.
100
+
101
+ ## The API
102
+
103
+ ```python
104
+ async with IdroGEO() as idrogeo:
105
+ italy = await idrogeo.summary("pir", "italia") # hazard and risk indicators
106
+ bari = await idrogeo.summary("pir", "comuni", 72006) # one municipality
107
+ regions = await idrogeo.summary("iffi", "regioni") # the list of a level
108
+ names = await idrogeo.dictionaries() # the code lists
109
+ causes = await idrogeo.dictionary("cause")
110
+ page = await idrogeo.search_landslides(limit=100, offset=0, select=["id_frana"])
111
+ ```
112
+
113
+ Reading needs no account. Search filters are a JSON object whose syntax is
114
+ in ISPRA's technical manual; an empty one matches everything, so page with
115
+ `limit` and `offset`. Some detail endpoints (`/frana/{id}`) answer 401
116
+ without a login, whatever the OpenAPI document says.
117
+
118
+ ## Errors and retries
119
+
120
+ - A dataset that does not exist (404), an API refusal, or a JSON that is
121
+ not what was asked for raise `IdrogeoError`.
122
+ - Network errors and 429/5xx are retried `retries` times (default 3) with
123
+ exponential backoff, then propagate as `httpx` exceptions. Pass
124
+ `retries=0` to wrap the calls in your own retry policy.
125
+ - Give it your `httpx.AsyncClient` and timeouts, proxies and pooling stay
126
+ yours.
127
+
128
+ ## The traps we already fell into
129
+
130
+ - **The old paths are gone.** `/opendata/iffi/<region>/iffi_<region>_<layer>.zip`
131
+ and `/opendata/iffi/dizionari/*.json` answer 404 in 2026. The files moved
132
+ to `/opendata/frane/`, the dictionaries to the API.
133
+ - **The WFS is not public.** `geoserver/idrogeo/frane/ows` answers 401, and
134
+ the global GeoServer lists no layer to an anonymous user. The downloads
135
+ and the API are the open way in.
136
+ - **Not every IdroGEO area is a region.** Trentino-Alto Adige publishes per
137
+ province (`bolzano`, `trento`), and Sicily also per province, besides its
138
+ regional file.
139
+
140
+ ## Data licence
141
+
142
+ Unless stated otherwise, ISPRA publishes its data under
143
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/legalcode)
144
+ ([note legali](https://www.isprambiente.gov.it/it/note-legali)): credit
145
+ *ISPRA — IdroGEO* when you publish anything derived from them. This library
146
+ only downloads them.
147
+
148
+ ## Development
149
+
150
+ ```bash
151
+ uv sync
152
+ make check
153
+ ```
154
+
155
+ Extracted from [Limen](https://github.com/agent-engineering-studio/limen),
156
+ a multi-hazard risk monitor for Italy.
157
+
158
+ ## License
159
+
160
+ [Apache-2.0](./LICENSE).
@@ -0,0 +1,102 @@
1
+ [project]
2
+ name = "ispra-idrogeo"
3
+ version = "0.1.0"
4
+ description = "Downloads and API client for ISPRA IdroGEO: IFFI landslide inventory, hazard mosaics and events, with a persistent conditional-GET cache"
5
+ readme = "README.md"
6
+ keywords = [
7
+ "ispra",
8
+ "idrogeo",
9
+ "iffi",
10
+ "landslide",
11
+ "frane",
12
+ "hazard",
13
+ "pai",
14
+ "flood",
15
+ "italy",
16
+ "gis",
17
+ ]
18
+ requires-python = ">=3.12"
19
+ license = "Apache-2.0"
20
+ license-files = ["LICENSE"]
21
+ classifiers = [
22
+ "Development Status :: 4 - Beta",
23
+ "Intended Audience :: Science/Research",
24
+ "Topic :: Scientific/Engineering :: GIS",
25
+ "Framework :: AsyncIO",
26
+ "Operating System :: OS Independent",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Typing :: Typed",
31
+ ]
32
+ dependencies = ["httpx>=0.27"]
33
+
34
+ [[project.authors]]
35
+ name = "Giuseppe Zileni"
36
+ email = "giuseppe.zileni@gmail.com"
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/agent-engineering-studio/ispra-idrogeo"
40
+ Issues = "https://github.com/agent-engineering-studio/ispra-idrogeo/issues"
41
+ Changelog = "https://github.com/agent-engineering-studio/ispra-idrogeo/blob/main/CHANGELOG.md"
42
+
43
+ [build-system]
44
+ requires = ["uv_build>=0.13.6,<0.14"]
45
+ build-backend = "uv_build"
46
+
47
+ [dependency-groups]
48
+ dev = [
49
+ "mypy>=1.13",
50
+ "pytest>=8.3",
51
+ "pytest-asyncio>=0.24",
52
+ "pytest-cov>=6.0",
53
+ "ruff>=0.8",
54
+ ]
55
+
56
+ [tool.ruff]
57
+ line-length = 100
58
+ target-version = "py312"
59
+
60
+ [tool.ruff.lint]
61
+ select = [
62
+ "E",
63
+ "F",
64
+ "W",
65
+ "I",
66
+ "N",
67
+ "UP",
68
+ "B",
69
+ "C4",
70
+ "SIM",
71
+ "ARG",
72
+ "PTH",
73
+ "RUF",
74
+ ]
75
+
76
+ [tool.ruff.lint.per-file-ignores]
77
+ "tests/**" = [
78
+ "ARG",
79
+ "B018",
80
+ ]
81
+
82
+ [tool.mypy]
83
+ strict = true
84
+ python_version = "3.12"
85
+ files = [
86
+ "src",
87
+ "tests",
88
+ ]
89
+ warn_unused_ignores = true
90
+ warn_redundant_casts = true
91
+
92
+ [tool.pytest.ini_options]
93
+ testpaths = ["tests"]
94
+ addopts = "--strict-markers"
95
+ asyncio_mode = "auto"
96
+
97
+ [tool.coverage.run]
98
+ source = ["ispra_idrogeo"]
99
+
100
+ [tool.coverage.report]
101
+ fail_under = 90
102
+ show_missing = true