parsimony-fred 0.1.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.
- parsimony_fred-0.1.1/.gitignore +40 -0
- parsimony_fred-0.1.1/CHANGELOG.md +17 -0
- parsimony_fred-0.1.1/LICENSE +190 -0
- parsimony_fred-0.1.1/PKG-INFO +90 -0
- parsimony_fred-0.1.1/README.md +55 -0
- parsimony_fred-0.1.1/parsimony_fred/__init__.py +320 -0
- parsimony_fred-0.1.1/parsimony_fred/py.typed +0 -0
- parsimony_fred-0.1.1/pyproject.toml +76 -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,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `parsimony-fred` will be documented here.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] — 2026-04-17
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial release.
|
|
13
|
+
- `fred_search` connector — tool-tagged keyword search.
|
|
14
|
+
- `fred_fetch` connector — observation-level time series fetch with metadata.
|
|
15
|
+
- `enumerate_fred_release` enumerator — catalog indexing for a FRED release.
|
|
16
|
+
- Plugin entry-point registration under `parsimony.providers`.
|
|
17
|
+
- Release-blocking conformance test against `parsimony.testing.assert_plugin_valid`.
|
|
@@ -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,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: parsimony-fred
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: FRED (Federal Reserve Economic Data) connector 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,fred,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<0.3,>=0.1.0a0
|
|
26
|
+
Requires-Dist: pydantic<3,>=2.11.1
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=1.3.0; 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-fred
|
|
37
|
+
|
|
38
|
+
**FRED (Federal Reserve Economic Data) connector for the [parsimony](https://github.com/ockham-sh/parsimony) framework.**
|
|
39
|
+
|
|
40
|
+
## What it does
|
|
41
|
+
|
|
42
|
+
Once installed alongside `parsimony-core`, this plugin is discovered automatically and exposes the following connectors:
|
|
43
|
+
|
|
44
|
+
| Connector | Kind | Tool-tagged | Description |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| `fred_search` | search | ✓ | Keyword search across FRED series (id, title, units, frequency). |
|
|
47
|
+
| `fred_fetch` | fetch | — | Fetch observation-level data for a FRED series by `series_id`. |
|
|
48
|
+
| `enumerate_fred_release` | enumerator | — | Enumerate all series in a FRED release (catalog indexing). |
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install parsimony-core parsimony-fred
|
|
54
|
+
export FRED_API_KEY=<your-key> # https://fred.stlouisfed.org/docs/api/api_key.html
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Verify discovery:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
parsimony list-plugins
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Use
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from parsimony.connectors import build_connectors_from_env
|
|
67
|
+
|
|
68
|
+
connectors = build_connectors_from_env()
|
|
69
|
+
result = await connectors["fred_fetch"](series_id="UNRATE")
|
|
70
|
+
df = result.data # pandas DataFrame
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or via the MCP server (exposes only tool-tagged connectors):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
parsimony mcp serve --tool-only
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv sync --extra dev
|
|
83
|
+
uv run pytest
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Release-blocking conformance test: `uv run pytest tests/test_conformance.py`.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# parsimony-fred
|
|
2
|
+
|
|
3
|
+
**FRED (Federal Reserve Economic Data) connector for the [parsimony](https://github.com/ockham-sh/parsimony) framework.**
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
Once installed alongside `parsimony-core`, this plugin is discovered automatically and exposes the following connectors:
|
|
8
|
+
|
|
9
|
+
| Connector | Kind | Tool-tagged | Description |
|
|
10
|
+
|---|---|---|---|
|
|
11
|
+
| `fred_search` | search | ✓ | Keyword search across FRED series (id, title, units, frequency). |
|
|
12
|
+
| `fred_fetch` | fetch | — | Fetch observation-level data for a FRED series by `series_id`. |
|
|
13
|
+
| `enumerate_fred_release` | enumerator | — | Enumerate all series in a FRED release (catalog indexing). |
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install parsimony-core parsimony-fred
|
|
19
|
+
export FRED_API_KEY=<your-key> # https://fred.stlouisfed.org/docs/api/api_key.html
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Verify discovery:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
parsimony list-plugins
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from parsimony.connectors import build_connectors_from_env
|
|
32
|
+
|
|
33
|
+
connectors = build_connectors_from_env()
|
|
34
|
+
result = await connectors["fred_fetch"](series_id="UNRATE")
|
|
35
|
+
df = result.data # pandas DataFrame
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or via the MCP server (exposes only tool-tagged connectors):
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
parsimony mcp serve --tool-only
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Development
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
uv sync --extra dev
|
|
48
|
+
uv run pytest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Release-blocking conformance test: `uv run pytest tests/test_conformance.py`.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"""FRED (Federal Reserve Economic Data) connector for parsimony.
|
|
2
|
+
|
|
3
|
+
Exports:
|
|
4
|
+
|
|
5
|
+
* :data:`CONNECTORS` — the :class:`parsimony.Connectors` collection exposed
|
|
6
|
+
via the ``parsimony.providers`` entry point. Includes ``fred_search``
|
|
7
|
+
(tool-tagged for MCP) and ``fred_fetch``.
|
|
8
|
+
* :data:`ENV_VARS` — maps the ``api_key`` dependency to ``FRED_API_KEY``.
|
|
9
|
+
* :func:`enumerate_fred_release` — catalog-enumeration connector for
|
|
10
|
+
indexing FRED releases.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from typing import Annotated, Any
|
|
16
|
+
|
|
17
|
+
import pandas as pd
|
|
18
|
+
from parsimony.connector import Connectors, Namespace, connector, enumerator
|
|
19
|
+
from parsimony.errors import EmptyDataError
|
|
20
|
+
from parsimony.result import (
|
|
21
|
+
Column,
|
|
22
|
+
ColumnRole,
|
|
23
|
+
OutputConfig,
|
|
24
|
+
Provenance,
|
|
25
|
+
Result,
|
|
26
|
+
)
|
|
27
|
+
from parsimony.transport.http import HttpClient
|
|
28
|
+
from pydantic import BaseModel, Field, field_validator
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"CONNECTORS",
|
|
32
|
+
"ENV_VARS",
|
|
33
|
+
"PROVIDER_METADATA",
|
|
34
|
+
"FredSearchParams",
|
|
35
|
+
"FredFetchParams",
|
|
36
|
+
"FredEnumerateParams",
|
|
37
|
+
"fred_search",
|
|
38
|
+
"fred_fetch",
|
|
39
|
+
"enumerate_fred_release",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
__version__ = "0.1.0"
|
|
43
|
+
|
|
44
|
+
ENV_VARS: dict[str, str] = {"api_key": "FRED_API_KEY"}
|
|
45
|
+
|
|
46
|
+
PROVIDER_METADATA: dict[str, Any] = {
|
|
47
|
+
"homepage": "https://fred.stlouisfed.org",
|
|
48
|
+
"pricing": "free",
|
|
49
|
+
"rate_limits": "120 requests/min with a free API key",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# ---------------------------------------------------------------------------
|
|
53
|
+
# Parameter models
|
|
54
|
+
# ---------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class FredSearchParams(BaseModel):
|
|
58
|
+
"""Parameters for FRED keyword search."""
|
|
59
|
+
|
|
60
|
+
search_text: str = Field(..., min_length=1, description="Search query")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class FredFetchParams(BaseModel):
|
|
64
|
+
"""Parameters for fetching FRED time series observations."""
|
|
65
|
+
|
|
66
|
+
series_id: Annotated[str, Namespace("fred")] = Field(..., description="FRED series identifier (e.g. GDPC1, UNRATE)")
|
|
67
|
+
observation_start: str | None = Field(default=None, description="Start date (YYYY-MM-DD)")
|
|
68
|
+
observation_end: str | None = Field(default=None, description="End date (YYYY-MM-DD)")
|
|
69
|
+
|
|
70
|
+
@field_validator("series_id")
|
|
71
|
+
@classmethod
|
|
72
|
+
def _non_empty(cls, value: str) -> str:
|
|
73
|
+
stripped = str(value).strip()
|
|
74
|
+
if not stripped:
|
|
75
|
+
raise ValueError("series_id must be non-empty")
|
|
76
|
+
return stripped
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class FredEnumerateParams(BaseModel):
|
|
80
|
+
"""Parameters for enumerating FRED series in a release (catalog indexing)."""
|
|
81
|
+
|
|
82
|
+
release_id: int = Field(..., ge=1, description="FRED release ID")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# ---------------------------------------------------------------------------
|
|
86
|
+
# Output configs
|
|
87
|
+
# ---------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
_FRED_IDENTITY_METADATA: list[Column] = [
|
|
90
|
+
Column(
|
|
91
|
+
name="series_id",
|
|
92
|
+
role=ColumnRole.KEY,
|
|
93
|
+
param_key="series_id",
|
|
94
|
+
namespace="fred",
|
|
95
|
+
),
|
|
96
|
+
Column(name="title", role=ColumnRole.TITLE),
|
|
97
|
+
Column(name="units_short", role=ColumnRole.METADATA),
|
|
98
|
+
Column(name="frequency_short", role=ColumnRole.METADATA),
|
|
99
|
+
Column(name="seasonal_adjustment_short", role=ColumnRole.METADATA),
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
FRED_ENUMERATE_OUTPUT = OutputConfig(
|
|
103
|
+
columns=[
|
|
104
|
+
Column(name="series_id", role=ColumnRole.KEY, namespace="fred"),
|
|
105
|
+
Column(name="title", role=ColumnRole.TITLE),
|
|
106
|
+
Column(name="units_short", role=ColumnRole.METADATA),
|
|
107
|
+
Column(name="frequency_short", role=ColumnRole.METADATA),
|
|
108
|
+
Column(name="seasonal_adjustment_short", role=ColumnRole.METADATA),
|
|
109
|
+
Column(name="release_id", role=ColumnRole.METADATA),
|
|
110
|
+
]
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
FETCH_OUTPUT = OutputConfig(
|
|
114
|
+
columns=[
|
|
115
|
+
*_FRED_IDENTITY_METADATA,
|
|
116
|
+
Column(name="date", dtype="datetime", role=ColumnRole.DATA),
|
|
117
|
+
Column(name="value", dtype="numeric", role=ColumnRole.DATA),
|
|
118
|
+
]
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
SEARCH_COLUMNS = [
|
|
122
|
+
"id",
|
|
123
|
+
"title",
|
|
124
|
+
"units",
|
|
125
|
+
"frequency_short",
|
|
126
|
+
"seasonal_adjustment_short",
|
|
127
|
+
"observation_start",
|
|
128
|
+
"observation_end",
|
|
129
|
+
"last_updated",
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _make_http(api_key: str) -> HttpClient:
|
|
134
|
+
return HttpClient(
|
|
135
|
+
"https://api.stlouisfed.org/fred",
|
|
136
|
+
query_params={"api_key": api_key, "file_type": "json"},
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# ---------------------------------------------------------------------------
|
|
141
|
+
# Connectors
|
|
142
|
+
# ---------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@connector(tags=["macro", "tool"])
|
|
146
|
+
async def fred_search(params: FredSearchParams, *, api_key: str) -> Result:
|
|
147
|
+
"""Keyword search for FRED economic time series.
|
|
148
|
+
|
|
149
|
+
Returns series metadata (id, title, units, frequency).
|
|
150
|
+
Use short, specific queries like 'US unemployment rate' or 'GDPC1'.
|
|
151
|
+
"""
|
|
152
|
+
http = _make_http(api_key)
|
|
153
|
+
response = await http.request(
|
|
154
|
+
"GET",
|
|
155
|
+
"/series/search",
|
|
156
|
+
params={"search_text": params.search_text},
|
|
157
|
+
)
|
|
158
|
+
response.raise_for_status()
|
|
159
|
+
seriess = response.json().get("seriess", [])
|
|
160
|
+
if not seriess:
|
|
161
|
+
raise EmptyDataError(provider="fred", message=f"No series found for: {params.search_text}")
|
|
162
|
+
df = pd.DataFrame(seriess)
|
|
163
|
+
cols = [c for c in SEARCH_COLUMNS if c in df.columns]
|
|
164
|
+
df = df[cols]
|
|
165
|
+
return Result.from_dataframe(
|
|
166
|
+
df,
|
|
167
|
+
Provenance(source="fred", params={"search_text": params.search_text}),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@connector(output=FETCH_OUTPUT, tags=["macro"])
|
|
172
|
+
async def fred_fetch(params: FredFetchParams, *, api_key: str) -> Result:
|
|
173
|
+
"""Fetch FRED time series observations by series_id.
|
|
174
|
+
|
|
175
|
+
Returns date + value columns with rich metadata (title, units, frequency, seasonal adjustment).
|
|
176
|
+
"""
|
|
177
|
+
http = _make_http(api_key)
|
|
178
|
+
series_id = params.series_id
|
|
179
|
+
|
|
180
|
+
req_params: dict[str, Any] = {"series_id": series_id}
|
|
181
|
+
if params.observation_start is not None:
|
|
182
|
+
req_params["observation_start"] = params.observation_start
|
|
183
|
+
if params.observation_end is not None:
|
|
184
|
+
req_params["observation_end"] = params.observation_end
|
|
185
|
+
|
|
186
|
+
obs_response = await http.request("GET", "/series/observations", params=req_params)
|
|
187
|
+
obs_response.raise_for_status()
|
|
188
|
+
obs_data = obs_response.json()["observations"]
|
|
189
|
+
|
|
190
|
+
series_response = await http.request("GET", "/series", params={"series_id": series_id})
|
|
191
|
+
series_response.raise_for_status()
|
|
192
|
+
series_data = series_response.json()["seriess"][0]
|
|
193
|
+
|
|
194
|
+
df = pd.DataFrame(obs_data)
|
|
195
|
+
df["series_id"] = series_id
|
|
196
|
+
df["title"] = str(series_data.get("title", ""))
|
|
197
|
+
df["units_short"] = series_data.get("units_short")
|
|
198
|
+
df["frequency_short"] = series_data.get("frequency_short")
|
|
199
|
+
df["seasonal_adjustment_short"] = series_data.get("seasonal_adjustment_short")
|
|
200
|
+
|
|
201
|
+
meta_keys = [
|
|
202
|
+
("id", False),
|
|
203
|
+
("title", False),
|
|
204
|
+
("units", False),
|
|
205
|
+
("units_short", True),
|
|
206
|
+
("frequency", False),
|
|
207
|
+
("frequency_short", False),
|
|
208
|
+
("seasonal_adjustment", False),
|
|
209
|
+
("seasonal_adjustment_short", True),
|
|
210
|
+
("last_updated", False),
|
|
211
|
+
("notes", True),
|
|
212
|
+
]
|
|
213
|
+
metadata_list = [
|
|
214
|
+
{"name": k, "value": str(series_data[k]), "exclude_from_llm_view": excl}
|
|
215
|
+
for k, excl in meta_keys
|
|
216
|
+
if k in series_data
|
|
217
|
+
]
|
|
218
|
+
metadata_list.append(
|
|
219
|
+
{
|
|
220
|
+
"name": "series_url",
|
|
221
|
+
"value": f"https://fred.stlouisfed.org/series/{series_id}",
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
prov_params: dict[str, Any] = {"series_id": series_id}
|
|
226
|
+
if params.observation_start is not None:
|
|
227
|
+
prov_params["observation_start"] = params.observation_start
|
|
228
|
+
if params.observation_end is not None:
|
|
229
|
+
prov_params["observation_end"] = params.observation_end
|
|
230
|
+
|
|
231
|
+
prov = Provenance(
|
|
232
|
+
source="fred",
|
|
233
|
+
params=prov_params,
|
|
234
|
+
properties={"metadata": metadata_list},
|
|
235
|
+
)
|
|
236
|
+
return FETCH_OUTPUT.build_table_result(
|
|
237
|
+
df,
|
|
238
|
+
provenance=prov,
|
|
239
|
+
params=prov_params,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
CONNECTORS = Connectors([fred_search, fred_fetch])
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
# ---------------------------------------------------------------------------
|
|
247
|
+
# Catalog enumeration
|
|
248
|
+
# ---------------------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
async def _fetch_release_series_page(
|
|
252
|
+
http: HttpClient,
|
|
253
|
+
release_id: int,
|
|
254
|
+
*,
|
|
255
|
+
limit: int = 1000,
|
|
256
|
+
offset: int = 0,
|
|
257
|
+
) -> list[dict[str, Any]]:
|
|
258
|
+
params: dict[str, Any] = {
|
|
259
|
+
"release_id": release_id,
|
|
260
|
+
"limit": limit,
|
|
261
|
+
"offset": offset,
|
|
262
|
+
"file_type": "json",
|
|
263
|
+
}
|
|
264
|
+
response = await http.request("GET", "/release/series", params=params)
|
|
265
|
+
response.raise_for_status()
|
|
266
|
+
return response.json().get("seriess") or []
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
async def _enumerate_release_series(
|
|
270
|
+
http: HttpClient,
|
|
271
|
+
release_id: int,
|
|
272
|
+
*,
|
|
273
|
+
page_size: int = 1000,
|
|
274
|
+
) -> list[dict[str, Any]]:
|
|
275
|
+
all_series: list[dict[str, Any]] = []
|
|
276
|
+
offset = 0
|
|
277
|
+
while True:
|
|
278
|
+
batch = await _fetch_release_series_page(http, release_id, limit=page_size, offset=offset)
|
|
279
|
+
if not batch:
|
|
280
|
+
break
|
|
281
|
+
all_series.extend(batch)
|
|
282
|
+
if len(batch) < page_size:
|
|
283
|
+
break
|
|
284
|
+
offset += page_size
|
|
285
|
+
return all_series
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
@enumerator(
|
|
289
|
+
output=FRED_ENUMERATE_OUTPUT,
|
|
290
|
+
tags=["fred"],
|
|
291
|
+
)
|
|
292
|
+
async def enumerate_fred_release(
|
|
293
|
+
params: FredEnumerateParams,
|
|
294
|
+
*,
|
|
295
|
+
api_key: str,
|
|
296
|
+
) -> pd.DataFrame:
|
|
297
|
+
"""Enumerate FRED series for a release (catalog indexing).
|
|
298
|
+
|
|
299
|
+
Return one row per series in the release with id, title, and metadata columns.
|
|
300
|
+
"""
|
|
301
|
+
http = _make_http(api_key)
|
|
302
|
+
seriess = await _enumerate_release_series(http, params.release_id, page_size=1000)
|
|
303
|
+
rows: list[dict[str, Any]] = []
|
|
304
|
+
rid = params.release_id
|
|
305
|
+
for item in seriess:
|
|
306
|
+
series_id = str(item.get("id", "")).strip()
|
|
307
|
+
if not series_id:
|
|
308
|
+
continue
|
|
309
|
+
title = str(item.get("title", "")).strip() or series_id
|
|
310
|
+
rows.append(
|
|
311
|
+
{
|
|
312
|
+
"series_id": series_id,
|
|
313
|
+
"title": title,
|
|
314
|
+
"frequency_short": item.get("frequency_short"),
|
|
315
|
+
"units_short": item.get("units_short"),
|
|
316
|
+
"seasonal_adjustment_short": item.get("seasonal_adjustment_short"),
|
|
317
|
+
"release_id": rid,
|
|
318
|
+
}
|
|
319
|
+
)
|
|
320
|
+
return pd.DataFrame(rows)
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "parsimony-fred"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "FRED (Federal Reserve Economic Data) connector for the parsimony framework"
|
|
5
|
+
authors = [{ name = "Ockham.sh", email = "team@ockham.sh" }]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
keywords = ["finance", "data", "connectors", "parsimony", "fred"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
14
|
+
"License :: OSI Approved :: Apache Software License",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Office/Business :: Financial",
|
|
20
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"parsimony-core>=0.1.0a0,<0.3",
|
|
25
|
+
"pydantic>=2.11.1,<3",
|
|
26
|
+
"pandas>=2.3.0,<3",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = [
|
|
31
|
+
"pytest>=9.0.3",
|
|
32
|
+
"pytest-asyncio>=1.3.0",
|
|
33
|
+
"pytest-cov>=5.0",
|
|
34
|
+
"respx>=0.22.0",
|
|
35
|
+
"ruff>=0.15.10",
|
|
36
|
+
"mypy>=1.10",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://parsimony.dev"
|
|
41
|
+
Repository = "https://github.com/ockham-sh/parsimony-connectors"
|
|
42
|
+
Issues = "https://github.com/ockham-sh/parsimony-connectors/issues"
|
|
43
|
+
|
|
44
|
+
[project.entry-points."parsimony.providers"]
|
|
45
|
+
fred = "parsimony_fred"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
[build-system]
|
|
49
|
+
requires = ["hatchling"]
|
|
50
|
+
build-backend = "hatchling.build"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.wheel]
|
|
53
|
+
packages = ["parsimony_fred"]
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.sdist]
|
|
56
|
+
include = ["parsimony_fred", "README.md", "LICENSE", "CHANGELOG.md"]
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
target-version = "py311"
|
|
60
|
+
line-length = 120
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
64
|
+
|
|
65
|
+
[tool.mypy]
|
|
66
|
+
python_version = "3.11"
|
|
67
|
+
warn_return_any = true
|
|
68
|
+
warn_unused_ignores = true
|
|
69
|
+
ignore_missing_imports = true
|
|
70
|
+
|
|
71
|
+
[tool.pytest.ini_options]
|
|
72
|
+
addopts = "--import-mode=importlib -m 'not integration'"
|
|
73
|
+
asyncio_mode = "auto"
|
|
74
|
+
markers = [
|
|
75
|
+
"integration: hits live APIs (may be slow, requires env vars)",
|
|
76
|
+
]
|