API reference — Dataspot source¶
The Dataspot catalog source: extraction, field mapping, vocabulary mapping, enrichment and structure handling. The field and vocabulary mappings are also documented as tables on the Mappings page.
source ¶
drain_extract_skips ¶
drain_extract_skips() -> list[dict]
Return and clear the skips recorded by the last extract.
Each dict matches the invalid_details shape the alert email
consumes (id/title/stage/kind/field_errors) plus
resource so the caller can attach it to the right raw asset.
Source code in src/metadataswiss_connector/sources/dataspot/source.py
63 64 65 66 67 68 69 70 71 72 | |
dataspot_source ¶
dataspot_source(
base_url: str = dlt.config.value,
database_name: str = dlt.config.value,
exposed_client_id: str = dlt.config.value,
tenant_id: str = dlt.secrets.value,
client_id: str = dlt.secrets.value,
client_secret: str = dlt.secrets.value,
dataspot_access_key: str = dlt.secrets.value,
)
dlt source for the Dataspot metadata catalog REST API.
Arguments not passed explicitly are injected by dlt's config/secrets
system from the sources.dataspot.* section — i.e. env vars under
the SOURCES__DATASPOT__* naming (loaded from .env; see
.env.example). The explicit section pins that lookup path
independently of this module's name.
Source code in src/metadataswiss_connector/sources/dataspot/source.py
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 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 514 515 516 517 518 519 520 | |
transform ¶
Dataspot-specific field mapping to I14Y DCAT format.
transform_to_dataset ¶
transform_to_dataset(
record: dict,
children: dict[str, list],
*,
lookups: Lookups,
publisher: str
) -> (
tuple[DcatDatasetInputModel, dict]
| DcatDatasetInputModel
)
Map a flattened Dataspot dataset row to a DcatDatasetInputModel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
dict
|
Flattened row from DuckDB. Nested fields use dlt's |
required |
children
|
dict[str, list]
|
dlt 1:n child tables keyed by field name (e.g. |
required |
lookups
|
Lookups
|
per-run view over the cross-reference tables (e.g.
|
required |
publisher
|
str
|
I14Y publisher identifier (e.g. "Basel-Stadt"). Configured globally via I14Y_PUBLISHER_IDENTIFIER env var. |
required |
Source code in src/metadataswiss_connector/sources/dataspot/transform.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 | |
transform_to_dataservice ¶
transform_to_dataservice(
record: dict,
children: dict[str, list],
*,
lookups: Lookups,
publisher: str
) -> DataServiceInputModel
Map a flattened Dataspot API record to a DataServiceInputModel.
Dataspot exposes APIs as data products with stereotype API. They
share most metadata with OGD/GEO datasets but publish to I14Y under
/dataservices with a different input model (no distributions, no
SHACL structure). Endpoint metadata comes from dedicated
i14y_api_* custom properties on the dataspot record.
Source code in src/metadataswiss_connector/sources/dataspot/transform.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
transform_to_concept ¶
transform_to_concept(
record: dict,
children: dict[str, list],
*,
lookups: Lookups,
publisher: str
) -> tuple[CodeListConceptInput, dict]
Map a Dataspot enumeration row to a CodeListConceptInput.
Returns (model, extras) where extras["entries"] carries the
code-list entry payloads. The concept itself is created via
POST /concepts; the entries are uploaded as a follow-up via
POST /concepts/{id}/codelist-entries/imports/Json once the
concept's I14Y UUID is known.
Source code in src/metadataswiss_connector/sources/dataspot/transform.py
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 | |
mappings ¶
Dataspot-specific vocabulary mappings to I14Y codes.
Kept separate from the generic I14Y builders so that vocabulary changes on the Dataspot side don't ripple into shared code, and other sources don't inherit Dataspot's input shapes.
themes ¶
themes(
topics: list[str] | None, geo_category: str | None
) -> list[CodeInputModel] | None
Map Dataspot topics (BFS) and geoCategory (eCH-166) to I14Y theme codes.
Unknown values are dropped; duplicates are collapsed; insertion order
is preserved. Returns None when nothing maps.
Source code in src/metadataswiss_connector/sources/dataspot/mappings.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
confidentiality_person ¶
confidentiality_person(
values: list[str] | None,
) -> CodeInputModel | None
Map Dataspot personal_data values to an I14Y confidentialityPerson code.
Source code in src/metadataswiss_connector/sources/dataspot/mappings.py
105 106 107 108 109 110 111 112 113 | |
retention_period_complement ¶
retention_period_complement(
period_years: int | str | None,
justification: str | None,
lang: str = "de",
) -> MultiLanguageModel | None
Combine Dataspot's retention period + justification into a plain-text block.
I14Y has no structured field for retention metadata, so the two Dataspot custom properties are concatenated into a single description.
Source code in src/metadataswiss_connector/sources/dataspot/mappings.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
enrichment ¶
Enrichment helpers for the Dataspot source.
Wraps the Dataspot REST client and the Staatskalender lookup behind a single class so the source-level dlt transformers stay declarative. Caches and retry logic live here so they're independently testable.
DataspotEnrichment ¶
Resolves ancestry, data-owner names, and staatskalender agencies.
All fetch methods are memoized for the lifetime of the instance.
Pass an existing client (and optional staatskalender_client)
to inject test doubles; otherwise both are constructed from
base_url/database_name/auth.
Source code in src/metadataswiss_connector/sources/dataspot/enrichment.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
fetch_parent ¶
fetch_parent(href: str) -> dict
Resolve and cache an inCollection href to its parent payload.
Errors propagate: an unreachable parent should fail loudly rather than silently truncating the ancestry chain.
Source code in src/metadataswiss_connector/sources/dataspot/enrichment.py
117 118 119 120 121 122 123 124 125 | |
fetch_attribute ¶
fetch_attribute(href: str) -> dict
Resolve and cache a composition's composedOf href to its attribute payload.
Source code in src/metadataswiss_connector/sources/dataspot/enrichment.py
127 128 129 130 131 | |
fetch_datatype ¶
fetch_datatype(href: str) -> dict
Resolve and cache an attribute's hasRange href to its datatype payload.
Source code in src/metadataswiss_connector/sources/dataspot/enrichment.py
133 134 135 136 137 | |
fetch_derived_dataset_ids ¶
fetch_derived_dataset_ids(dataset_id: str) -> list[str]
Dataspot dataset IDs an API produces, per its SPEZ2 derivations.
An API's datasets/{id}/derivedFrom link returns Derivation
objects in _embedded.derivedFrom; each carries a derivedFrom
target ID and a qualifier. We keep only SPEZ2 derivations
(the "produces" relation) and return their target dataset IDs.
Source code in src/metadataswiss_connector/sources/dataspot/enrichment.py
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 | |
walk_ancestors ¶
walk_ancestors(item: dict) -> Iterator[tuple[str, dict]]
Yield (href, parent) tuples for each public ancestor.
Source code in src/metadataswiss_connector/sources/dataspot/enrichment.py
254 255 256 257 258 259 260 261 262 | |
structure ¶
Adapter: Dataspot structure rows → I14Y SHACL Turtle.
Translates rows from the dataset_structure_components raw table into
the source-neutral StructureComponent shape consumed by
dcat.shacl.build_shacl_turtle. Keep the what (Dataspot field
mapping, XSD resolution, minCount/maxCount semantics) here; the how
(Turtle rendering) lives in dcat/shacl.py.
build_dataset_shacl_turtle ¶
build_dataset_shacl_turtle(
*,
dataset_id: str,
dataset_label: str | None,
components: list[dict]
) -> str | None
Return a SHACL Turtle document for one Dataspot dataset, or None.
components are raw rows from dataset_structure_components;
rows without attribute_id are skipped. The result is uploaded to
I14Y's POST /datasets/{id}/structures/imports endpoint.
Source code in src/metadataswiss_connector/sources/dataspot/structure.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
auth ¶
DataspotAuth ¶
Bases: OAuth2ClientCredentials
Dataspot API authentication.
Combines Azure AD M2M OAuth2 (client_credentials) with a custom dataspot-access-key header required by the Dataspot API.
Source code in src/metadataswiss_connector/sources/dataspot/auth.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
constants ¶
Dataspot-specific constant values used across the source extraction.