statcatlib 0.8.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.
Files changed (35) hide show
  1. statcatlib-0.8.0/LICENSE +180 -0
  2. statcatlib-0.8.0/PKG-INFO +429 -0
  3. statcatlib-0.8.0/README.md +395 -0
  4. statcatlib-0.8.0/pyproject.toml +130 -0
  5. statcatlib-0.8.0/pyproject.toml.orig +160 -0
  6. statcatlib-0.8.0/src/statcatlib/__init__.py +187 -0
  7. statcatlib-0.8.0/src/statcatlib/bundle.py +565 -0
  8. statcatlib-0.8.0/src/statcatlib/cli/__init__.py +546 -0
  9. statcatlib-0.8.0/src/statcatlib/expr.py +167 -0
  10. statcatlib-0.8.0/src/statcatlib/model/__init__.py +56 -0
  11. statcatlib-0.8.0/src/statcatlib/model/agents.py +32 -0
  12. statcatlib-0.8.0/src/statcatlib/model/catalog.py +71 -0
  13. statcatlib-0.8.0/src/statcatlib/model/classification.py +19 -0
  14. statcatlib-0.8.0/src/statcatlib/model/dataset.py +198 -0
  15. statcatlib-0.8.0/src/statcatlib/model/distribution.py +50 -0
  16. statcatlib-0.8.0/src/statcatlib/model/licence.py +18 -0
  17. statcatlib-0.8.0/src/statcatlib/model/quality.py +31 -0
  18. statcatlib-0.8.0/src/statcatlib/model/skos.py +141 -0
  19. statcatlib-0.8.0/src/statcatlib/model/spatial.py +19 -0
  20. statcatlib-0.8.0/src/statcatlib/model/temporal.py +33 -0
  21. statcatlib-0.8.0/src/statcatlib/model/types.py +5 -0
  22. statcatlib-0.8.0/src/statcatlib/py.typed +0 -0
  23. statcatlib-0.8.0/src/statcatlib/query.py +924 -0
  24. statcatlib-0.8.0/src/statcatlib/sources/__init__.py +13 -0
  25. statcatlib-0.8.0/src/statcatlib/sources/ckan.py +490 -0
  26. statcatlib-0.8.0/src/statcatlib/sources/sdmx.py +321 -0
  27. statcatlib-0.8.0/src/statcatlib/store/__init__.py +38 -0
  28. statcatlib-0.8.0/src/statcatlib/store/lance.py +1494 -0
  29. statcatlib-0.8.0/src/statcatlib/store/row.py +30 -0
  30. statcatlib-0.8.0/src/statcatlib/store/schema.py +403 -0
  31. statcatlib-0.8.0/src/statcatlib/store/scopes.py +1419 -0
  32. statcatlib-0.8.0/src/statcatlib/store/sentinel.py +99 -0
  33. statcatlib-0.8.0/src/statcatlib/store/store.py +6836 -0
  34. statcatlib-0.8.0/src/statcatlib/store/xhtml.py +206 -0
  35. statcatlib-0.8.0/src/statcatlib/urn.py +108 -0
