api_client
umwelt_apy.api_client
fetch_by_ids(ids, search_url=SEARCH_URL, output='Json', **kwargs)
Fetch multiple specific datasets by their unique identifiers.
Retrieves complete metadata for a list of dataset IDs. If a dataset is not found, logs an error and continues with the next ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list
|
List of unique dataset identifiers (strings) to fetch. |
required |
search_url
|
str
|
Address of the server. Defaults to "https://md.umwelt.info". |
SEARCH_URL
|
output
|
str
|
Format of the returned data. One of "Json", "Pandas", "Polars". Defaults to "Json". |
'Json'
|
**kwargs
|
Any
|
Additional parameters reserved for future extensions. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[Generator[dict, None, None], DataFrame, DataFrame]
|
Generator[dict, None, None] | pandas.DataFrame | polars.DataFrame: Depending on the output parameter: - "Json": Generator yielding dataset dicts one by one. - "Pandas": pandas DataFrame containing all datasets. - "Polars": polars DataFrame containing all datasets. Skips datasets that return HTTP errors (e.g., not found). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output is not one of the allowed formats. |
ImportError
|
If pandas or polars is not installed. |
Examples:
>>> ids = [
... "manual/camels_de",
... "manual/hochwasserzentralen"
... ]
>>> datasets = fetch_by_ids(ids)
>>> for dataset in datasets:
... print(dataset[`title`])
Note
Failed fetches (HTTPError) are logged but do not stop the iteration. Check logs for any missing datasets.
Source code in src/umwelt_apy/api_client.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
fetch_by_query(query='*', output='Json', search_url=SEARCH_URL, sampling_fraction=None, **kwargs)
fetch_by_query(query: str = '*', output: Literal['Json', 'Json Ranked'] = 'Json', search_url: str = SEARCH_URL, sampling_fraction: Optional[float] = None, **kwargs: Any) -> Generator[dict, None, None]
fetch_by_query(query: str = '*', output: Literal['Pandas'] = 'Pandas', search_url: str = SEARCH_URL, sampling_fraction: Optional[float] = None, exclude: Optional[List[str]] = None, columns: Optional[List[str]] = None, build_row: Optional[Callable] = None, filter_datasets: Optional[Callable] = None, dataset_list: Optional[List[str]] = None, flatten: bool = False, **kwargs: Any) -> pandas.DataFrame
fetch_by_query(query: str = '*', output: Literal['Polars'] = 'Polars', search_url: str = SEARCH_URL, sampling_fraction: Optional[float] = None, columns: Optional[List[str]] = None, build_row: Optional[Callable] = None, **kwargs: Any) -> polars.DataFrame
Searches the umwelt.info index by a search query and fetches the resulting datasets. Unlike fetch_by_url(), this allows to search for multiple entries (e.g. organisations). If you want to reproduce a given search from our web-ui, you should use fetch_by_url() instead. For information on how to build a query see https://md.umwelt.info/swagger-ui/#/search/text_search
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Search query string. Defaults to "*", which returns all datasets. |
'*'
|
output
|
str
|
Format of the returned data. One of "Json", "Json Ranked", "Pandas", "Polars". Defaults to "Json". |
'Json'
|
search_url
|
str
|
Address of the server. Defaults to "https://md.umwelt.info". |
SEARCH_URL
|
sampling_fraction
|
float
|
Fraction of results to return (0.0-1.0). If None, returns all results. Useful for testing with large datasets. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional search parameters passed to the underlying fetch function (e.g. filters, facets). |
{}
|
Returns:
| Type | Description |
|---|---|
Union[Generator[dict, None, None], DataFrame, DataFrame]
|
Union[Generator, pandas.DataFrame, polars.DataFrame]:
The return type depends on the |
Example
results = list(fetch_by_query(query="organisation:/Land/Bayern/LfU AND Luftqualität")) print(results[0][
title])
Source code in src/umwelt_apy/api_client.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
fetch_by_url(api_url, output='Json', sampling_fraction=None, **kwargs)
fetch_by_url(api_url: str, output: Literal['Json'] = 'Json', sampling_fraction: Optional[float] = None, **kwargs: Any) -> Generator[dict, None, None]
fetch_by_url(api_url: str, output: Literal['Pandas'] = 'Pandas', sampling_fraction: Optional[float] = None, exclude: Optional[List[str]] = None, columns: Optional[List[str]] = None, build_row: Optional[Callable] = None, filter_datasets: Optional[Callable] = None, flatten: bool = False, **kwargs: Any) -> pandas.DataFrame
fetch_by_url(api_url: str, output: Literal['Polars'] = 'Polars', sampling_fraction: Optional[float] = None, columns: Optional[List[str]] = None, build_row: Optional[Callable] = None, **kwargs: Any) -> polars.DataFrame
Fetch datasets using a complete API search URL.
Unlike fetch_by_query(), this function accepts a fully-formed URL including all query parameters. You can get this url by using our web-ui.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_url
|
str
|
Complete URL with query parameters. Example: https://md.umwelt.info/search/all?query=Borganisation%3A%2FBund+%2Btype%3A%22%2FChemische+Verbindung%22&language=de |
required |
output
|
str
|
Format of the returned data. One of "Json", "Pandas", "Polars". Defaults to "Json". |
'Json'
|
sampling_fraction
|
float
|
Fraction of results to return (0.0-1.0). If None, returns all results. Useful for testing with large datasets. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional search parameters passed to the underlying fetch function. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[Generator[dict, None, None], DataFrame, DataFrame]
|
Union[Generator, pandas.DataFrame, polars.DataFrame]:
The return type depends on the |
Examples:
>>> url = 'https://md.umwelt.info/search/all?query=%2B%28wasser%29+%2Borganisation%3A%2FLand&language=de'
>>> for dataset in fetch_by_url(url):
... print(dataset[`title`])
Source code in src/umwelt_apy/api_client.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
fetch_facet_values(name='type', url=SEARCH_URL)
Fetches all possible values for a given facet from the umwelt.info API.
Facets are hierarchical groupings used to filter search results. This function queries the /facet/{name} endpoint and returns all available values for the requested facet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the facet to retrieve. Must be one of: - "type" → dataset types (e.g. Taxon, Text, Image) - "topic" → thematic tags (e.g. /Boden, /Wasser) - "organisation" → data providers (e.g. /Bund/UBA, /Land/Bayern) - "license" → licenses (e.g. /offen, /geschlossen) - "language" → languages (e.g. /Deutsch, /Englisch) - "resource_type" → resource types (e.g. /Datei, /Dienst) Defaults to "type". |
'type'
|
url
|
str
|
Base URL of the API endpoint. Defaults to SEARCH_URL. |
SEARCH_URL
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
List of facet values as returned by the API. Each entry contains a path (str) and a dataset count (int). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not one of the valid facet names. |
HTTPError
|
If the API returns an error. |
Examples:
Fetch all resource types (analogue to R: fetch_facet_values("resource_type")):
>>> resource_types = fetch_facet_values("resource_type")
>>> for value in resource_types[:5]:
... print(value)
Fetch all organisations: This can be e.g. useful if you want to restrict the results to certain organisations when building your own query, so you know which organisations are available.
>>> organisations = fetch_facet_values("organisation")
>>> print(organisations[:3])
Invalid Name gives ValueError:
>>> fetch_facet_values("invalid")
ValueError: Invalid Facette Name: 'invalid'.
Allowed Values: ['type', 'topic', 'organisation', 'license', 'language', 'resource_type']
Source code in src/umwelt_apy/api_client.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |