|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "# httpx-Installation und Beispielanwendung" |
8 | | - ] |
9 | | - }, |
10 | | - { |
11 | | - "cell_type": "markdown", |
12 | | - "metadata": {}, |
13 | | - "source": [ |
14 | | - "## Installation\n", |
15 | | - "\n", |
16 | | - "Für die Kommunikation mit solchen REST-APIs ist die [httpx](https://www.python-httpx.org)-Bibliothek hilfreich. Mit [Spack](https://www.python4data.science/de/latest/productive/envs/spack/index.html) könnt ihr httpx in eurem Kernel bereitstellen:\n", |
17 | | - "\n", |
18 | | - "``` bash\n", |
19 | | - "$ spack env activate python-311\n", |
20 | | - "$ spack install py-httpx\n", |
21 | | - "```\n", |
22 | | - "\n", |
23 | | - "Alternativ könnt ihr httpx auch mit anderen Paketmanagern installieren, z.B.\n", |
24 | | - "\n", |
25 | | - "``` bash\n", |
26 | | - "$ uv add httpx\n", |
27 | | - "```" |
28 | | - ] |
29 | | - }, |
30 | | - { |
31 | | - "cell_type": "markdown", |
32 | | - "metadata": {}, |
33 | | - "source": [ |
34 | | - "## Beispiel OSM Nominatim-API\n", |
| 7 | + "# Beispiel OSM Nominatim-API\n", |
35 | 8 | "\n", |
36 | 9 | "In diesem Beispiel holen wir unsere Daten von der [OpenStreetMap Nominatim-API](https://nominatim.org/release-docs/develop/api/Overview/). Diese ist erreichbar über die URL `https://nominatim.openstreetmap.org/search?`. Um z.B. Informationen über das Berlin Congress Center in Berlin im JSON-Format zu erhalten, sollte die URL `https://nominatim.openstreetmap.org/search.php?q=Alexanderplatz+Berlin&format=json` angegeben werden, und wenn ihr euch den entsprechenden Kartenausschnitt anzeigen\n", |
37 | 10 | "lassen wollt, so müsst ihr einfach nur `&format=json` weglassen\n", |
|
49 | 22 | { |
50 | 23 | "cell_type": "code", |
51 | 24 | "execution_count": 1, |
52 | | - "metadata": {}, |
| 25 | + "metadata": { |
| 26 | + "execution": { |
| 27 | + "iopub.execute_input": "2026-10-12T11:45:34.613925Z", |
| 28 | + "iopub.status.busy": "2026-10-12T11:45:34.613718Z", |
| 29 | + "iopub.status.idle": "2026-10-12T11:45:35.527021Z", |
| 30 | + "shell.execute_reply": "2026-10-12T11:45:35.525467Z", |
| 31 | + "shell.execute_reply.started": "2026-10-12T11:45:34.613904Z" |
| 32 | + } |
| 33 | + }, |
53 | 34 | "outputs": [], |
54 | 35 | "source": [ |
55 | | - "import httpx\n", |
| 36 | + "import httpx2 as httpx\n", |
56 | 37 | "\n", |
57 | 38 | "\n", |
58 | 39 | "search_url = \"https://nominatim.openstreetmap.org/search?\"\n", |
|
66 | 47 | { |
67 | 48 | "cell_type": "code", |
68 | 49 | "execution_count": 2, |
69 | | - "metadata": {}, |
| 50 | + "metadata": { |
| 51 | + "execution": { |
| 52 | + "iopub.execute_input": "2026-10-12T11:45:37.828998Z", |
| 53 | + "iopub.status.busy": "2026-10-12T11:45:37.828480Z", |
| 54 | + "iopub.status.idle": "2026-10-12T11:45:37.840524Z", |
| 55 | + "shell.execute_reply": "2026-10-12T11:45:37.838951Z", |
| 56 | + "shell.execute_reply.started": "2026-10-12T11:45:37.828949Z" |
| 57 | + } |
| 58 | + }, |
70 | 59 | "outputs": [ |
71 | 60 | { |
72 | 61 | "data": { |
|
87 | 76 | "cell_type": "code", |
88 | 77 | "execution_count": 3, |
89 | 78 | "metadata": { |
| 79 | + "execution": { |
| 80 | + "iopub.execute_input": "2026-10-12T11:45:39.728585Z", |
| 81 | + "iopub.status.busy": "2026-10-12T11:45:39.728237Z", |
| 82 | + "iopub.status.idle": "2026-10-12T11:45:39.734810Z", |
| 83 | + "shell.execute_reply": "2026-10-12T11:45:39.733773Z", |
| 84 | + "shell.execute_reply.started": "2026-10-12T11:45:39.728554Z" |
| 85 | + }, |
90 | 86 | "scrolled": true |
91 | 87 | }, |
92 | 88 | "outputs": [ |
93 | 89 | { |
94 | 90 | "data": { |
95 | 91 | "text/plain": [ |
96 | | - "[{'place_id': 159000335,\n", |
| 92 | + "[{'place_id': 145504962,\n", |
97 | 93 | " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
98 | 94 | " 'osm_type': 'way',\n", |
99 | 95 | " 'osm_id': 783052052,\n", |
100 | 96 | " 'lat': '52.5219814',\n", |
101 | | - " 'lon': '13.413635717448294',\n", |
| 97 | + " 'lon': '13.4136358',\n", |
102 | 98 | " 'class': 'place',\n", |
103 | 99 | " 'type': 'square',\n", |
104 | 100 | " 'place_rank': 25,\n", |
105 | | - " 'importance': 0.47149825263735834,\n", |
| 101 | + " 'importance': 0.5119277148736227,\n", |
106 | 102 | " 'addresstype': 'square',\n", |
107 | 103 | " 'name': 'Alexanderplatz',\n", |
108 | | - " 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n", |
| 104 | + " 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n", |
109 | 105 | " 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']},\n", |
110 | | - " {'place_id': 159254539,\n", |
| 106 | + " {'place_id': 145397195,\n", |
111 | 107 | " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
112 | 108 | " 'osm_type': 'node',\n", |
113 | 109 | " 'osm_id': 3908141014,\n", |
|
116 | 112 | " 'class': 'railway',\n", |
117 | 113 | " 'type': 'station',\n", |
118 | 114 | " 'place_rank': 30,\n", |
119 | | - " 'importance': 0.43609907778808027,\n", |
| 115 | + " 'importance': 0.4682518726909874,\n", |
120 | 116 | " 'addresstype': 'railway',\n", |
121 | 117 | " 'name': 'Alexanderplatz',\n", |
122 | | - " 'display_name': 'Alexanderplatz, Dircksenstraße, Mitte, Berlin, 10179, Deutschland',\n", |
| 118 | + " 'display_name': 'Alexanderplatz, 2, Dircksenstraße, Klosterviertel, Spandauer Vorstadt, Mitte, Berlin, 10179, Deutschland',\n", |
123 | 119 | " 'boundingbox': ['52.5165661', '52.5265661', '13.4062804', '13.4162804']},\n", |
124 | | - " {'place_id': 159367604,\n", |
| 120 | + " {'place_id': 143700934,\n", |
125 | 121 | " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
126 | 122 | " 'osm_type': 'way',\n", |
127 | 123 | " 'osm_id': 346206374,\n", |
128 | | - " 'lat': '52.5216214',\n", |
129 | | - " 'lon': '13.4131913',\n", |
| 124 | + " 'lat': '52.5216438',\n", |
| 125 | + " 'lon': '13.4131914',\n", |
130 | 126 | " 'class': 'highway',\n", |
131 | 127 | " 'type': 'pedestrian',\n", |
132 | 128 | " 'place_rank': 26,\n", |
133 | | - " 'importance': 0.10000999999999993,\n", |
| 129 | + " 'importance': 0.05342208819714653,\n", |
134 | 130 | " 'addresstype': 'road',\n", |
135 | 131 | " 'name': 'Alexanderplatz',\n", |
136 | | - " 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n", |
137 | | - " 'boundingbox': ['52.5216214', '52.5216661', '13.4131913', '13.4131914']},\n", |
138 | | - " {'place_id': 159038218,\n", |
139 | | - " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
140 | | - " 'osm_type': 'way',\n", |
141 | | - " 'osm_id': 301241483,\n", |
142 | | - " 'lat': '52.5227066',\n", |
143 | | - " 'lon': '13.415336',\n", |
144 | | - " 'class': 'highway',\n", |
145 | | - " 'type': 'primary',\n", |
146 | | - " 'place_rank': 26,\n", |
147 | | - " 'importance': 0.10000999999999993,\n", |
148 | | - " 'addresstype': 'road',\n", |
149 | | - " 'name': 'Alexanderstraße',\n", |
150 | | - " 'display_name': 'Alexanderstraße, Mitte, Berlin, 10178, Deutschland',\n", |
151 | | - " 'boundingbox': ['52.5226699', '52.5227698', '13.4152008', '13.4154146']}]" |
| 132 | + " 'display_name': 'Alexanderplatz, Klosterviertel, Spandauer Vorstadt, Mitte, Berlin, 10178, Deutschland',\n", |
| 133 | + " 'boundingbox': ['52.5216214', '52.5216661', '13.4131913', '13.4131914']}]" |
152 | 134 | ] |
153 | 135 | }, |
154 | 136 | "execution_count": 3, |
|
170 | 152 | { |
171 | 153 | "cell_type": "code", |
172 | 154 | "execution_count": 4, |
173 | | - "metadata": {}, |
| 155 | + "metadata": { |
| 156 | + "execution": { |
| 157 | + "iopub.execute_input": "2026-10-12T11:45:43.483396Z", |
| 158 | + "iopub.status.busy": "2026-10-12T11:45:43.482792Z", |
| 159 | + "iopub.status.idle": "2026-10-12T11:45:43.662874Z", |
| 160 | + "shell.execute_reply": "2026-10-12T11:45:43.662168Z", |
| 161 | + "shell.execute_reply.started": "2026-10-12T11:45:43.483345Z" |
| 162 | + } |
| 163 | + }, |
174 | 164 | "outputs": [ |
175 | 165 | { |
176 | 166 | "data": { |
177 | 167 | "text/plain": [ |
178 | | - "[{'place_id': 159000335,\n", |
| 168 | + "[{'place_id': 144771482,\n", |
179 | 169 | " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
180 | 170 | " 'osm_type': 'way',\n", |
181 | 171 | " 'osm_id': 783052052,\n", |
182 | 172 | " 'lat': '52.5219814',\n", |
183 | | - " 'lon': '13.413635717448294',\n", |
| 173 | + " 'lon': '13.4136358',\n", |
184 | 174 | " 'class': 'place',\n", |
185 | 175 | " 'type': 'square',\n", |
186 | 176 | " 'place_rank': 25,\n", |
187 | | - " 'importance': 0.47149825263735834,\n", |
| 177 | + " 'importance': 0.5119277148736227,\n", |
188 | 178 | " 'addresstype': 'square',\n", |
189 | 179 | " 'name': 'Alexanderplatz',\n", |
190 | | - " 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n", |
| 180 | + " 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n", |
191 | 181 | " 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']}]" |
192 | 182 | ] |
193 | 183 | }, |
|
227 | 217 | { |
228 | 218 | "cell_type": "code", |
229 | 219 | "execution_count": 5, |
230 | | - "metadata": {}, |
| 220 | + "metadata": { |
| 221 | + "execution": { |
| 222 | + "iopub.execute_input": "2026-10-12T11:45:52.621660Z", |
| 223 | + "iopub.status.busy": "2026-10-12T11:45:52.621398Z", |
| 224 | + "iopub.status.idle": "2026-10-12T11:45:52.625507Z", |
| 225 | + "shell.execute_reply": "2026-10-12T11:45:52.624584Z", |
| 226 | + "shell.execute_reply.started": "2026-10-12T11:45:52.621639Z" |
| 227 | + } |
| 228 | + }, |
231 | 229 | "outputs": [ |
232 | 230 | { |
233 | 231 | "data": { |
|
254 | 252 | { |
255 | 253 | "cell_type": "code", |
256 | 254 | "execution_count": 6, |
257 | | - "metadata": {}, |
| 255 | + "metadata": { |
| 256 | + "execution": { |
| 257 | + "iopub.execute_input": "2026-10-12T11:45:56.557581Z", |
| 258 | + "iopub.status.busy": "2026-10-12T11:45:56.557121Z", |
| 259 | + "iopub.status.idle": "2026-10-12T11:45:57.566387Z", |
| 260 | + "shell.execute_reply": "2026-10-12T11:45:57.565511Z", |
| 261 | + "shell.execute_reply.started": "2026-10-12T11:45:56.557545Z" |
| 262 | + } |
| 263 | + }, |
258 | 264 | "outputs": [ |
259 | 265 | { |
260 | 266 | "data": { |
261 | 267 | "text/plain": [ |
262 | | - "[{'place_id': 159000335,\n", |
| 268 | + "[{'place_id': 144771482,\n", |
263 | 269 | " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
264 | 270 | " 'osm_type': 'way',\n", |
265 | 271 | " 'osm_id': 783052052,\n", |
266 | 272 | " 'lat': '52.5219814',\n", |
267 | | - " 'lon': '13.413635717448294',\n", |
| 273 | + " 'lon': '13.4136358',\n", |
268 | 274 | " 'class': 'place',\n", |
269 | 275 | " 'type': 'square',\n", |
270 | 276 | " 'place_rank': 25,\n", |
271 | | - " 'importance': 0.47149825263735834,\n", |
| 277 | + " 'importance': 0.5119277148736227,\n", |
272 | 278 | " 'addresstype': 'square',\n", |
273 | 279 | " 'name': 'Alexanderplatz',\n", |
274 | | - " 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n", |
| 280 | + " 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n", |
275 | 281 | " 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']}]" |
276 | 282 | ] |
277 | 283 | }, |
|
298 | 304 | { |
299 | 305 | "cell_type": "code", |
300 | 306 | "execution_count": 7, |
301 | | - "metadata": {}, |
| 307 | + "metadata": { |
| 308 | + "execution": { |
| 309 | + "iopub.execute_input": "2026-10-12T11:46:00.837322Z", |
| 310 | + "iopub.status.busy": "2026-10-12T11:46:00.837060Z", |
| 311 | + "iopub.status.idle": "2026-10-12T11:46:00.842935Z", |
| 312 | + "shell.execute_reply": "2026-10-12T11:46:00.840641Z", |
| 313 | + "shell.execute_reply.started": "2026-10-12T11:46:00.837301Z" |
| 314 | + } |
| 315 | + }, |
302 | 316 | "outputs": [], |
303 | 317 | "source": [ |
304 | 318 | "def nominatim_search(address, fmt=\"json\", limit=1, **kwargs):\n", |
|
326 | 340 | { |
327 | 341 | "cell_type": "code", |
328 | 342 | "execution_count": 8, |
329 | | - "metadata": {}, |
| 343 | + "metadata": { |
| 344 | + "execution": { |
| 345 | + "iopub.execute_input": "2026-10-12T11:46:04.641500Z", |
| 346 | + "iopub.status.busy": "2026-10-12T11:46:04.641081Z", |
| 347 | + "iopub.status.idle": "2026-10-12T11:46:05.729206Z", |
| 348 | + "shell.execute_reply": "2026-10-12T11:46:05.727315Z", |
| 349 | + "shell.execute_reply.started": "2026-10-12T11:46:04.641458Z" |
| 350 | + } |
| 351 | + }, |
330 | 352 | "outputs": [ |
331 | 353 | { |
332 | 354 | "data": { |
333 | 355 | "text/plain": [ |
334 | | - "[{'place_id': 159000335,\n", |
| 356 | + "[{'place_id': 144771482,\n", |
335 | 357 | " 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n", |
336 | 358 | " 'osm_type': 'way',\n", |
337 | 359 | " 'osm_id': 783052052,\n", |
338 | 360 | " 'lat': '52.5219814',\n", |
339 | | - " 'lon': '13.413635717448294',\n", |
| 361 | + " 'lon': '13.4136358',\n", |
340 | 362 | " 'class': 'place',\n", |
341 | 363 | " 'type': 'square',\n", |
342 | 364 | " 'place_rank': 25,\n", |
343 | | - " 'importance': 0.47149825263735834,\n", |
| 365 | + " 'importance': 0.5119277148736227,\n", |
344 | 366 | " 'addresstype': 'square',\n", |
345 | 367 | " 'name': 'Alexanderplatz',\n", |
346 | | - " 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n", |
| 368 | + " 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n", |
347 | 369 | " 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']}]" |
348 | 370 | ] |
349 | 371 | }, |
|
368 | 390 | { |
369 | 391 | "cell_type": "code", |
370 | 392 | "execution_count": 9, |
371 | | - "metadata": {}, |
| 393 | + "metadata": { |
| 394 | + "execution": { |
| 395 | + "iopub.execute_input": "2026-10-12T11:46:10.214619Z", |
| 396 | + "iopub.status.busy": "2026-10-12T11:46:10.214114Z", |
| 397 | + "iopub.status.idle": "2026-10-12T11:46:10.219522Z", |
| 398 | + "shell.execute_reply": "2026-10-12T11:46:10.217326Z", |
| 399 | + "shell.execute_reply.started": "2026-10-12T11:46:10.214575Z" |
| 400 | + } |
| 401 | + }, |
372 | 402 | "outputs": [], |
373 | 403 | "source": [ |
374 | 404 | "from functools import lru_cache\n", |
|
389 | 419 | ], |
390 | 420 | "metadata": { |
391 | 421 | "kernelspec": { |
392 | | - "display_name": "Python 3.13 Kernel", |
| 422 | + "display_name": "Python 3.14 Kernel", |
393 | 423 | "language": "python", |
394 | | - "name": "python313" |
| 424 | + "name": "python314" |
395 | 425 | }, |
396 | 426 | "language_info": { |
397 | 427 | "codemirror_mode": { |
|
403 | 433 | "name": "python", |
404 | 434 | "nbconvert_exporter": "python", |
405 | 435 | "pygments_lexer": "ipython3", |
406 | | - "version": "3.13.0" |
| 436 | + "version": "3.14.0" |
407 | 437 | }, |
408 | 438 | "latex_envs": { |
409 | 439 | "LaTeX_envs_menu_present": true, |
|
0 commit comments