@@ -0,0 +1,180 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any other
81
+ Contribution embodied in the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the
117
+ License.
118
+
119
+ You may add Your own license statement for Your modifications and
120
+ may provide additional grant of rights to use, copy, modify, merge,
121
+ publish, distribute, sublicense, and/or sell copies of the
122
+ Contribution, either on its own behalf or on behalf of the Licensor,
123
+ and only if You accept these terms.
124
+
125
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
126
+ any Contribution intentionally submitted for inclusion in the Work
127
+ by You to the Licensor shall be under the terms and conditions of
128
+ this License, without any additional terms or conditions.
129
+ Notwithstanding the above, nothing herein shall supersede or modify
130
+ the terms of any separate license agreement you may have executed
131
+ with Licensor regarding such Contributions.
132
+
133
+ 6. Trademarks. This License does not grant permission to use the trade
134
+ names, trademarks, service marks, or product names of the Licensor,
135
+ except as required for reasonable and customary use in describing the
136
+ origin of the Work and reproducing the content of the NOTICE file.
137
+
138
+ 7. Disclaimer of Warranty. Unless required by applicable law or
139
+ agreed to in writing, Licensor provides the Work (and each
140
+ Contributor provides its Contributions) on an "AS IS" BASIS,
141
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
142
+ implied, including, without limitation, any conditions of TITLE,
143
+ NONINFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
144
+ PURPOSE. You are solely responsible for determining the
145
+ appropriateness of using or redistributing the Work and assume any
146
+ risks associated with Your exercise of permissions under this License.
147
+
148
+ 8. Limitation of Liability. In no event and under no legal theory,
149
+ whether in tort (including negligence), contract, or otherwise,
150
+ unless required by applicable law (such as deliberate and grossly
151
+ negligent acts) or agreed to in writing, shall any Contributor be
152
+ liable to You for damages, including any direct, indirect, special,
153
+ incidental, or exemplary damages of any character arising as a
154
+ result of this License or out of the use or inability to use the
155
+ Work (even if such Contributor has been advised of the possibility
156
+ of such damages).
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer only
163
+ conditions consistent with this License, and charge a fee for,
164
+ such acceptance.
165
+
166
+ END OF TERMS AND CONDITIONS
167
+
168
+ Copyright 2026 gabrielgellner
169
+
170
+ Licensed under the Apache License, Version 2.0 (the "License");
171
+ you may not use this file except in compliance with the License.
172
+ You may obtain a copy of the License at
173
+
174
+ http://www.apache.org/licenses/LICENSE-2.0
175
+
176
+ Unless required by applicable law or agreed to in writing, software
177
+ distributed under the License is distributed on an "AS IS" BASIS,
178
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179
+ See the License for the specific language governing permissions and
180
+ limitations under the License.
@@ -0,0 +1,429 @@
1
+ Metadata-Version: 2.4
2
+ Name: statcatlib
3
+ Version: 0.8.0
4
+ Summary: Queryable open data catalog engine for DCAT-AP, StatDCAT-AP, CKAN, and SDMX
5
+ Keywords: sdmx,dcat,open-data,catalog,duckdb,statistical-data,ckan
6
+ Author: gabrielgellner
7
+ Author-email: gabrielgellner <gabrielgellner@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Database
16
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
17
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
18
+ Requires-Dist: attrs>=26.1.0
19
+ Requires-Dist: duckdb>=1.1,<2
20
+ Requires-Dist: httpx>=0.28
21
+ Requires-Dist: sdmxlib>=0.67
22
+ Requires-Dist: lancedb>=0.39 ; extra == 'search'
23
+ Requires-Dist: sentence-transformers>=3.0 ; extra == 'search'
24
+ Requires-Dist: typer>=0.15 ; extra == 'search'
25
+ Requires-Dist: rich>=15.0 ; extra == 'search'
26
+ Requires-Python: >=3.13
27
+ Project-URL: Homepage, https://github.com/StatCat-Suite/statcatlib
28
+ Project-URL: Repository, https://github.com/StatCat-Suite/statcatlib
29
+ Project-URL: Documentation, https://statcat-suite.github.io/statcatlib
30
+ Project-URL: Issue Tracker, https://github.com/StatCat-Suite/statcatlib/issues
31
+ Project-URL: Changelog, https://github.com/StatCat-Suite/statcatlib/blob/main/CHANGELOG.md
32
+ Provides-Extra: search
33
+ Description-Content-Type: text/markdown
34
+
35
+ # statcatlib
36
+
37
+ > **Note:** This library has been written extensively with AI assistance
38
+ > (Claude Code). Users who are not comfortable with AI-generated code should
39
+ > take that into account before adopting it.
40
+
41
+ **statcatlib** is a Python library for building, managing, and querying
42
+ statistical metadata catalogs. Formerly published as `statcatlib`.
43
+
44
+ Inspired by DCAT and the broader landscape of metadata standards (SDMX, DDI),
45
+ statcatlib provides a general-purpose engine for catalog storage, discovery, and
46
+ retrieval — designed to be embedded in ETL pipelines, data platforms, and
47
+ analytical tooling rather than used as a standalone application. It pairs
48
+ naturally with domain-specific libraries like
49
+ [sdmxlib](https://github.com/StatCat-Suite/sdmxlib) for standards-aware
50
+ workflows.
51
+
52
+ ```python
53
+ import statcatlib as sc
54
+ ```
55
+
56
+ ## What it does
57
+
58
+ statcatlib materializes remote catalog and structural metadata into a local
59
+ DuckDB database and exposes a fluent Python API for discovery queries —
60
+ filtering by publisher, theme, dimension, code, free text, or provenance lineage.
61
+
62
+ **The catalog is a materialized graph.** Rather than federated queries across
63
+ separate REST endpoints, ingest pulls the full structural model into one database.
64
+ SQL JOINs are the graph traversal. No network round-trips at query time.
65
+
66
+ ## Installation
67
+
68
+ Requires Python 3.13+. Managed with [uv](https://docs.astral.sh/uv/).
69
+
70
+ ```bash
71
+ uv add statcatlib
72
+ # or: pip install statcatlib
73
+ ```
74
+
75
+ Published on PyPI as `statcatlib` (formerly `pinaxlib`, imported as `pinax`).
76
+
77
+ statcatlib is pre-1.0: until 1.0, a minor release may break the API.
78
+
79
+ ## Quick start
80
+
81
+ ```python
82
+ import statcatlib as sc
83
+ import statcatlib.query as q
84
+ import sdmxlib as sl
85
+
86
+ # Creates my_catalog/bundle.duckdb and my_catalog/parquet/
87
+ with sc.Catalog("my_catalog").open() as store:
88
+ with sl.RestRegistry(sl.Provider.ESTAT) as reg:
89
+ reg.get(sl.Dataflow.urn_for(agency="ESTAT", id="NAMA_10_GDP"), resolve=True)
90
+ sc.ingest_sdmx(store, reg.registry)
91
+
92
+ # Catalog query — no network needed
93
+ results = (
94
+ store.query(sc.AggregateDataset)
95
+ .filter(q.has_code("geo", "DE"))
96
+ .search("GDP")
97
+ .with_facets("themes", "frequency")
98
+ .execute()
99
+ )
100
+ print(results.total, "datasets found")
101
+ print(results.facets["themes"])
102
+ ```
103
+
104
+ ## Five dataset kinds
105
+
106
+ statcatlib uses a discriminated union of dataset types aligned with DCAT-AP and
107
+ StatDCAT-AP:
108
+
109
+ ```python
110
+ # Generic datasets (CKAN, open portals)
111
+ sc.OpenDataset(identifier="co2-2024", title=i18n("CO2 Emissions 2024"), ...)
112
+
113
+ # Statistical tables with SDMX structure (dimensions, codelists)
114
+ sc.AggregateDataset(identifier="ESTAT:UNE_RT_M(1.0)", ..., sdmx_dataflow_urn="urn:...")
115
+
116
+ # Survey microdata with variable-level metadata
117
+ sc.MicrodataDataset(identifier="lfs-2023", ..., variables=[...])
118
+
119
+ # Spatial datasets with bounding box and CRS
120
+ sc.GeospatialDataset(identifier="boundaries-2024", ..., crs="EPSG:4326")
121
+
122
+ # Articles, reports, and analytical publications
123
+ sc.PublicationDataset(identifier="pub-71-607-x", ..., doi="10.25318/...", authors=[...])
124
+ ```
125
+
126
+ All five share the same store and query API. Use `sc.BaseDataset` as the bound
127
+ for generic code; `sc.Dataset` is a type alias for the full union.
128
+
129
+ ## Source connectors
130
+
131
+ ### SDMX (Eurostat, OECD, BIS, ABS, ...)
132
+
133
+ ```python
134
+ import sdmxlib as sl
135
+ import statcatlib as sc
136
+
137
+ with sc.Catalog("my_catalog").open() as store:
138
+ with sl.RestRegistry(sl.Provider.ESTAT) as reg:
139
+ for df_id in ["NAMA_10_GDP", "UNE_RT_M", "PRIC_HPI_IDX"]:
140
+ reg.get(sl.Dataflow.urn_for(agency="ESTAT", id=df_id), resolve=True)
141
+ sc.ingest_sdmx(store, reg.registry)
142
+
143
+ # Stream observation data to Parquet, attach as Distribution
144
+ sc.ingest_data(store, reg, "ESTAT:NAMA_10_GDP(latest)", measure_dim="na_item")
145
+ ```
146
+
147
+ ### CKAN (open.canada.ca, data.gov, ...)
148
+
149
+ ```python
150
+ from statcatlib.sources.ckan import CkanClient
151
+
152
+ with sc.Catalog("open_canada").open() as store:
153
+ with CkanClient("https://open.canada.ca/data") as client:
154
+ sc.ingest_ckan(store, client, organization="statcan", rows=500)
155
+ ```
156
+
157
+ ## Scope-based graph traversal
158
+
159
+ statcatlib exposes a lazy, scope-based API for navigating the catalog graph.
160
+ Navigation builds scope objects without executing SQL; only terminal methods
161
+ (`.collect()`, `.count()`) hit the database.
162
+
163
+ ```python
164
+ import statcatlib as sc
165
+
166
+ store = sc.Catalog("my_catalog").open()
167
+
168
+ # Navigate themes — no SQL until .collect()
169
+ concepts = store.themes["statcan"].collect() # ItemList[Concept]
170
+ concept = store.themes["statcan"]["13"].collect() # Concept
171
+
172
+ # Cross-entity navigation — .datasets returns a lazy QueryBuilder
173
+ datasets = store.themes["statcan"]["13"].datasets.collect()
174
+
175
+ # Enrich with sub-traversal expressions (like Polars' pl.col())
176
+ store.themes["statcan"].enrich(
177
+ n=sc.each("datasets").count(),
178
+ has_data=sc.each("datasets").exists(),
179
+ ).collect()
180
+
181
+ # Codelist navigation — sc.urn builds URN strings for you
182
+ codes = store.codelist(sc.urn.codelist("SDMX", "CL_GEO")).collect() # ItemList[Code]
183
+ code = store.codelist(sc.urn.codelist("SDMX", "CL_GEO"))["ON"].collect() # Code
184
+
185
+ # CodelistsScope — parallel to ThemesScope, supports enrich
186
+ # Enriched output includes labels resolved via sdmx.localized_text
187
+ store.codelists.lang("en").enrich(n=sc.each("datasets").count()).collect()
188
+ # → [{"urn": "...", "label": "Geography", "n": 5}, ...]
189
+
190
+ # Filter codelists by label text (SQL-level, case-insensitive)
191
+ store.codelists.filter(text_contains="geo").enrich(n=sc.each("datasets").count()).collect()
192
+
193
+ store.codelist(urn).label("en") # quick name lookup
194
+
195
+ # Enriched per-code output includes code name labels
196
+ store.codelist(urn).lang("en").enrich(n=sc.each("datasets").count()).collect()
197
+ # → [{"code_id": "ON", "label": "Ontario", "n": 5}, ...]
198
+
199
+ # Batch label resolution — single SQL query for many codes
200
+ store.codelist(geo_urn).batch_labels(["CA", "US", "DE"])
201
+ # → {"CA": "Canada", "US": "United States", "DE": "Germany"}
202
+
203
+ # Across multiple codelists at once
204
+ store.codelists.batch_labels([(geo_urn, "CA"), (freq_urn, "A")], lang="en")
205
+ # → {(geo_urn, "CA"): "Canada", (freq_urn, "A"): "Annual"}
206
+
207
+ # Dimension traversal
208
+ dims = store.dimensions(ds).collect() # ItemList[DimensionInfo]
209
+ codelist = store.dimensions(ds)["GEO"].codelist # CodelistScope (lazy)
210
+ ```
211
+
212
+ Scope classes: `ConceptSchemesScope`, `ConceptSchemeScope`, `ThemesScope`,
213
+ `SchemeScope`, `ConceptScope`, `CodelistsScope`, `CodelistScope`, `CodeScope`,
214
+ `DimensionsScope`, `DimensionScope`.
215
+
216
+ Expression types: `sc.each("edge")` creates a context-free sub-traversal
217
+ expression. Reusable across `.enrich()`, `.filter()`, and `.sort_by()`.
218
+
219
+ ## Query API
220
+
221
+ ### Structured filters
222
+
223
+ ```python
224
+ import statcatlib.query as q
225
+
226
+ # Field filters (keyword arguments)
227
+ store.query(sc.AggregateDataset).filter(publisher="ESTAT", status="current").all()
228
+
229
+ # Composable filter objects
230
+ store.query(sc.AggregateDataset).filter(
231
+ q.has_code("geo", "DE"), # datasets with GEO=DE in their codelist
232
+ q.has_dimensions(["geo", "freq"]), # datasets with both GEO and FREQ dimensions
233
+ ).all()
234
+
235
+ # Hierarchy descent — any geography *under* Canada, strict (CA itself excluded).
236
+ # The applicable Hierarchy is resolved per dataflow; add include_self=True to
237
+ # match the root as well.
238
+ store.query(sc.AggregateDataset).filter(q.within("REF_AREA", "CA")).all()
239
+
240
+ # Distribution and service filters
241
+ store.query(sc.OpenDataset).filter(
242
+ q.distribution(format="CSV"),
243
+ q.has_service(endpoint_url="https://..."),
244
+ ).all()
245
+ ```
246
+
247
+ ### Cross-entity queries
248
+
249
+ ```python
250
+ # Agents that publish datasets with code GEO=CA
251
+ store.query(sc.Agent).filter(
252
+ q.publishes(q.has_code("geo", "CA"), kind="aggregate")
253
+ ).all()
254
+
255
+ # Data services serving aggregate datasets
256
+ store.query(sc.DataService).filter(
257
+ q.serves(kind="aggregate")
258
+ ).all()
259
+ ```
260
+
261
+ ### MAP column filters
262
+
263
+ ```python
264
+ # Spatial coverage filter
265
+ store.query(sc.BaseDataset).filter(q.has_spatial("Canada")).all()
266
+
267
+ # Keyword filter
268
+ store.query(sc.BaseDataset).filter(q.has_keyword("employment")).all()
269
+
270
+ # Title/description search (case-insensitive ILIKE)
271
+ store.query(sc.BaseDataset).filter(q.title_contains("GDP")).all()
272
+ store.query(sc.BaseDataset).filter(q.description_contains("quarterly")).all()
273
+
274
+ # Sort by multilingual title
275
+ store.query(sc.BaseDataset).sort_by("title", lang="en").all()
276
+ store.query(sc.BaseDataset).sort_by("title", lang="en", desc=True).all()
277
+ ```
278
+
279
+ ### Selective relationship loading
280
+
281
+ By default, querying a list of datasets loads all relationships (~17 queries).
282
+ Use `.include()` to declare exactly which relationships to batch-load — the rest
283
+ are set to an `UNLOADED` sentinel:
284
+
285
+ ```python
286
+ # Only load publisher and themes — 3 queries instead of ~17
287
+ results = (
288
+ store.query(sc.BaseDataset)
289
+ .filter(status="published")
290
+ .include("publisher", "themes", "keywords")
291
+ .sort_by("issued", desc=True)
292
+ .limit(20)
293
+ .all()
294
+ )
295
+
296
+ # Explicit full hydration — useful to make the cost visible at the call site
297
+ results = store.query(sc.BaseDataset).filter(...).full().all()
298
+
299
+ # get() always loads everything — no include() needed
300
+ ds = store.get(sc.AggregateDataset, "ESTAT:NAMA_10_GDP(1.0)")
301
+ ```
302
+
303
+ Unloaded fields raise `sc.NotLoadedError` on access. Use `sc.is_unloaded(value)`
304
+ to check before accessing:
305
+
306
+ ```python
307
+ ds = store.query(sc.BaseDataset).include("publisher").first()
308
+ ds.publisher.name # OK
309
+ ds.themes[0] # raises NotLoadedError: 'themes' was not loaded
310
+
311
+ if not sc.is_unloaded(ds.themes):
312
+ print(ds.themes)
313
+ ```
314
+
315
+ Valid relationship names: `publisher`, `contact_point`, `frequency`, `licence`,
316
+ `themes`, `subject`, `dataset_type`, `keywords`, `spatial_coverage`,
317
+ `distributions`, `conforms_to`, `quality_annotations`, `provenance`,
318
+ `dimension_names`, `variables`, `feature_types`, `authors`.
319
+
320
+ ### Lightweight projections
321
+
322
+ When you need just a few columns (e.g. autocomplete), projection modifiers
323
+ bypass full object reconstruction — a single SQL query:
324
+
325
+ ```python
326
+ # Row projection — .select() + .rows() returns Row objects (dict subclass)
327
+ rows = (
328
+ store.query(sc.BaseDataset)
329
+ .filter(q.title_contains("GDP"))
330
+ .sort_by("title", lang="en")
331
+ .limit(3)
332
+ .select("identifier", "title", lang="en")
333
+ .rows()
334
+ )
335
+ # → [Row({"identifier": "GDP", "title": "GDP Growth"}), ...]
336
+ rows[0].identifier # attribute-style access
337
+ rows[0]["title"] # dict-style access — both work
338
+
339
+ # Flat value projection — .scalars() + .values() returns bare values
340
+ ids = store.query(sc.BaseDataset).filter(status="current").scalars("identifier").values()
341
+ # → ["EXR", "M1", "UNEMP", ...]
342
+
343
+ # Existence check — no object reconstruction
344
+ if store.query(sc.AggregateDataset).filter(q.has_code("geo", "DE")).exists():
345
+ ...
346
+ ```
347
+
348
+ ### Full-text search and facets
349
+
350
+ ```python
351
+ # BM25 search across titles, descriptions, keywords, themes, and dimensions
352
+ results = store.search("unemployment", limit=20)
353
+
354
+ # Combined search and filter
355
+ results = (
356
+ store.query(sc.AggregateDataset)
357
+ .filter(publisher="ESTAT")
358
+ .search("labour force")
359
+ .with_facets("themes", "frequency")
360
+ .execute()
361
+ )
362
+ print(results.facets["themes"]) # {"Labour": 18, "Economy": 6, ...}
363
+
364
+ # Aggregation counts
365
+ counts = store.facets("publisher", "themes", "frequency", "status")
366
+ ```
367
+
368
+ ### Lineage and provenance (PROV-O)
369
+
370
+ ```python
371
+ # Record derivation relationships between datasets
372
+ store.add_lineage(
373
+ "lfs-microdata",
374
+ "14100287",
375
+ "aggregated_from",
376
+ activity_type="aggregation",
377
+ activity_label="LFS monthly tabulation",
378
+ confidence="asserted",
379
+ )
380
+
381
+ # Transitive upstream/downstream traversal — returns QueryBuilder for chaining
382
+ ancestors = store.dataset("14100287").upstream(depth=5).collect()
383
+ dependents = store.dataset("CL_GEO").downstream(relationship="uses_classification").collect()
384
+
385
+ # Chain additional filters after traversal
386
+ current = store.dataset("14100287").upstream().filter(status="current").collect()
387
+
388
+ # Inspect lineage records
389
+ rows = store.dataset("14100287").lineage_records(role="target", relationship="aggregated_from")
390
+ ```
391
+
392
+ ## Architecture
393
+
394
+ Three layers share one DuckDB database:
395
+
396
+ ```
397
+ Discovery layer — Catalog (dataset, agent, concept_scheme, concept, distribution, lineage)
398
+ Structural layer — sdmxlib tables (dataflows, dsd_components, codes, codelists)
399
+ Observation layer — Polars / Parquet (actual time-series data)
400
+ ```
401
+
402
+ statcatlib owns the discovery layer. sdmxlib owns the structural layer. Both write
403
+ to the same DuckDB connection — queries JOIN freely across both. Parquet files live
404
+ alongside the database and are referenced via DCAT `Distribution` records.
405
+
406
+ ## Development
407
+
408
+ Run once per clone — installs a pre-push hook that runs the full gate, since
409
+ hosted CI only builds the docs site:
410
+
411
+ ```bash
412
+ just hooks-install
413
+ ```
414
+
415
+ ```bash
416
+ just ci # full gate: index guard + lint + format + docstrings + Any ratchet + both type checkers + unit tests + strict docs build
417
+ just test # unit tests
418
+ just test-integration # integration tests (no network)
419
+ just test-live # live tests against real SDMX endpoints
420
+ just lint # ruff check
421
+ just typecheck # basedpyright
422
+ just check-indexes # only public PyPI is named anywhere in the repo
423
+ just docs # local docs server
424
+ ```
425
+
426
+ `uv.lock` is not committed: statcatlib is a library, so consumers resolve against
427
+ `pyproject.toml`, and a lockfile would record whichever index resolved it.
428
+ `just check-indexes` fails the build if a non-public package index is named in
429
+ any tracked file.