parsimony-sdmx 0.2.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 (50) hide show
  1. parsimony_sdmx-0.2.0/.gitignore +40 -0
  2. parsimony_sdmx-0.2.0/CHANGELOG.md +5 -0
  3. parsimony_sdmx-0.2.0/LICENSE +190 -0
  4. parsimony_sdmx-0.2.0/PKG-INFO +145 -0
  5. parsimony_sdmx-0.2.0/README.md +103 -0
  6. parsimony_sdmx-0.2.0/parsimony_sdmx/__init__.py +43 -0
  7. parsimony_sdmx-0.2.0/parsimony_sdmx/_catalog_planning.py +95 -0
  8. parsimony_sdmx-0.2.0/parsimony_sdmx/_legacy_sdmx.py +794 -0
  9. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/__init__.py +1 -0
  10. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/args.py +126 -0
  11. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/layout.py +41 -0
  12. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/listing.py +172 -0
  13. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/main.py +183 -0
  14. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/memory_monitor.py +225 -0
  15. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/orchestrator.py +345 -0
  16. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/orphan_sweep.py +32 -0
  17. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/summary.py +38 -0
  18. parsimony_sdmx-0.2.0/parsimony_sdmx/cli/worker.py +80 -0
  19. parsimony_sdmx-0.2.0/parsimony_sdmx/connectors/__init__.py +41 -0
  20. parsimony_sdmx-0.2.0/parsimony_sdmx/connectors/_agencies.py +44 -0
  21. parsimony_sdmx-0.2.0/parsimony_sdmx/connectors/enumerate_datasets.py +110 -0
  22. parsimony_sdmx-0.2.0/parsimony_sdmx/connectors/enumerate_series.py +128 -0
  23. parsimony_sdmx-0.2.0/parsimony_sdmx/connectors/fetch.py +166 -0
  24. parsimony_sdmx-0.2.0/parsimony_sdmx/core/__init__.py +5 -0
  25. parsimony_sdmx-0.2.0/parsimony_sdmx/core/codelists.py +50 -0
  26. parsimony_sdmx-0.2.0/parsimony_sdmx/core/errors.py +27 -0
  27. parsimony_sdmx-0.2.0/parsimony_sdmx/core/models.py +17 -0
  28. parsimony_sdmx-0.2.0/parsimony_sdmx/core/outcomes.py +47 -0
  29. parsimony_sdmx-0.2.0/parsimony_sdmx/core/projection.py +87 -0
  30. parsimony_sdmx-0.2.0/parsimony_sdmx/core/titles.py +55 -0
  31. parsimony_sdmx-0.2.0/parsimony_sdmx/io/__init__.py +1 -0
  32. parsimony_sdmx-0.2.0/parsimony_sdmx/io/html.py +38 -0
  33. parsimony_sdmx-0.2.0/parsimony_sdmx/io/http.py +198 -0
  34. parsimony_sdmx-0.2.0/parsimony_sdmx/io/parquet.py +201 -0
  35. parsimony_sdmx-0.2.0/parsimony_sdmx/io/paths.py +47 -0
  36. parsimony_sdmx-0.2.0/parsimony_sdmx/io/xml.py +116 -0
  37. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/__init__.py +1 -0
  38. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/agencies.py +15 -0
  39. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/ecb.py +139 -0
  40. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/ecb_portal.py +224 -0
  41. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/ecb_series_attrs.py +81 -0
  42. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/estat.py +23 -0
  43. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/imf.py +23 -0
  44. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/protocol.py +26 -0
  45. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/registry.py +33 -0
  46. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/sdmx_client.py +38 -0
  47. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/sdmx_extract.py +153 -0
  48. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/sdmx_flow.py +152 -0
  49. parsimony_sdmx-0.2.0/parsimony_sdmx/providers/wb.py +355 -0
  50. parsimony_sdmx-0.2.0/pyproject.toml +87 -0
