parsimony-bdp 0.0.1__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.
@@ -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
+ logs/
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,71 @@
1
+ # Changelog — parsimony-bdp
2
+
3
+ All notable changes to `parsimony-bdp` will be documented in this file. The
4
+ format is based on [Keep a Changelog](https://keepachangelog.com/) and
5
+ this project adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.8.0] — 2026-06-09
8
+
9
+ Ground-up refactor, run through the full connector guidebook process and
10
+ **live-verified** against the production BPstat API (keyless).
11
+
12
+ ### Fixed
13
+
14
+ - **Completeness: the datasets list is now paginated.** `/domains/{id}/datasets/`
15
+ caps at 10 items per page; the previous enumerator read only page 1, so the 3
16
+ domains with more than 10 datasets (domain 19 has 25) silently lost datasets —
17
+ and every series in them. The crawl now follows `extension.next_page`
18
+ (`page_size=100`). Verified: domain 19 recovers all 25 datasets / 4,094 series,
19
+ domain 1 recovers all 16,644 series — both exact matches to the declared counts.
20
+
21
+ ### Changed
22
+
23
+ - **Leaner per-dataset crawl.** The dataset-detail crawl now uses
24
+ `page_size=100&obs_last_n=1` (100 series/page with a one-point observation
25
+ array, ~70 KB) instead of the default 10 series/page with full observation
26
+ history. This cuts the universe crawl from ~7,200 pages to ~720 and removes the
27
+ 502s a naive `page_size=100` triggered on large datasets.
28
+ - **Bilingual catalog via a `/series/` enrichment pass.** The crawl now only
29
+ discovers ids + terse English labels; the rich, search-bearing descriptions
30
+ come from a build-time `/series/?series_ids=` pass (100 ids/call) in **English
31
+ and Portuguese**. English is the primary search signal; Portuguese folds into
32
+ the indexed `description` for cross-language recall on the BM25 index. Batched,
33
+ retried, split-on-failure.
34
+ - **Package restructured** into `_http` / `outputs` / `enrich` / `connectors/
35
+ {fetch,enumerate,_catalog}` / `search` / `catalog_build`, mirroring the `bde`
36
+ exemplar; the top-level surface stays `CONNECTORS`. The monolithic 843-line
37
+ `__init__.py` is gone.
38
+ - **Enumerator schema simplified.** Dropped the fragile JSON-stat-dimension-derived
39
+ `frequency` / `units` / `start_date` / `end_date` columns (frequency is a
40
+ per-series dimension, not a dataset property; the frequency/unit words now ride
41
+ in the prose `description` in both languages). Added `short_label` and a
42
+ per-dataset / per-domain `num_series`.
43
+ - `bdp_fetch` validates `start_date` / `end_date` as ISO dates pre-network
44
+ (`InvalidParameterError`) and tolerates null observation values.
45
+ - The enumerator self-checks each crawled dataset against its declared
46
+ `num_series` and logs any shortfall.
47
+
48
+ ### Added
49
+
50
+ - `catalog_tests/queries.yaml` recall gate (exact `code:` + lexical title probes)
51
+ and `tests/test_build_catalog.py` index-policy test.
52
+
53
+ ## [0.5.0] — 2026-05-06
54
+
55
+ ### Changed
56
+
57
+ - Adapted to `parsimony-core==0.5`. Connector code no longer constructs `Provenance` directly; the framework authors all provenance fields in `Connector._wrap_result`. Source-specific extras (where present) move to `Result.with_properties(**kwargs)`. Drops the `provenance=` and `params=` kwargs from `OutputConfig.build_table_result` / `Result.from_dataframe` call sites.
58
+ - Bump `parsimony-core` pin from `>=0.4.0,<0.5` to `>=0.5.0,<0.6` (and `[standard-onnx]` extra accordingly on catalog-publishing packages).
59
+ ## [0.4.0] — 2026-04-24
60
+
61
+ Part of the first coordinated release of the
62
+ [`parsimony-connectors`](https://github.com/ockham-sh/parsimony-connectors)
63
+ monorepo under `parsimony-core==0.4`.
64
+
65
+ ### Changed
66
+
67
+ - Connector rewritten against the kernel's `parsimony.discover` surface
68
+ (`iter_providers`, `load`, `load_all`) and the `@connector(env=...)`
69
+ decorator-level env-var declaration that replaced module-level
70
+ `ENV_VARS`.
71
+ - Pin bumped to `parsimony-core>=0.4,<0.5`.
@@ -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,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: parsimony-bdp
3
+ Version: 0.0.1
4
+ Summary: Banco de Portugal connector for the parsimony framework
5
+ Project-URL: Homepage, https://www.bportugal.pt
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: bdp,connectors,data,finance,parsimony
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: pandas<3,>=2.3.0
25
+ Requires-Dist: parsimony-core[catalog]>=0.0.1
26
+ Requires-Dist: parsimony-shared>=0.0.1
27
+ Requires-Dist: pydantic<3,>=2.11.1
28
+ Provides-Extra: dev
29
+ Requires-Dist: mypy>=1.10; extra == 'dev'
30
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
31
+ Requires-Dist: pytest>=9.0.3; extra == 'dev'
32
+ Requires-Dist: respx>=0.22.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.15.10; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # parsimony-bdp
37
+
38
+ Banco de Portugal connector — Portuguese macroeconomic, monetary, financial, and
39
+ external time series via the BPstat (JSON-stat) API.
40
+
41
+ Part of the [parsimony-connectors](https://github.com/ockham-sh/parsimony-connectors) monorepo. Distributed standalone on PyPI as `parsimony-bdp`.
42
+
43
+ ## Connectors
44
+
45
+ | Name | Kind | Description |
46
+ |---|---|---|
47
+ | `bdp_fetch` | connector | Fetch Banco de Portugal observations by `domain_id` + `dataset_id` (optional `series_ids` filter and date window). |
48
+ | `enumerate_bdp` | enumerator | Crawl the full BPstat universe (~72 K series across 212 datasets / 65 leaf domains) for catalog discovery. |
49
+ | `bdp_search` | connector | Semantic-search the published BdP catalog snapshot; returns ranked series codes. |
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pip install parsimony-bdp
55
+ ```
56
+
57
+ Pulls in `parsimony-core>=0.7,<0.8` automatically. Verify discovery:
58
+
59
+ ```bash
60
+ python -c "from parsimony import discover; print([p.name for p in discover.iter_providers()])"
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ No configuration required — the BPstat API is open and unauthenticated.
66
+
67
+ `bdp_search` reads a published catalog snapshot (default `hf://parsimony-dev/bdp`).
68
+ Override the snapshot location with the `PARSIMONY_BDP_CATALOG_URL` environment
69
+ variable, or pass `catalog_url=` at call time.
70
+
71
+ ## Quick start
72
+
73
+ ```python
74
+ from parsimony_bdp import CONNECTORS
75
+
76
+ # Discover via bdp_search, then fetch. A search hit's code splits as
77
+ # domain_id:dataset_id:series_id.
78
+ hits = CONNECTORS["bdp_search"](query="economic activity coincident indicator")
79
+ code = hits.data.iloc[0]["code"] # e.g. "48:aea9…:12099329"
80
+ domain_id, dataset_id, series_id = code.split(":")
81
+ result = CONNECTORS["bdp_fetch"](
82
+ domain_id=int(domain_id), dataset_id=dataset_id, series_ids=series_id
83
+ )
84
+ print(result.data.head())
85
+ ```
86
+
87
+ For multi-plugin composition (autoloads everything installed):
88
+
89
+ ```python
90
+ from parsimony import discover
91
+ connectors = discover.load_all()
92
+ ```
93
+
94
+ ## Catalogs
95
+
96
+ BPstat has no flat "list all series" endpoint, so `enumerate_bdp` walks the
97
+ `domain → dataset → series` hierarchy. Two things make the crawl both complete
98
+ and cheap: it **paginates the datasets list** (domains with >10 datasets would
99
+ otherwise lose series), and it crawls each dataset at `page_size=100&obs_last_n=1`
100
+ (100 series per page with a one-point observation array) — about 720 lean pages
101
+ for the whole universe. Each dataset is self-checked against its declared series
102
+ count. Maintainers then run a bilingual `/series/` enrichment pass (English +
103
+ Portuguese descriptions folded into the catalog `description` for cross-language
104
+ recall), build a `Catalog` snapshot (`scripts/build_catalog.py`), and push it to
105
+ the snapshot URL `bdp_search` reads — the build runs offline as a publish job,
106
+ never at query time.
107
+
108
+ ## Provider
109
+
110
+ - Homepage: https://www.bportugal.pt
111
+ - BPstat portal: https://bpstat.bportugal.pt
112
+ - API docs: https://bpstat.bportugal.pt/data/docs
113
+
114
+ ## License
115
+
116
+ See [LICENSE](./LICENSE).
@@ -0,0 +1,81 @@
1
+ # parsimony-bdp
2
+
3
+ Banco de Portugal connector — Portuguese macroeconomic, monetary, financial, and
4
+ external time series via the BPstat (JSON-stat) API.
5
+
6
+ Part of the [parsimony-connectors](https://github.com/ockham-sh/parsimony-connectors) monorepo. Distributed standalone on PyPI as `parsimony-bdp`.
7
+
8
+ ## Connectors
9
+
10
+ | Name | Kind | Description |
11
+ |---|---|---|
12
+ | `bdp_fetch` | connector | Fetch Banco de Portugal observations by `domain_id` + `dataset_id` (optional `series_ids` filter and date window). |
13
+ | `enumerate_bdp` | enumerator | Crawl the full BPstat universe (~72 K series across 212 datasets / 65 leaf domains) for catalog discovery. |
14
+ | `bdp_search` | connector | Semantic-search the published BdP catalog snapshot; returns ranked series codes. |
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pip install parsimony-bdp
20
+ ```
21
+
22
+ Pulls in `parsimony-core>=0.7,<0.8` automatically. Verify discovery:
23
+
24
+ ```bash
25
+ python -c "from parsimony import discover; print([p.name for p in discover.iter_providers()])"
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ No configuration required — the BPstat API is open and unauthenticated.
31
+
32
+ `bdp_search` reads a published catalog snapshot (default `hf://parsimony-dev/bdp`).
33
+ Override the snapshot location with the `PARSIMONY_BDP_CATALOG_URL` environment
34
+ variable, or pass `catalog_url=` at call time.
35
+
36
+ ## Quick start
37
+
38
+ ```python
39
+ from parsimony_bdp import CONNECTORS
40
+
41
+ # Discover via bdp_search, then fetch. A search hit's code splits as
42
+ # domain_id:dataset_id:series_id.
43
+ hits = CONNECTORS["bdp_search"](query="economic activity coincident indicator")
44
+ code = hits.data.iloc[0]["code"] # e.g. "48:aea9…:12099329"
45
+ domain_id, dataset_id, series_id = code.split(":")
46
+ result = CONNECTORS["bdp_fetch"](
47
+ domain_id=int(domain_id), dataset_id=dataset_id, series_ids=series_id
48
+ )
49
+ print(result.data.head())
50
+ ```
51
+
52
+ For multi-plugin composition (autoloads everything installed):
53
+
54
+ ```python
55
+ from parsimony import discover
56
+ connectors = discover.load_all()
57
+ ```
58
+
59
+ ## Catalogs
60
+
61
+ BPstat has no flat "list all series" endpoint, so `enumerate_bdp` walks the
62
+ `domain → dataset → series` hierarchy. Two things make the crawl both complete
63
+ and cheap: it **paginates the datasets list** (domains with >10 datasets would
64
+ otherwise lose series), and it crawls each dataset at `page_size=100&obs_last_n=1`
65
+ (100 series per page with a one-point observation array) — about 720 lean pages
66
+ for the whole universe. Each dataset is self-checked against its declared series
67
+ count. Maintainers then run a bilingual `/series/` enrichment pass (English +
68
+ Portuguese descriptions folded into the catalog `description` for cross-language
69
+ recall), build a `Catalog` snapshot (`scripts/build_catalog.py`), and push it to
70
+ the snapshot URL `bdp_search` reads — the build runs offline as a publish job,
71
+ never at query time.
72
+
73
+ ## Provider
74
+
75
+ - Homepage: https://www.bportugal.pt
76
+ - BPstat portal: https://bpstat.bportugal.pt
77
+ - API docs: https://bpstat.bportugal.pt/data/docs
78
+
79
+ ## License
80
+
81
+ See [LICENSE](./LICENSE).
@@ -0,0 +1,20 @@
1
+ """Banco de Portugal (BdP): fetch + catalog enumeration.
2
+
3
+ Keyless BPstat (Opendatasoft-independent JSON-stat API).
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from parsimony.connector import Connectors
9
+
10
+ from parsimony_bdp.connectors import CONNECTORS
11
+
12
+
13
+ def load(*, catalog_url: str | None = None) -> Connectors:
14
+ """Return :data:`CONNECTORS` with an optional catalog URL bound on search."""
15
+ if catalog_url is None:
16
+ return CONNECTORS
17
+ return CONNECTORS.bind(catalog_url=catalog_url)
18
+
19
+
20
+ __all__ = ["CONNECTORS", "load"]
@@ -0,0 +1,52 @@
1
+ """Banco de Portugal (BPstat) transport constants and throttling config.
2
+
3
+ BPstat is a **keyless** public JSON API (no api_key, no auth header). The base
4
+ is a JSON-stat 2.0 hierarchy ``domain → dataset → series``.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from parsimony_shared.cb_enumerate import MetadataCrawlConfig
10
+
11
+ BASE_URL = "https://bpstat.bportugal.pt/data/v1"
12
+
13
+ # BPstat sits behind Akamai. A browser User-Agent plus Origin/Referer headers
14
+ # keep both the per-call fetch and the bulk crawl from being challenged.
15
+ BROWSER_USER_AGENT = (
16
+ "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
17
+ "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
18
+ )
19
+ HEADERS = {
20
+ "User-Agent": BROWSER_USER_AGENT,
21
+ "Accept": "application/json",
22
+ "Origin": "https://bpstat.bportugal.pt",
23
+ "Referer": "https://bpstat.bportugal.pt/",
24
+ }
25
+
26
+ # Conservative throttle for the bulk enumeration crawl. Akamai may answer 403
27
+ # under load, so it is in the retry set alongside 429/5xx.
28
+ METADATA_CRAWL = MetadataCrawlConfig(
29
+ inter_request_delay_s=0.25,
30
+ retry_statuses=frozenset({403, 429, 500, 502, 503, 504}),
31
+ )
32
+
33
+ # Both list endpoints cap ``page_size`` at 100 (101+ → HTTP 400). For the
34
+ # dataset-detail crawl, ``page_size=100`` alone 502s on a big dataset because
35
+ # the observation ``value`` array gets too large — pairing it with
36
+ # ``obs_last_n=1`` shrinks that array to one point per series, so the 100-series
37
+ # page succeeds (~70 KB). The crawl only needs the series ids + labels anyway.
38
+ DATASET_PAGE_SIZE = 100
39
+ DATASET_CRAWL_PARAMS = {"page_size": DATASET_PAGE_SIZE, "obs_last_n": 1}
40
+
41
+ # ``/series/?series_ids=`` accepts at most 100 ids per call.
42
+ SERIES_BATCH = 100
43
+
44
+ VALID_LANGS = frozenset({"en", "pt"})
45
+
46
+ # Defensive page-cap so a runaway ``next_page`` cycle can't exhaust the process.
47
+ # The largest real dataset is 16,644 series → 167 pages at page_size=100; 2,000
48
+ # pages (200 K series) is far above anything BPstat publishes.
49
+ MAX_PAGES_PER_DATASET = 2_000
50
+
51
+ # Cap descriptions before the embedder sees them (context-window safety).
52
+ DESCRIPTION_CHAR_CAP = 1500
@@ -0,0 +1,50 @@
1
+ """Build the Banco de Portugal catalog snapshot.
2
+
3
+ Maintainer tooling, not part of the plugin contract: ``enumerate_bdp`` crawls
4
+ the full BPstat hierarchy (ids + terse English labels), then a bilingual
5
+ ``/series/`` enrichment pass overlays the rich EN + PT descriptions (EN as the
6
+ primary search signal, PT folded in for Portuguese recall on the BM25 index).
7
+ The enriched rows become catalog entities and the catalog is indexed and built.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from parsimony.catalog import Catalog
13
+ from parsimony.catalog.policy import discovery_indexes
14
+ from parsimony.catalog.source import entities_from_raw
15
+
16
+ from parsimony_bdp.connectors._catalog import apply_enrichment, series_id_from_code
17
+ from parsimony_bdp.connectors.enumerate import enumerate_bdp
18
+ from parsimony_bdp.enrich import fetch_series_metadata
19
+ from parsimony_bdp.outputs import BDP_ENUMERATE_OUTPUT
20
+
21
+ CATALOG_NAMESPACE = "bdp"
22
+
23
+
24
+ async def build_bdp_catalog(*, enrich: bool = True) -> Catalog:
25
+ """Enumerate the full BdP universe and build a searchable catalog snapshot.
26
+
27
+ ``enrich`` (default on) runs the bilingual ``/series/`` metadata pass; set it
28
+ ``False`` for a fast crawl-only smoke build (English labels only).
29
+ """
30
+ result = enumerate_bdp()
31
+ df = result.data
32
+
33
+ if enrich and not df.empty:
34
+ series_ids = [
35
+ sid
36
+ for code in df.loc[df["entity_type"] == "series", "code"].tolist()
37
+ if (sid := series_id_from_code(str(code))) is not None
38
+ ]
39
+ enrich_en = await fetch_series_metadata(series_ids, lang="EN")
40
+ enrich_pt = await fetch_series_metadata(series_ids, lang="PT")
41
+ df = apply_enrichment(df, enrich_en=enrich_en, enrich_pt=enrich_pt)
42
+
43
+ entries = entities_from_raw(df, BDP_ENUMERATE_OUTPUT)
44
+ catalog = Catalog(CATALOG_NAMESPACE, indexes=discovery_indexes(entries), default_field="title")
45
+ catalog.set_entities(entries)
46
+ catalog.build()
47
+ return catalog
48
+
49
+
50
+ __all__ = ["CATALOG_NAMESPACE", "build_bdp_catalog"]
@@ -0,0 +1,13 @@
1
+ """bdp connector registry."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from parsimony.connector import Connectors
6
+
7
+ from parsimony_bdp.connectors.enumerate import enumerate_bdp
8
+ from parsimony_bdp.connectors.fetch import bdp_fetch
9
+ from parsimony_bdp.search import bdp_search
10
+
11
+ CONNECTORS = Connectors([bdp_fetch, enumerate_bdp, bdp_search])
12
+
13
+ __all__ = ["CONNECTORS"]