Skip to content

Commit 8d7ea07

Browse files
committed
📝 Switch to httpx2
1 parent 1847301 commit 8d7ea07

4 files changed

Lines changed: 164 additions & 100 deletions

File tree

docs/data-processing/httpx/install-example.ipynb renamed to docs/data-processing/httpx/example.ipynb

Lines changed: 109 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"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",
358
"\n",
369
"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",
3710
"lassen wollt, so müsst ihr einfach nur `&format=json` weglassen\n",
@@ -49,10 +22,18 @@
4922
{
5023
"cell_type": "code",
5124
"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+
},
5334
"outputs": [],
5435
"source": [
55-
"import httpx\n",
36+
"import httpx2 as httpx\n",
5637
"\n",
5738
"\n",
5839
"search_url = \"https://nominatim.openstreetmap.org/search?\"\n",
@@ -66,7 +47,15 @@
6647
{
6748
"cell_type": "code",
6849
"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+
},
7059
"outputs": [
7160
{
7261
"data": {
@@ -87,27 +76,34 @@
8776
"cell_type": "code",
8877
"execution_count": 3,
8978
"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+
},
9086
"scrolled": true
9187
},
9288
"outputs": [
9389
{
9490
"data": {
9591
"text/plain": [
96-
"[{'place_id': 159000335,\n",
92+
"[{'place_id': 145504962,\n",
9793
" 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n",
9894
" 'osm_type': 'way',\n",
9995
" 'osm_id': 783052052,\n",
10096
" 'lat': '52.5219814',\n",
101-
" 'lon': '13.413635717448294',\n",
97+
" 'lon': '13.4136358',\n",
10298
" 'class': 'place',\n",
10399
" 'type': 'square',\n",
104100
" 'place_rank': 25,\n",
105-
" 'importance': 0.47149825263735834,\n",
101+
" 'importance': 0.5119277148736227,\n",
106102
" 'addresstype': 'square',\n",
107103
" 'name': 'Alexanderplatz',\n",
108-
" 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n",
104+
" 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n",
109105
" 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']},\n",
110-
" {'place_id': 159254539,\n",
106+
" {'place_id': 145397195,\n",
111107
" 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n",
112108
" 'osm_type': 'node',\n",
113109
" 'osm_id': 3908141014,\n",
@@ -116,39 +112,25 @@
116112
" 'class': 'railway',\n",
117113
" 'type': 'station',\n",
118114
" 'place_rank': 30,\n",
119-
" 'importance': 0.43609907778808027,\n",
115+
" 'importance': 0.4682518726909874,\n",
120116
" 'addresstype': 'railway',\n",
121117
" '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",
123119
" 'boundingbox': ['52.5165661', '52.5265661', '13.4062804', '13.4162804']},\n",
124-
" {'place_id': 159367604,\n",
120+
" {'place_id': 143700934,\n",
125121
" 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n",
126122
" 'osm_type': 'way',\n",
127123
" 'osm_id': 346206374,\n",
128-
" 'lat': '52.5216214',\n",
129-
" 'lon': '13.4131913',\n",
124+
" 'lat': '52.5216438',\n",
125+
" 'lon': '13.4131914',\n",
130126
" 'class': 'highway',\n",
131127
" 'type': 'pedestrian',\n",
132128
" 'place_rank': 26,\n",
133-
" 'importance': 0.10000999999999993,\n",
129+
" 'importance': 0.05342208819714653,\n",
134130
" 'addresstype': 'road',\n",
135131
" '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']}]"
152134
]
153135
},
154136
"execution_count": 3,
@@ -170,24 +152,32 @@
170152
{
171153
"cell_type": "code",
172154
"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+
},
174164
"outputs": [
175165
{
176166
"data": {
177167
"text/plain": [
178-
"[{'place_id': 159000335,\n",
168+
"[{'place_id': 144771482,\n",
179169
" 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n",
180170
" 'osm_type': 'way',\n",
181171
" 'osm_id': 783052052,\n",
182172
" 'lat': '52.5219814',\n",
183-
" 'lon': '13.413635717448294',\n",
173+
" 'lon': '13.4136358',\n",
184174
" 'class': 'place',\n",
185175
" 'type': 'square',\n",
186176
" 'place_rank': 25,\n",
187-
" 'importance': 0.47149825263735834,\n",
177+
" 'importance': 0.5119277148736227,\n",
188178
" 'addresstype': 'square',\n",
189179
" 'name': 'Alexanderplatz',\n",
190-
" 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n",
180+
" 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n",
191181
" 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']}]"
192182
]
193183
},
@@ -227,7 +217,15 @@
227217
{
228218
"cell_type": "code",
229219
"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+
},
231229
"outputs": [
232230
{
233231
"data": {
@@ -254,24 +252,32 @@
254252
{
255253
"cell_type": "code",
256254
"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+
},
258264
"outputs": [
259265
{
260266
"data": {
261267
"text/plain": [
262-
"[{'place_id': 159000335,\n",
268+
"[{'place_id': 144771482,\n",
263269
" 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n",
264270
" 'osm_type': 'way',\n",
265271
" 'osm_id': 783052052,\n",
266272
" 'lat': '52.5219814',\n",
267-
" 'lon': '13.413635717448294',\n",
273+
" 'lon': '13.4136358',\n",
268274
" 'class': 'place',\n",
269275
" 'type': 'square',\n",
270276
" 'place_rank': 25,\n",
271-
" 'importance': 0.47149825263735834,\n",
277+
" 'importance': 0.5119277148736227,\n",
272278
" 'addresstype': 'square',\n",
273279
" 'name': 'Alexanderplatz',\n",
274-
" 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n",
280+
" 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n",
275281
" 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']}]"
276282
]
277283
},
@@ -298,7 +304,15 @@
298304
{
299305
"cell_type": "code",
300306
"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+
},
302316
"outputs": [],
303317
"source": [
304318
"def nominatim_search(address, fmt=\"json\", limit=1, **kwargs):\n",
@@ -326,24 +340,32 @@
326340
{
327341
"cell_type": "code",
328342
"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+
},
330352
"outputs": [
331353
{
332354
"data": {
333355
"text/plain": [
334-
"[{'place_id': 159000335,\n",
356+
"[{'place_id': 144771482,\n",
335357
" 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright',\n",
336358
" 'osm_type': 'way',\n",
337359
" 'osm_id': 783052052,\n",
338360
" 'lat': '52.5219814',\n",
339-
" 'lon': '13.413635717448294',\n",
361+
" 'lon': '13.4136358',\n",
340362
" 'class': 'place',\n",
341363
" 'type': 'square',\n",
342364
" 'place_rank': 25,\n",
343-
" 'importance': 0.47149825263735834,\n",
365+
" 'importance': 0.5119277148736227,\n",
344366
" 'addresstype': 'square',\n",
345367
" 'name': 'Alexanderplatz',\n",
346-
" 'display_name': 'Alexanderplatz, Mitte, Berlin, 10178, Deutschland',\n",
368+
" 'display_name': 'Alexanderplatz, Spandauer Vorstadt, Mitte, Berlin, Deutschland',\n",
347369
" 'boundingbox': ['52.5201457', '52.5238113', '13.4103097', '13.4160801']}]"
348370
]
349371
},
@@ -368,7 +390,15 @@
368390
{
369391
"cell_type": "code",
370392
"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+
},
372402
"outputs": [],
373403
"source": [
374404
"from functools import lru_cache\n",
@@ -389,9 +419,9 @@
389419
],
390420
"metadata": {
391421
"kernelspec": {
392-
"display_name": "Python 3.13 Kernel",
422+
"display_name": "Python 3.14 Kernel",
393423
"language": "python",
394-
"name": "python313"
424+
"name": "python314"
395425
},
396426
"language_info": {
397427
"codemirror_mode": {
@@ -403,7 +433,7 @@
403433
"name": "python",
404434
"nbconvert_exporter": "python",
405435
"pygments_lexer": "ipython3",
406-
"version": "3.13.0"
436+
"version": "3.14.0"
407437
},
408438
"latex_envs": {
409439
"LaTeX_envs_menu_present": true,

‎docs/data-processing/httpx/index.rst‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@
22
..
33
.. SPDX-License-Identifier: BSD-3-Clause
44
5-
httpx
6-
=====
5+
HTTPX2
6+
======
77

8-
`httpx <https://httpx.readthedocs.io/en/latest/>`_ vereinfacht HTML-Anfragen
9-
gegenüber der Python-Standardbibliothek `urllib.request
10-
<https://docs.python.org/3/library/urllib.request.html>`_.
8+
`HTTPX2 <https://pydantic.dev/docs/httpx2/get-started/>`_ ist ein HTTP-Client,
9+
der sich nahtlos als Ersatz für `HTTPX
10+
<https://httpx.readthedocs.io/en/latest/>`_ verwenden lässt und HTML-Anfragen
11+
gegenüber der Python-Standardbibliothek :doc:`urllib.request
12+
<python:library/urllib.request>` vereinfacht.
13+
14+
Installation
15+
------------
16+
17+
HTTPX2 könnt ihr mit :ref:`uv` einfach installieren:
18+
19+
.. code-block:: console
20+
21+
$ uv add httpx2
1122
1223
.. toctree::
1324
:hidden:
1425
:titlesonly:
1526
:maxdepth: 0
1627

17-
install-example.ipynb
28+
example.ipynb
1829
module.ipynb

0 commit comments

Comments
 (0)