@@ -0,0 +1,40 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+
6
+ .Python
7
+ build/
8
+ dist/
9
+ *.egg-info/
10
+ *.egg
11
+
12
+ .venv/
13
+ .env
14
+ .env.*
15
+ !.env.example
16
+
17
+ .pytest_cache/
18
+ .mypy_cache/
19
+ .ruff_cache/
20
+ .coverage
21
+ htmlcov/
22
+ coverage.xml
23
+
24
+ uv.lock
25
+
26
+ .vscode/
27
+ .council/
28
+ PLAN-*.md
29
+ .idea/
30
+ *.swp
31
+ .DS_Store
32
+
33
+ outputs/
34
+
35
+ # Recorded HTTP cassettes must never be committed — respx mocks are hand-authored
36
+ # from upstream API documentation. A pre-commit / CI regex scan is the belt; this
37
+ # ignore is the braces. Override per-file via `!` if you need a hand-authored
38
+ # fixture checked in.
39
+ packages/*/tests/fixtures/**
40
+ !packages/*/tests/fixtures/README.md
@@ -0,0 +1,5 @@
1
+ # Changelog — parsimony-sdmx
2
+
3
+ ## Unreleased
4
+
5
+ - Initial scaffold.
@@ -0,0 +1,190 @@
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, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Ockham.sh
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: parsimony-sdmx
3
+ Version: 0.2.0
4
+ Summary: SDMX protocol connector (ECB, Eurostat, IMF, OECD, BIS, World Bank, ILO) for the parsimony framework
5
+ Project-URL: Homepage, https://parsimony.dev
6
+ Project-URL: Repository, https://github.com/ockham-sh/parsimony-connectors
7
+ Project-URL: Issues, https://github.com/ockham-sh/parsimony-connectors/issues
8
+ Author-email: "Ockham.sh" <team@ockham.sh>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: connectors,data,finance,parsimony,sdmx
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Office/Business :: Financial
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: beautifulsoup4>=4.12
25
+ Requires-Dist: lxml>=5.0
26
+ Requires-Dist: pandas<3,>=2.3.0
27
+ Requires-Dist: parsimony-core<0.3,>=0.1.0a0
28
+ Requires-Dist: psutil>=5.9
29
+ Requires-Dist: pyarrow>=16.0
30
+ Requires-Dist: pydantic<3,>=2.11.1
31
+ Requires-Dist: requests>=2.32
32
+ Requires-Dist: sdmx1>=2.16
33
+ Provides-Extra: dev
34
+ Requires-Dist: mypy>=1.10; extra == 'dev'
35
+ Requires-Dist: pytest-asyncio>=1.3.0; extra == 'dev'
36
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
37
+ Requires-Dist: pytest>=9.0.3; extra == 'dev'
38
+ Requires-Dist: pyyaml>=6.0; extra == 'dev'
39
+ Requires-Dist: respx>=0.22.0; extra == 'dev'
40
+ Requires-Dist: ruff>=0.15.10; extra == 'dev'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # parsimony-sdmx
44
+
45
+ Flat SDMX catalog builder. Harvests dataflows from statistical agencies (ECB, Eurostat, IMF, World Bank) and writes two parquet files per agency — a dataset-level catalog and one series-level catalog per dataset — ready to feed a FAISS or SQL index.
46
+
47
+ ## Layout
48
+
49
+ ```
50
+ outputs/{AGENCY}/datasets.parquet # columns: dataset_id, agency_id, title
51
+ outputs/{AGENCY}/series/{DATASET}.parquet # columns: id, dataset_id, title
52
+ ```
53
+
54
+ Titles are composed as `"CODE1: label1 - CODE2: label2 - …"` over the DSD's non-`TIME_PERIOD` dimensions in DSD order. ECB series additionally append `TITLE` / `TITLE_COMPL` fetched from the per-series XML endpoint. HTML-embedded descriptions (common on Eurostat) are stripped before they reach parquet.
55
+
56
+ ## Install
57
+
58
+ Requires Python ≥ 3.12 and [uv](https://docs.astral.sh/uv/).
59
+
60
+ ```bash
61
+ make install # uv sync --all-extras
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ```bash
67
+ # Print every dataset the agency exposes
68
+ parsimony-sdmx -a ESTAT --list-datasets
69
+
70
+ # Write only outputs/{AGENCY}/datasets.parquet (no series fetched)
71
+ parsimony-sdmx -a ECB --catalog
72
+
73
+ # Fetch one dataset
74
+ parsimony-sdmx -a ECB -d YC
75
+
76
+ # Fetch every dataset the agency exposes
77
+ parsimony-sdmx -a ESTAT --all
78
+
79
+ # Preview what an --all run would write, without fetching
80
+ parsimony-sdmx -a ESTAT --all --dry-run
81
+
82
+ # Rebuild datasets whose parquet already exists (resume contract: file present → skip)
83
+ parsimony-sdmx -a ECB -d YC --force
84
+ ```
85
+
86
+ Or via Make shortcuts:
87
+
88
+ ```bash
89
+ make catalog AGENCY=ECB # datasets.parquet only
90
+ make fetch AGENCY=ECB DATASET=YC # single dataset
91
+ make fetch-all AGENCY=ESTAT # every dataset for the agency
92
+ make list AGENCY=IMF_DATA # enumerate datasets
93
+ ```
94
+
95
+ Supported agencies: `ECB`, `ESTAT`, `IMF_DATA`, `WB_WDI`. Exit codes: `0` every dataset ok/empty, `1` at least one failed.
96
+
97
+ ## Architecture
98
+
99
+ Four packages under `parsimony_sdmx/`:
100
+
101
+ - **`core/`** — pure, I/O-free: record dataclasses, title composition, codelist resolution, outcome types, domain exceptions.
102
+ - **`io/`** — boundary effects: atomic parquet writers, hardened lxml iterparse, HTTPS-only bounded HTTP session, path safety helpers, exception classification.
103
+ - **`providers/`** — per-agency adapters behind a narrow `CatalogProvider` protocol; ECB/ESTAT/IMF share a common sdmx1 flow helper, WB diverges with a path × decade sweep because its SDMX endpoint doesn't expose `series_keys`.
104
+ - **`cli/`** — argparse front-end, orchestrator that forks one subprocess per dataset (`mp.spawn`) for memory isolation, a psutil-backed memory monitor that kills the largest child above a threshold and writes OOM markers, atomic `.tmp/` cleanup, and an operator-readable end-of-run summary.
105
+
106
+ ### Why subprocess-per-dataset
107
+
108
+ `sdmx1` caches structure messages at module level with no public invalidation hook. Running every dataset in its own subprocess is the only reliable way to start each fetch with a clean cache. Large catalogs (8 k+ Eurostat dataflows) have hit real OOMs in production; the memory monitor catches runaway workers before the kernel OOM killer does, preserving a classifiable failure instead of an opaque `exit 137`.
109
+
110
+ ### Resume
111
+
112
+ Filesystem-backed: a dataset is skipped if `outputs/{AGENCY}/series/{DATASET}.parquet` already exists. Writes land in `.tmp/` first and are `os.replace`-d atomically, so the canonical path exists iff the previous run completed. `--force` overrides (and logs a count of overwrites).
113
+
114
+ ## Development
115
+
116
+ ```bash
117
+ make check # ruff + mypy strict + fast tests
118
+ make test # fast tests only (skip subprocess-path tests)
119
+ make test-slow # subprocess tests (fork real mp.Process children)
120
+ make test-all # everything
121
+ make format # ruff format + --fix
122
+ make clean # wipe caches + build artifacts
123
+ ```
124
+
125
+ Hardening enforced by default:
126
+
127
+ - `mypy --strict` across source and tests
128
+ - `ruff` with `E, F, W, I, B, UP, S` (security rules on)
129
+ - Hardened `lxml.iterparse` (no entity resolution, no DTD load, no network)
130
+ - HTTPS-only `bounded_get` with a configurable byte cap
131
+ - Path traversal guards on every on-disk write
132
+
133
+ ## Project layout
134
+
135
+ ```
136
+ parsimony_sdmx/
137
+ ├── core/ # pure domain logic
138
+ ├── io/ # boundary-layer effects
139
+ ├── providers/ # per-agency adapters
140
+ └── cli/ # argparse → orchestrator → worker → parquet
141
+
142
+ tests/ # flat: test_<module>.py per source module
143
+ ```
144
+
145
+ Test suite: 312 tests. 4 of them (`@pytest.mark.slow`) fork real subprocesses to exercise the orchestrator's timeout / OOM classification / clean-exit paths; the other 308 run in < 2 s.
@@ -0,0 +1,103 @@
1
+ # parsimony-sdmx
2
+
3
+ Flat SDMX catalog builder. Harvests dataflows from statistical agencies (ECB, Eurostat, IMF, World Bank) and writes two parquet files per agency — a dataset-level catalog and one series-level catalog per dataset — ready to feed a FAISS or SQL index.
4
+
5
+ ## Layout
6
+
7
+ ```
8
+ outputs/{AGENCY}/datasets.parquet # columns: dataset_id, agency_id, title
9
+ outputs/{AGENCY}/series/{DATASET}.parquet # columns: id, dataset_id, title
10
+ ```
11
+
12
+ Titles are composed as `"CODE1: label1 - CODE2: label2 - …"` over the DSD's non-`TIME_PERIOD` dimensions in DSD order. ECB series additionally append `TITLE` / `TITLE_COMPL` fetched from the per-series XML endpoint. HTML-embedded descriptions (common on Eurostat) are stripped before they reach parquet.
13
+
14
+ ## Install
15
+
16
+ Requires Python ≥ 3.12 and [uv](https://docs.astral.sh/uv/).
17
+
18
+ ```bash
19
+ make install # uv sync --all-extras
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```bash
25
+ # Print every dataset the agency exposes
26
+ parsimony-sdmx -a ESTAT --list-datasets
27
+
28
+ # Write only outputs/{AGENCY}/datasets.parquet (no series fetched)
29
+ parsimony-sdmx -a ECB --catalog
30
+
31
+ # Fetch one dataset
32
+ parsimony-sdmx -a ECB -d YC
33
+
34
+ # Fetch every dataset the agency exposes
35
+ parsimony-sdmx -a ESTAT --all
36
+
37
+ # Preview what an --all run would write, without fetching
38
+ parsimony-sdmx -a ESTAT --all --dry-run
39
+
40
+ # Rebuild datasets whose parquet already exists (resume contract: file present → skip)
41
+ parsimony-sdmx -a ECB -d YC --force
42
+ ```
43
+
44
+ Or via Make shortcuts:
45
+
46
+ ```bash
47
+ make catalog AGENCY=ECB # datasets.parquet only
48
+ make fetch AGENCY=ECB DATASET=YC # single dataset
49
+ make fetch-all AGENCY=ESTAT # every dataset for the agency
50
+ make list AGENCY=IMF_DATA # enumerate datasets
51
+ ```
52
+
53
+ Supported agencies: `ECB`, `ESTAT`, `IMF_DATA`, `WB_WDI`. Exit codes: `0` every dataset ok/empty, `1` at least one failed.
54
+
55
+ ## Architecture
56
+
57
+ Four packages under `parsimony_sdmx/`:
58
+
59
+ - **`core/`** — pure, I/O-free: record dataclasses, title composition, codelist resolution, outcome types, domain exceptions.
60
+ - **`io/`** — boundary effects: atomic parquet writers, hardened lxml iterparse, HTTPS-only bounded HTTP session, path safety helpers, exception classification.
61
+ - **`providers/`** — per-agency adapters behind a narrow `CatalogProvider` protocol; ECB/ESTAT/IMF share a common sdmx1 flow helper, WB diverges with a path × decade sweep because its SDMX endpoint doesn't expose `series_keys`.
62
+ - **`cli/`** — argparse front-end, orchestrator that forks one subprocess per dataset (`mp.spawn`) for memory isolation, a psutil-backed memory monitor that kills the largest child above a threshold and writes OOM markers, atomic `.tmp/` cleanup, and an operator-readable end-of-run summary.
63
+
64
+ ### Why subprocess-per-dataset
65
+
66
+ `sdmx1` caches structure messages at module level with no public invalidation hook. Running every dataset in its own subprocess is the only reliable way to start each fetch with a clean cache. Large catalogs (8 k+ Eurostat dataflows) have hit real OOMs in production; the memory monitor catches runaway workers before the kernel OOM killer does, preserving a classifiable failure instead of an opaque `exit 137`.
67
+
68
+ ### Resume
69
+
70
+ Filesystem-backed: a dataset is skipped if `outputs/{AGENCY}/series/{DATASET}.parquet` already exists. Writes land in `.tmp/` first and are `os.replace`-d atomically, so the canonical path exists iff the previous run completed. `--force` overrides (and logs a count of overwrites).
71
+
72
+ ## Development
73
+
74
+ ```bash
75
+ make check # ruff + mypy strict + fast tests
76
+ make test # fast tests only (skip subprocess-path tests)
77
+ make test-slow # subprocess tests (fork real mp.Process children)
78
+ make test-all # everything
79
+ make format # ruff format + --fix
80
+ make clean # wipe caches + build artifacts
81
+ ```
82
+
83
+ Hardening enforced by default:
84
+
85
+ - `mypy --strict` across source and tests
86
+ - `ruff` with `E, F, W, I, B, UP, S` (security rules on)
87
+ - Hardened `lxml.iterparse` (no entity resolution, no DTD load, no network)
88
+ - HTTPS-only `bounded_get` with a configurable byte cap
89
+ - Path traversal guards on every on-disk write
90
+
91
+ ## Project layout
92
+
93
+ ```
94
+ parsimony_sdmx/
95
+ ├── core/ # pure domain logic
96
+ ├── io/ # boundary-layer effects
97
+ ├── providers/ # per-agency adapters
98
+ └── cli/ # argparse → orchestrator → worker → parquet
99
+
100
+ tests/ # flat: test_<module>.py per source module
101
+ ```
102
+
103
+ Test suite: 312 tests. 4 of them (`@pytest.mark.slow`) fork real subprocesses to exercise the orchestrator's timeout / OOM classification / clean-exit paths; the other 308 run in < 2 s.
@@ -0,0 +1,43 @@
1
+ """``parsimony-sdmx`` — SDMX connector plugin for the ``parsimony`` kernel.
2
+
3
+ Exports:
4
+
5
+ - :data:`CONNECTORS` — the plugin surface discovered via the
6
+ ``parsimony.providers`` entry point group. Three items: two enumerators
7
+ (dataset-level + per-dataset series) and one live fetch connector. Both
8
+ enumerators carry a ``catalog=`` declaration so ``parsimony bundles``
9
+ drives publish; SDMX no longer ships its own bundle CLI.
10
+ - :data:`ENV_VARS` — empty. SDMX endpoints are public.
11
+ - :data:`PROVIDER_METADATA` — bundle topology and supported agencies.
12
+
13
+ Discovery is driven by the kernel via entry points declared in
14
+ ``pyproject.toml``. No manual registration required — users ``pip install
15
+ parsimony-sdmx`` and the plugin appears in ``parsimony list-plugins``.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from typing import Any
21
+
22
+ from parsimony_sdmx.connectors import CONNECTORS, ENV_VARS
23
+ from parsimony_sdmx.connectors._agencies import ALL_AGENCIES
24
+
25
+ __version__ = "0.2.0"
26
+
27
+
28
+ PROVIDER_METADATA: dict[str, Any] = {
29
+ "agencies": [a.value for a in ALL_AGENCIES],
30
+ "namespace_templates": [
31
+ "sdmx_datasets",
32
+ "sdmx_series_{agency}_{dataset_id}",
33
+ ],
34
+ "plugin_version": __version__,
35
+ }
36
+
37
+
38
+ __all__ = [
39
+ "CONNECTORS",
40
+ "ENV_VARS",
41
+ "PROVIDER_METADATA",
42
+ "__version__",
43
+ ]
@@ -0,0 +1,95 @@
1
+ """Plan generators for ``parsimony.bundles`` discovery.
2
+
3
+ The new bundle pipeline (``parsimony.bundles``) drives every plugin's
4
+ publish flow through ``CatalogDynamicSpec.plan`` — an async generator
5
+ that yields one :class:`~parsimony.bundles.CatalogPlan` per bundle the
6
+ plugin wants built. SDMX has thousands of per-dataset series bundles, so
7
+ the plan generator walks the on-disk flat-catalog parquet files and
8
+ emits one plan item per ``(agency, dataset_id)`` pair.
9
+
10
+ The on-disk root is :data:`DEFAULT_OUTPUTS_ROOT` (sibling to the package),
11
+ overridable via the ``PARSIMONY_SDMX_OUTPUTS_ROOT`` env var. Missing
12
+ agencies are silently skipped — callers running ``parsimony bundles
13
+ plan`` against a workspace where only one agency has been built locally
14
+ should see only that agency's bundles.
15
+
16
+ This module is import-cheap: it imports ``pyarrow`` lazily inside
17
+ :func:`plan_sdmx_series` so importing the plugin's surface (which the
18
+ ``parsimony list-plugins`` discovery does eagerly) doesn't pay arrow's
19
+ cost when no one is publishing yet.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import os
25
+ from collections.abc import AsyncIterator
26
+ from pathlib import Path
27
+
28
+ from parsimony.bundles import CatalogPlan
29
+
30
+ from parsimony_sdmx.connectors._agencies import (
31
+ ALL_AGENCIES,
32
+ AgencyId,
33
+ to_namespace_token,
34
+ )
35
+
36
+
37
+ def _outputs_root() -> Path:
38
+ """Resolve the flat-catalog outputs root from env var or default.
39
+
40
+ The default is imported lazily — :mod:`parsimony_sdmx.connectors.enumerate_datasets`
41
+ pulls in pyarrow+pandas at module load, which we don't want when the
42
+ plan generator is only being inspected (e.g. by the discovery walk).
43
+ """
44
+ env = os.environ.get("PARSIMONY_SDMX_OUTPUTS_ROOT")
45
+ if env:
46
+ return Path(env)
47
+ from parsimony_sdmx.connectors.enumerate_datasets import DEFAULT_OUTPUTS_ROOT
48
+
49
+ return DEFAULT_OUTPUTS_ROOT
50
+
51
+
52
+ def _series_namespace(agency: AgencyId, dataset_id: str) -> str:
53
+ """Compose the per-dataset series namespace from agency + dataset id.
54
+
55
+ The template literal is inlined here (rather than imported from
56
+ :mod:`parsimony_sdmx.connectors.enumerate_series`) to avoid a
57
+ circular import — ``enumerate_series`` declares ``catalog=`` with
58
+ a callable that lives in this module.
59
+ """
60
+ return f"sdmx_series_{to_namespace_token(agency)}_{dataset_id.lower()}"
61
+
62
+
63
+ async def plan_sdmx_series() -> AsyncIterator[CatalogPlan]:
64
+ """Yield one plan per ``(agency, dataset_id)`` pair found on disk.
65
+
66
+ Reads each agency's ``outputs/{AGENCY}/datasets.parquet`` and emits a
67
+ :class:`CatalogPlan` for every row. Empty / absent agency files are
68
+ skipped silently — local workspaces don't always have every agency.
69
+
70
+ Plan params shape::
71
+
72
+ {"agency": "ECB", "dataset_id": "YC"}
73
+
74
+ These map 1:1 to :class:`~parsimony_sdmx.connectors.enumerate_series.EnumerateSeriesParams`
75
+ so the ``parsimony bundles`` runner adapter constructs the model
76
+ directly via ``EnumerateSeriesParams(**plan.params)``.
77
+ """
78
+ import pyarrow.parquet as pq
79
+
80
+ root = _outputs_root()
81
+ for agency in ALL_AGENCIES:
82
+ path = root / agency.value / "datasets.parquet"
83
+ if not path.exists():
84
+ continue
85
+ table = pq.read_table(path, columns=["dataset_id"])
86
+ for dataset_id in table.column("dataset_id").to_pylist():
87
+ yield CatalogPlan(
88
+ namespace=_series_namespace(agency, dataset_id),
89
+ params={"agency": agency.value, "dataset_id": dataset_id},
90
+ )
91
+
92
+
93
+ __all__ = [
94
+ "plan_sdmx_series",
95
+ ]