mloda-plugin-govdata 0.2.3__tar.gz → 0.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.
- mloda_plugin_govdata-0.3.0/NOTICE.md +7 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/PKG-INFO +65 -14
- mloda_plugin_govdata-0.3.0/README.md +163 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/conftest.py +10 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/__init__.py +50 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/api.py +293 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/auth.py +156 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/cache.py +261 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/envelope.py +336 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/errors.py +62 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/hosts.py +62 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/parse.py +198 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/period.py +106 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core/redact.py +69 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/locator.py +173 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/reader.py +68 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/__init__.py +31 -2
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/govdata/bundeswahlleiterin.py +91 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/govdata/core/cache.py +155 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/core/client.py +46 -7
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/core/locator.py +18 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/govdata/core/provenance.py +41 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/population.py +1 -1
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/govdata/reader.py +150 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/uba.py +90 -11
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/__init__.py +8 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/base.py +111 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/__init__.py +1 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/crosswalk.py +61 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/keys.py +78 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/land_codes.py +79 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/nuts.py +195 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/rebase.py +463 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/reference/__init__.py +1 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/reference/bbsr.py +153 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/reference/download.py +42 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/reference/eurostat.py +115 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/reference/gv_isys.py +110 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/core/reference/sources.py +72 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/nuts.py +111 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/period.py +65 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/harmonization/rebase.py +241 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/land_population_per_voter.py +75 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/recipes/__init__.py +24 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/recipes/credential_scan.py +133 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/recipes/frames.py +46 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/recipes/load.py +75 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/recipes/model.py +172 -0
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/recipes/write.py +185 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata.egg-info/PKG-INFO +65 -14
- mloda_plugin_govdata-0.3.0/mloda_plugin_govdata.egg-info/SOURCES.txt +67 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata.egg-info/requires.txt +6 -1
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/pyproject.toml +23 -7
- mloda_plugin_govdata-0.3.0/tests/test_capture_genesis_fixtures.py +149 -0
- mloda_plugin_govdata-0.3.0/tests/test_demo_definition.py +90 -0
- mloda_plugin_govdata-0.3.0/tests/test_land_join.py +101 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/tests/test_mloda_imports.py +11 -0
- mloda_plugin_govdata-0.3.0/tests/test_packaging.py +46 -0
- mloda_plugin_govdata-0.2.3/README.md +0 -116
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/bundeswahlleiterin.py +0 -48
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/core/cache.py +0 -114
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/reader.py +0 -123
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/conftest.py +0 -8
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_cache.py +0 -62
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_client.py +0 -49
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_discovery.py +0 -157
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_parse.py +0 -183
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_parse_hypothesis.py +0 -38
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_reader.py +0 -327
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests/test_uba.py +0 -193
- mloda_plugin_govdata-0.2.3/mloda_plugin_govdata.egg-info/SOURCES.txt +0 -33
- mloda_plugin_govdata-0.2.3/tests/test_demo_definition.py +0 -19
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/LICENSE +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3/mloda_plugin_govdata/feature_groups/govdata/tests → mloda_plugin_govdata-0.3.0/mloda_plugin_govdata/feature_groups/destatis/core}/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/core/__init__.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/core/discovery.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/core/parse.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata/feature_groups/govdata/feature.py +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata.egg-info/dependency_links.txt +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/mloda_plugin_govdata.egg-info/top_level.txt +0 -0
- {mloda_plugin_govdata-0.2.3 → mloda_plugin_govdata-0.3.0}/setup.cfg +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026- Tom Kaltofen <tomkaltofen@mloda.ai>
|
|
2
|
+
|
|
3
|
+
This project, "mloda-plugin-govdata," is licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at:
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mloda-plugin-govdata
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: mloda plugin providing connectors and
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: mloda plugin providing connectors, harmonization and recipes for German government data (GovData.de CKAN API, Destatis GENESIS webservice).
|
|
5
5
|
Author-email: Tom Kaltofen <tomkaltofen@mloda.ai>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/mloda-ai/mloda-plugin-govdata
|
|
@@ -12,9 +12,12 @@ Project-URL: Prototype Fund, https://www.prototypefund.de/projects/mloda-plugin-
|
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
|
-
|
|
15
|
+
License-File: NOTICE.md
|
|
16
|
+
Requires-Dist: mloda<0.14.0,>=0.13.0
|
|
16
17
|
Requires-Dist: mloda-testing>=0.3.1
|
|
18
|
+
Requires-Dist: filelock>=3.12
|
|
17
19
|
Requires-Dist: httpx>=0.27
|
|
20
|
+
Requires-Dist: openpyxl>=3.1
|
|
18
21
|
Requires-Dist: pandas>=2.0
|
|
19
22
|
Requires-Dist: pyarrow>=17.0
|
|
20
23
|
Requires-Dist: pydantic>=2.0
|
|
@@ -32,6 +35,7 @@ Requires-Dist: bandit; extra == "dev"
|
|
|
32
35
|
Requires-Dist: hypothesis; extra == "dev"
|
|
33
36
|
Requires-Dist: respx; extra == "dev"
|
|
34
37
|
Requires-Dist: pandas-stubs; extra == "dev"
|
|
38
|
+
Requires-Dist: tomli; python_version < "3.11" and extra == "dev"
|
|
35
39
|
Dynamic: license-file
|
|
36
40
|
|
|
37
41
|
[](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/LICENSE)
|
|
@@ -44,14 +48,16 @@ Dynamic: license-file
|
|
|
44
48
|
|
|
45
49
|
Connectors for German open government data, built on [mloda](https://github.com/mloda-ai/mloda). Request the columns you want as mloda features; the plugin handles CKAN discovery, download with caching and retries, and parsing (German CSV or publisher JSON) into a typed Arrow table.
|
|
46
50
|
|
|
47
|
-
Three example datasets cover
|
|
51
|
+
Three example datasets cover population (GovData CSV), elections (Bundeswahlleiterin `kerg.csv`), and environment (UBA Air Data JSON); the Destatis connector adds GENESIS tables, with harmonization features and recipe files on top.
|
|
48
52
|
|
|
49
53
|
## Status
|
|
50
54
|
|
|
51
|
-
Young but working.
|
|
55
|
+
Young but working. The three example readers and the Destatis connector run end to end, with paginated dataset search, cached downloads with retries, and unit plus property-based tests behind them. Every reader is a thin subclass of `BaseGovDataReader` that overrides the parse step (and the fetch step for a source with its own locator type); new datasets follow the same path (see [docs/adding-a-reader.md](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/adding-a-reader.md)). How the packages fit together, and where to start for a change: [docs/architecture.md](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/architecture.md). Development happens in a 6-month Prototype Fund stage (June to November 2026), so the API may still shift between releases.
|
|
52
56
|
|
|
53
57
|
## Usage
|
|
54
58
|
|
|
59
|
+
### GovData readers
|
|
60
|
+
|
|
55
61
|
Read the Stuttgart population dataset (via GovData) as a typed PyArrow table:
|
|
56
62
|
|
|
57
63
|
```python
|
|
@@ -70,7 +76,7 @@ table = result[0] # pyarrow.Table with the requested columns
|
|
|
70
76
|
result.plan # resolved execution steps: which FeatureGroup ran on which framework
|
|
71
77
|
```
|
|
72
78
|
|
|
73
|
-
The options key is the reader class or its class-name string; both select the same reader. The option value is a GovData dataset slug or a direct distribution URL. The license is read from the CKAN distribution metadata. Set `BaseGovDataReader.cache_dir` to control where downloads are cached. For any other GovData CSV dataset, `GovDataReader` works out of the box and reads every column as a string; subclass it and set `schema` for typed columns.
|
|
79
|
+
The options key is the reader class or its class-name string; both select the same reader. The option value is a GovData dataset slug or a direct distribution URL. The license is read from the CKAN distribution metadata. Set `BaseGovDataReader.cache_dir` to control where downloads are cached (harmonized features below use a separate `HarmonizationFeature.cache_dir`). For any other GovData CSV dataset, `GovDataReader` works out of the box and reads every column as a string; subclass it and set `schema` for typed columns.
|
|
74
80
|
|
|
75
81
|
Don't know the slug yet? Search GovData with the paginated CKAN `package_search` API:
|
|
76
82
|
|
|
@@ -90,7 +96,7 @@ Got a slug but not the column names? `peek` lists what you can request as featur
|
|
|
90
96
|
StuttgartPopulationReader.peek(slug) # {"Stichtag": "date32[day]", "Stadtbezirk": "string", ...}
|
|
91
97
|
```
|
|
92
98
|
|
|
93
|
-
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(
|
|
99
|
+
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(uba_measures_url(...))`) and downloads through the cache, so the actual feature request reuses the file. `peek` takes a raw URL, bypassing the `READER_OPTIONS` validation below. A typo in a feature name fails with the available columns and a close-match suggestion instead of a raw KeyError.
|
|
94
100
|
|
|
95
101
|
The elections reader handles a direct CSV URL whose file has a multi-row merged header (Bundeswahlleiterin `kerg.csv`):
|
|
96
102
|
|
|
@@ -104,16 +110,30 @@ result = mloda.run_all(
|
|
|
104
110
|
)
|
|
105
111
|
```
|
|
106
112
|
|
|
107
|
-
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp.
|
|
113
|
+
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp. Query parameters are per-feature options, not a pre-built URL (here: hourly ozone at station 143); a bad value is rejected during feature resolution, before any network call:
|
|
108
114
|
|
|
109
115
|
```python
|
|
110
|
-
from mloda_plugin_govdata.feature_groups.govdata import
|
|
116
|
+
from mloda_plugin_govdata.feature_groups.govdata import (
|
|
117
|
+
OPTION_UBA_COMPONENT,
|
|
118
|
+
OPTION_UBA_DATE_FROM,
|
|
119
|
+
OPTION_UBA_DATE_TO,
|
|
120
|
+
OPTION_UBA_SCOPE,
|
|
121
|
+
OPTION_UBA_STATION,
|
|
122
|
+
UbaAirReader,
|
|
123
|
+
)
|
|
111
124
|
|
|
112
|
-
|
|
125
|
+
uba_options = {
|
|
126
|
+
UbaAirReader: True,
|
|
127
|
+
OPTION_UBA_STATION: 143,
|
|
128
|
+
OPTION_UBA_COMPONENT: 3,
|
|
129
|
+
OPTION_UBA_SCOPE: 2,
|
|
130
|
+
OPTION_UBA_DATE_FROM: "2025-01-01",
|
|
131
|
+
OPTION_UBA_DATE_TO: "2025-01-01",
|
|
132
|
+
}
|
|
113
133
|
result = mloda.run_all(
|
|
114
134
|
[
|
|
115
|
-
Feature("date_start", options=
|
|
116
|
-
Feature("value", options=
|
|
135
|
+
Feature("date_start", options=uba_options),
|
|
136
|
+
Feature("value", options=uba_options),
|
|
117
137
|
],
|
|
118
138
|
compute_frameworks=["PyArrowTable"],
|
|
119
139
|
)
|
|
@@ -121,9 +141,40 @@ result = mloda.run_all(
|
|
|
121
141
|
|
|
122
142
|
Columns are `station_id`, `date_start`, `component_id`, `scope_id`, `value`, `date_end`, and `index` (the air-quality index). Component and scope ids come from the UBA `components` and `scopes` endpoints.
|
|
123
143
|
|
|
144
|
+
### Destatis
|
|
145
|
+
|
|
146
|
+
The Destatis connector reads a GENESIS table (Statistisches Bundesamt or a Regionalstatistik installation) by table code, needs a free registration (`GENESIS_TOKEN` or `GENESIS_USER` / `GENESIS_PASSWORD`; see [docs/credentials.md](docs/credentials.md)), and parses the ffcsv reply:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from mloda_plugin_govdata.feature_groups.destatis import DestatisReader
|
|
150
|
+
|
|
151
|
+
result = mloda.run_all(
|
|
152
|
+
[Feature("value", options={DestatisReader: "12411-0010"})], # population by Land
|
|
153
|
+
compute_frameworks=["PyArrowTable"],
|
|
154
|
+
)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The option value is a bare table code (the server's default years), a `DestatisLocator`, or its dict form; the latter two narrow the selection by region, years, and classifying variables, and the dict form round-trips through a recipe file. See [docs/destatis-options.md](docs/destatis-options.md) for the full parameter table. `peek` lists the ffcsv columns the same way as the other readers.
|
|
158
|
+
|
|
159
|
+
### Harmonization
|
|
160
|
+
|
|
161
|
+
Harmonized features chain an operation onto a reader column (`<column>__<operation>`): `value__rebased` re-bases a Kreis series onto a later Gebietsstand with the BBSR keys, `1_variable_attribute_code__nuts2024` adds NUTS codes to Kreis and Gemeinde keys, and `time__year_period` types the period. A feature with several output columns returns them as `<name>~<part>`, mloda's multi-output convention: `value__rebased~key`, `value__rebased~flag`, and so on. `value__rebased` and `__nuts2024` read their reference tables offline from `HarmonizationFeature.cache_dir`, so fetch them once first; see [docs/harmonization.md](docs/harmonization.md) for the example, the options, and the one-time fetch.
|
|
162
|
+
|
|
163
|
+
### Recipes
|
|
164
|
+
|
|
165
|
+
A recipe file bundles the features, joins, and provenance of one run as JSON; `load_recipe` returns what `mloda.run_all` needs plus the compliance block (license, attribution, payload sha256, credential env names). Recipes ship under `recipes/` in the repository, not in the published package: the Land table, the re-based Kreis series, a rate with its denominator, the Land-level join, and the three example datasets above. See [docs/recipes.md](docs/recipes.md).
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from mloda_plugin_govdata.recipes import load_recipe
|
|
169
|
+
|
|
170
|
+
recipe = load_recipe("recipes/land_population.json")
|
|
171
|
+
result = mloda.run_all(recipe.features, compute_frameworks=["PyArrowTable"], links=set(recipe.links))
|
|
172
|
+
recipe.compliance.sources[0].attribution # what to print next to the result
|
|
173
|
+
```
|
|
174
|
+
|
|
124
175
|
## Demo
|
|
125
176
|
|
|
126
|
-
An interactive [marimo](https://marimo.io) notebook walks through dataset discovery
|
|
177
|
+
An interactive [marimo](https://marimo.io) notebook walks through dataset discovery, all three example datasets, a Destatis table, a recipe joining two sources (population per eligible voter by Land), and a Kreis series re-based across a merger. The notebook lives in the repository (not in the published package), so run it from a source checkout:
|
|
127
178
|
|
|
128
179
|
```bash
|
|
129
180
|
git clone https://github.com/mloda-ai/mloda-plugin-govdata.git
|
|
@@ -132,7 +183,7 @@ uv sync --all-extras
|
|
|
132
183
|
uv run marimo edit demos/govdata_demo.py
|
|
133
184
|
```
|
|
134
185
|
|
|
135
|
-
The notebook hits the live GovData, Bundeswahlleiterin, and
|
|
186
|
+
The notebook hits the live GovData, Bundeswahlleiterin, UBA, and GENESIS-Online endpoints and fetches the BBSR key file; downloads are cached locally after the first run. The Destatis chapters need GENESIS-Online credentials in the environment (`GENESIS_TOKEN`, or `GENESIS_USER` and `GENESIS_PASSWORD`; see [docs/credentials.md](docs/credentials.md)) and skip themselves without them.
|
|
136
187
|
|
|
137
188
|
## Related Repositories
|
|
138
189
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
[](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/LICENSE)
|
|
2
|
+
[](https://github.com/mloda-ai/mloda)
|
|
3
|
+
[](https://www.python.org/)
|
|
4
|
+
[](https://github.com/mloda-ai/mloda-plugin-govdata/actions/workflows/test.yml?query=branch%3Amain)
|
|
5
|
+
[](https://prototypefund.de)
|
|
6
|
+
|
|
7
|
+
# mloda-plugin-govdata
|
|
8
|
+
|
|
9
|
+
Connectors for German open government data, built on [mloda](https://github.com/mloda-ai/mloda). Request the columns you want as mloda features; the plugin handles CKAN discovery, download with caching and retries, and parsing (German CSV or publisher JSON) into a typed Arrow table.
|
|
10
|
+
|
|
11
|
+
Three example datasets cover population (GovData CSV), elections (Bundeswahlleiterin `kerg.csv`), and environment (UBA Air Data JSON); the Destatis connector adds GENESIS tables, with harmonization features and recipe files on top.
|
|
12
|
+
|
|
13
|
+
## Status
|
|
14
|
+
|
|
15
|
+
Young but working. The three example readers and the Destatis connector run end to end, with paginated dataset search, cached downloads with retries, and unit plus property-based tests behind them. Every reader is a thin subclass of `BaseGovDataReader` that overrides the parse step (and the fetch step for a source with its own locator type); new datasets follow the same path (see [docs/adding-a-reader.md](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/adding-a-reader.md)). How the packages fit together, and where to start for a change: [docs/architecture.md](https://github.com/mloda-ai/mloda-plugin-govdata/blob/main/docs/architecture.md). Development happens in a 6-month Prototype Fund stage (June to November 2026), so the API may still shift between releases.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### GovData readers
|
|
20
|
+
|
|
21
|
+
Read the Stuttgart population dataset (via GovData) as a typed PyArrow table:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from mloda.user import Feature, mloda
|
|
25
|
+
from mloda_plugin_govdata.feature_groups.govdata import StuttgartPopulationReader
|
|
26
|
+
|
|
27
|
+
slug = "einwohner-nach-altersgruppen-und-stadtbezirken"
|
|
28
|
+
result = mloda.run_all(
|
|
29
|
+
[
|
|
30
|
+
Feature("Einwohner", options={StuttgartPopulationReader: slug}),
|
|
31
|
+
Feature("Stadtbezirk", options={StuttgartPopulationReader: slug}),
|
|
32
|
+
],
|
|
33
|
+
compute_frameworks=["PyArrowTable"],
|
|
34
|
+
)
|
|
35
|
+
table = result[0] # pyarrow.Table with the requested columns
|
|
36
|
+
result.plan # resolved execution steps: which FeatureGroup ran on which framework
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The options key is the reader class or its class-name string; both select the same reader. The option value is a GovData dataset slug or a direct distribution URL. The license is read from the CKAN distribution metadata. Set `BaseGovDataReader.cache_dir` to control where downloads are cached (harmonized features below use a separate `HarmonizationFeature.cache_dir`). For any other GovData CSV dataset, `GovDataReader` works out of the box and reads every column as a string; subclass it and set `schema` for typed columns.
|
|
40
|
+
|
|
41
|
+
Don't know the slug yet? Search GovData with the paginated CKAN `package_search` API:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from mloda_plugin_govdata.feature_groups.govdata import build_client, search_datasets
|
|
45
|
+
|
|
46
|
+
with build_client() as client:
|
|
47
|
+
for dataset in search_datasets(client, "einwohner stuttgart", max_results=10):
|
|
48
|
+
print(dataset.name, "|", dataset.title)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`search_datasets` walks the result pages lazily (`page_size` per request) and stops at `max_results` or the end of the result set.
|
|
52
|
+
|
|
53
|
+
Got a slug but not the column names? `peek` lists what you can request as features:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
StuttgartPopulationReader.peek(slug) # {"Stichtag": "date32[day]", "Stadtbezirk": "string", ...}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
It works on every reader (`BundeswahlleiterinReader.peek(kerg)`, `UbaAirReader.peek(uba_measures_url(...))`) and downloads through the cache, so the actual feature request reuses the file. `peek` takes a raw URL, bypassing the `READER_OPTIONS` validation below. A typo in a feature name fails with the available columns and a close-match suggestion instead of a raw KeyError.
|
|
60
|
+
|
|
61
|
+
The elections reader handles a direct CSV URL whose file has a multi-row merged header (Bundeswahlleiterin `kerg.csv`):
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from mloda_plugin_govdata.feature_groups.govdata import BundeswahlleiterinReader
|
|
65
|
+
|
|
66
|
+
kerg = "https://www.bundeswahlleiterin.de/bundestagswahlen/2025/ergebnisse/opendata/btw25/csv/kerg.csv"
|
|
67
|
+
result = mloda.run_all(
|
|
68
|
+
[Feature("Gebiet", options={BundeswahlleiterinReader: kerg})],
|
|
69
|
+
compute_frameworks=["PyArrowTable"],
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The environment reader fetches the Umweltbundesamt (UBA) Air Data v4 `measures` endpoint (REST JSON) and flattens it to one typed row per station and timestamp. Query parameters are per-feature options, not a pre-built URL (here: hourly ozone at station 143); a bad value is rejected during feature resolution, before any network call:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from mloda_plugin_govdata.feature_groups.govdata import (
|
|
77
|
+
OPTION_UBA_COMPONENT,
|
|
78
|
+
OPTION_UBA_DATE_FROM,
|
|
79
|
+
OPTION_UBA_DATE_TO,
|
|
80
|
+
OPTION_UBA_SCOPE,
|
|
81
|
+
OPTION_UBA_STATION,
|
|
82
|
+
UbaAirReader,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
uba_options = {
|
|
86
|
+
UbaAirReader: True,
|
|
87
|
+
OPTION_UBA_STATION: 143,
|
|
88
|
+
OPTION_UBA_COMPONENT: 3,
|
|
89
|
+
OPTION_UBA_SCOPE: 2,
|
|
90
|
+
OPTION_UBA_DATE_FROM: "2025-01-01",
|
|
91
|
+
OPTION_UBA_DATE_TO: "2025-01-01",
|
|
92
|
+
}
|
|
93
|
+
result = mloda.run_all(
|
|
94
|
+
[
|
|
95
|
+
Feature("date_start", options=uba_options),
|
|
96
|
+
Feature("value", options=uba_options),
|
|
97
|
+
],
|
|
98
|
+
compute_frameworks=["PyArrowTable"],
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Columns are `station_id`, `date_start`, `component_id`, `scope_id`, `value`, `date_end`, and `index` (the air-quality index). Component and scope ids come from the UBA `components` and `scopes` endpoints.
|
|
103
|
+
|
|
104
|
+
### Destatis
|
|
105
|
+
|
|
106
|
+
The Destatis connector reads a GENESIS table (Statistisches Bundesamt or a Regionalstatistik installation) by table code, needs a free registration (`GENESIS_TOKEN` or `GENESIS_USER` / `GENESIS_PASSWORD`; see [docs/credentials.md](docs/credentials.md)), and parses the ffcsv reply:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from mloda_plugin_govdata.feature_groups.destatis import DestatisReader
|
|
110
|
+
|
|
111
|
+
result = mloda.run_all(
|
|
112
|
+
[Feature("value", options={DestatisReader: "12411-0010"})], # population by Land
|
|
113
|
+
compute_frameworks=["PyArrowTable"],
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The option value is a bare table code (the server's default years), a `DestatisLocator`, or its dict form; the latter two narrow the selection by region, years, and classifying variables, and the dict form round-trips through a recipe file. See [docs/destatis-options.md](docs/destatis-options.md) for the full parameter table. `peek` lists the ffcsv columns the same way as the other readers.
|
|
118
|
+
|
|
119
|
+
### Harmonization
|
|
120
|
+
|
|
121
|
+
Harmonized features chain an operation onto a reader column (`<column>__<operation>`): `value__rebased` re-bases a Kreis series onto a later Gebietsstand with the BBSR keys, `1_variable_attribute_code__nuts2024` adds NUTS codes to Kreis and Gemeinde keys, and `time__year_period` types the period. A feature with several output columns returns them as `<name>~<part>`, mloda's multi-output convention: `value__rebased~key`, `value__rebased~flag`, and so on. `value__rebased` and `__nuts2024` read their reference tables offline from `HarmonizationFeature.cache_dir`, so fetch them once first; see [docs/harmonization.md](docs/harmonization.md) for the example, the options, and the one-time fetch.
|
|
122
|
+
|
|
123
|
+
### Recipes
|
|
124
|
+
|
|
125
|
+
A recipe file bundles the features, joins, and provenance of one run as JSON; `load_recipe` returns what `mloda.run_all` needs plus the compliance block (license, attribution, payload sha256, credential env names). Recipes ship under `recipes/` in the repository, not in the published package: the Land table, the re-based Kreis series, a rate with its denominator, the Land-level join, and the three example datasets above. See [docs/recipes.md](docs/recipes.md).
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from mloda_plugin_govdata.recipes import load_recipe
|
|
129
|
+
|
|
130
|
+
recipe = load_recipe("recipes/land_population.json")
|
|
131
|
+
result = mloda.run_all(recipe.features, compute_frameworks=["PyArrowTable"], links=set(recipe.links))
|
|
132
|
+
recipe.compliance.sources[0].attribution # what to print next to the result
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Demo
|
|
136
|
+
|
|
137
|
+
An interactive [marimo](https://marimo.io) notebook walks through dataset discovery, all three example datasets, a Destatis table, a recipe joining two sources (population per eligible voter by Land), and a Kreis series re-based across a merger. The notebook lives in the repository (not in the published package), so run it from a source checkout:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git clone https://github.com/mloda-ai/mloda-plugin-govdata.git
|
|
141
|
+
cd mloda-plugin-govdata
|
|
142
|
+
uv sync --all-extras
|
|
143
|
+
uv run marimo edit demos/govdata_demo.py
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The notebook hits the live GovData, Bundeswahlleiterin, UBA, and GENESIS-Online endpoints and fetches the BBSR key file; downloads are cached locally after the first run. The Destatis chapters need GENESIS-Online credentials in the environment (`GENESIS_TOKEN`, or `GENESIS_USER` and `GENESIS_PASSWORD`; see [docs/credentials.md](docs/credentials.md)) and skip themselves without them.
|
|
147
|
+
|
|
148
|
+
## Related Repositories
|
|
149
|
+
|
|
150
|
+
- **[mloda](https://github.com/mloda-ai/mloda)**: the core library this plugin builds on. You declare which features you need; mloda resolves how to compute them.
|
|
151
|
+
|
|
152
|
+
- **[mloda-registry](https://github.com/mloda-ai/mloda-registry)**: plugin registry and development guides for the mloda ecosystem.
|
|
153
|
+
|
|
154
|
+
## Funding
|
|
155
|
+
|
|
156
|
+
Developed as part of the [Prototype Fund](https://prototypefund.de) (Round 2 / Jahrgang 02), funded by the German Federal Ministry of Research, Technology and Space (BMFTR) and supported by the [Open Knowledge Foundation Deutschland](https://okfn.de). Funding code (Förderkennzeichen): **16IS26S11**. Stage 1 funding period: 6 months from June 2026.
|
|
157
|
+
|
|
158
|
+
<p>
|
|
159
|
+
<img src="https://raw.githubusercontent.com/mloda-ai/mloda-plugin-govdata/main/logos/bmftr.png" alt="Funded by the Federal Ministry of Research, Technology and Space (BMFTR)" height="110">
|
|
160
|
+
|
|
161
|
+
<img src="https://raw.githubusercontent.com/mloda-ai/mloda-plugin-govdata/main/logos/prototypefund.png" alt="Supported by the Prototype Fund" height="110">
|
|
162
|
+
</p>
|
|
163
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Shared pytest fixtures for every ``tests/`` package under ``mloda_plugin_govdata``."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.fixture
|
|
9
|
+
def fixtures_dir(request: pytest.FixtureRequest) -> Path:
|
|
10
|
+
return Path(request.path).parent / "fixtures"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Destatis GENESIS connector: ``DestatisReader`` reads the table selection a ``DestatisLocator`` names.
|
|
2
|
+
|
|
3
|
+
GENESIS is the database software and its REST API. ``genesis`` (GENESIS-Online, Destatis) and ``regionalstatistik``
|
|
4
|
+
(Regionaldatenbank, run by IT.NRW) are two installations of it, each with its own registration. By convention
|
|
5
|
+
``Destatis*`` classes face mloda and ``Genesis*`` classes speak the protocol; ``OPTION_GENESIS_CREDENTIALS`` is an
|
|
6
|
+
mloda option despite its name.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from .core.api import GenesisClient
|
|
10
|
+
from .core.auth import OPTION_GENESIS_CREDENTIALS, DestatisCredentials
|
|
11
|
+
from .core.errors import (
|
|
12
|
+
GenesisAuthError,
|
|
13
|
+
GenesisBackendError,
|
|
14
|
+
GenesisEmptySelection,
|
|
15
|
+
GenesisError,
|
|
16
|
+
GenesisJobAccepted,
|
|
17
|
+
GenesisMaintenance,
|
|
18
|
+
GenesisResultTooLarge,
|
|
19
|
+
GenesisUnknownEnvelope,
|
|
20
|
+
GenesisUnknownTable,
|
|
21
|
+
MissingCredentialsError,
|
|
22
|
+
WrongHostCredentialsError,
|
|
23
|
+
)
|
|
24
|
+
from .core.hosts import GENESIS_ONLINE, REGIONALSTATISTIK, GenesisHost
|
|
25
|
+
from .core.parse import parse_ffcsv_zip
|
|
26
|
+
from .locator import DestatisLocator
|
|
27
|
+
from .reader import DestatisReader
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"GENESIS_ONLINE",
|
|
31
|
+
"OPTION_GENESIS_CREDENTIALS",
|
|
32
|
+
"REGIONALSTATISTIK",
|
|
33
|
+
"DestatisCredentials",
|
|
34
|
+
"DestatisLocator",
|
|
35
|
+
"DestatisReader",
|
|
36
|
+
"GenesisAuthError",
|
|
37
|
+
"GenesisBackendError",
|
|
38
|
+
"GenesisClient",
|
|
39
|
+
"GenesisEmptySelection",
|
|
40
|
+
"GenesisError",
|
|
41
|
+
"GenesisHost",
|
|
42
|
+
"GenesisJobAccepted",
|
|
43
|
+
"GenesisMaintenance",
|
|
44
|
+
"GenesisResultTooLarge",
|
|
45
|
+
"GenesisUnknownEnvelope",
|
|
46
|
+
"GenesisUnknownTable",
|
|
47
|
+
"MissingCredentialsError",
|
|
48
|
+
"WrongHostCredentialsError",
|
|
49
|
+
"parse_ffcsv_zip",
|
|
50
|
+
]
|