pyfred-client 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.
- pyfred_client-0.2.0/.gitignore +53 -0
- pyfred_client-0.2.0/CHANGELOG.md +201 -0
- pyfred_client-0.2.0/CITATION.cff +31 -0
- pyfred_client-0.2.0/LICENSE +21 -0
- pyfred_client-0.2.0/PKG-INFO +390 -0
- pyfred_client-0.2.0/README.md +367 -0
- pyfred_client-0.2.0/pyproject.toml +247 -0
- pyfred_client-0.2.0/src/pyfred/__init__.py +53 -0
- pyfred_client-0.2.0/src/pyfred/__main__.py +14 -0
- pyfred_client-0.2.0/src/pyfred/core.py +2257 -0
- pyfred_client-0.2.0/src/pyfred/py.typed +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.venv/
|
|
6
|
+
venv/
|
|
7
|
+
.env
|
|
8
|
+
|
|
9
|
+
# Build artifacts
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
|
|
13
|
+
# Tooling caches / reports
|
|
14
|
+
.pytest_cache/
|
|
15
|
+
.mypy_cache/
|
|
16
|
+
.ruff_cache/
|
|
17
|
+
.coverage
|
|
18
|
+
.coverage.*
|
|
19
|
+
coverage.xml
|
|
20
|
+
htmlcov/
|
|
21
|
+
|
|
22
|
+
# Default outputs folder: keep the folder, ignore everything written into it
|
|
23
|
+
outputs/*
|
|
24
|
+
!outputs/.gitkeep
|
|
25
|
+
|
|
26
|
+
# OS / editors
|
|
27
|
+
.DS_Store
|
|
28
|
+
.idea/
|
|
29
|
+
.vscode/
|
|
30
|
+
|
|
31
|
+
# Sphinx docs build output
|
|
32
|
+
docs/_build/
|
|
33
|
+
|
|
34
|
+
# LaTeX build files
|
|
35
|
+
*.aux
|
|
36
|
+
*.log
|
|
37
|
+
*.out
|
|
38
|
+
*.toc
|
|
39
|
+
*.bbl
|
|
40
|
+
*.blg
|
|
41
|
+
*.synctex.gz
|
|
42
|
+
*.fls
|
|
43
|
+
*.fdb_latexmk
|
|
44
|
+
*.bcf
|
|
45
|
+
*.run.xml
|
|
46
|
+
*.nav
|
|
47
|
+
*.snm
|
|
48
|
+
*.lof
|
|
49
|
+
*.lot
|
|
50
|
+
*.xdv
|
|
51
|
+
|
|
52
|
+
# Jupyter
|
|
53
|
+
.ipynb_checkpoints/
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-12-06
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Renamed to `pyfred-client` (was `fred-api`): the PyPI distribution, the console command and
|
|
15
|
+
the repository. The import package stays `pyfred`.
|
|
16
|
+
- Published to PyPI as `pyfred-client`; wrapkit now comes from PyPI (`wrapkit>=0.4,<0.5`).
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- README section "Data and terms" (replaces "Data source & license"): the MIT
|
|
21
|
+
License covers the code only; FRED's terms prohibit storing, caching or
|
|
22
|
+
archiving FRED content, which `update_csv`, `to_parquet` and `--out` files
|
|
23
|
+
do; copyrighted series need their owner's permission. The terms link now
|
|
24
|
+
goes to https://fred.stlouisfed.org/legal.
|
|
25
|
+
- `tests/fixtures/NOTICE.md`: where the fixtures come from.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **Breaking:** Python 3.12 is now the minimum supported version (3.10 reached
|
|
30
|
+
end of life in October 2026); 3.10 and 3.11 users keep the last release that
|
|
31
|
+
supports them (0.1.4). CI runs on 3.12.
|
|
32
|
+
- Lock refreshed; soupsieve 4.x (security fixes).
|
|
33
|
+
- Author contact in `pyproject.toml` and `CITATION.cff` is now the GitHub
|
|
34
|
+
noreply address.
|
|
35
|
+
- FRED's request limit is enforced strictly. `pyfred.RATE_LIMIT` states it:
|
|
36
|
+
120 requests a minute per key
|
|
37
|
+
([errors](https://fred.stlouisfed.org/docs/api/fred/errors.html)) and
|
|
38
|
+
`Crawl-delay: 2` in the API host's robots.txt, so one request every
|
|
39
|
+
2 seconds. The default `requests_per_second` is now `None`, the limit's
|
|
40
|
+
rate (0.5 a second; was 1.5). `None` and `0` no longer turn the throttle
|
|
41
|
+
off, and a faster rate raises the new `pyfred.RateLimitError` (a
|
|
42
|
+
`ValueError`) when the client is built. All clients in a process share
|
|
43
|
+
one budget.
|
|
44
|
+
- A 429 is retried only after a full minute: FRED sends no `Retry-After` and
|
|
45
|
+
counts its limit per minute, so an earlier retry would fall in the same
|
|
46
|
+
window.
|
|
47
|
+
|
|
48
|
+
### Removed
|
|
49
|
+
|
|
50
|
+
- **Breaking:** the on-disk response cache is gone, since FRED's terms
|
|
51
|
+
prohibit storing or caching its content. The `cache_dir` and
|
|
52
|
+
`cache_ttl_hours` arguments of `FredClient`, its `cache_dir` attribute and
|
|
53
|
+
the `pyfred.DEFAULT_CACHE_DIR` constant are removed (passing either
|
|
54
|
+
argument now raises `TypeError`), and the CLI no longer caches. Every call
|
|
55
|
+
now goes to the API, so a repeated call is a new request; each one still
|
|
56
|
+
waits its turn at the strict shared throttle (one request every 2
|
|
57
|
+
seconds). The client still remembers each series' metadata for the tidy
|
|
58
|
+
`unit` column while it lives. The old cache folder, `~/.cache/pyfred`, is
|
|
59
|
+
no longer read or written and can be deleted by hand.
|
|
60
|
+
|
|
61
|
+
## [0.1.4] - 2026-12-01
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- CI runs the live smoke test against the real FRED API, with the
|
|
66
|
+
`FRED_API_KEY` repository secret. Pull requests from forks skip it.
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
- wrapkit is now pinned at
|
|
71
|
+
[v0.2.10](https://github.com/hmorao95/wrapkit/releases/tag/v0.2.10) (was
|
|
72
|
+
v0.2.9): a cached answer whose file time is ahead of the clock is now
|
|
73
|
+
fetched again instead of being served as fresh.
|
|
74
|
+
- `update-csv --start` was dropped when the CSV existed but was empty or held
|
|
75
|
+
only a header, although such a file is written from scratch like a missing
|
|
76
|
+
one. `--start` now applies until the file holds an observation; later runs
|
|
77
|
+
re-fetch from the look-back, as documented.
|
|
78
|
+
- `raw()` (and `fred-api raw`) sent a list or tuple value as its Python repr
|
|
79
|
+
(`['usa', 'm2']`). Lists are now joined as FRED expects: with `;` for
|
|
80
|
+
`tag_names` and `exclude_tag_names`, with `,` otherwise (`vintage_dates`).
|
|
81
|
+
|
|
82
|
+
## [0.1.3] - 2026-11-18
|
|
83
|
+
|
|
84
|
+
### Fixed
|
|
85
|
+
|
|
86
|
+
- On Windows, a clone whose path has non-ASCII characters (such as
|
|
87
|
+
`C:\Users\João\...`) left `pyfred` unimportable when `uv sync` built the
|
|
88
|
+
environment on Python 3.10 or 3.11, which read the editable install's `.pth`
|
|
89
|
+
file in the ANSI code page. The development environment now defaults to
|
|
90
|
+
Python 3.12 (`.python-version`), which reads it as UTF-8. CI still runs the
|
|
91
|
+
checks on 3.10. The README gives workarounds for 3.10 and 3.11.
|
|
92
|
+
|
|
93
|
+
### Security
|
|
94
|
+
|
|
95
|
+
- wrapkit is now pinned at
|
|
96
|
+
[v0.2.9](https://github.com/hmorao95/wrapkit/releases/tag/v0.2.9) (was
|
|
97
|
+
v0.2.6), which brings these fixes:
|
|
98
|
+
- The API key is now also masked in records from `urllib3.connection`,
|
|
99
|
+
`urllib3.poolmanager` and `httpcore`. urllib3 logs the full request URL,
|
|
100
|
+
key included, at WARNING when a response's headers fail to parse. Those
|
|
101
|
+
loggers were not covered, so a script or notebook with root log handlers
|
|
102
|
+
could log the key in clear.
|
|
103
|
+
- Cache entries are written through a temp file created exclusively under a
|
|
104
|
+
random name, owner-only on POSIX. Another account that can write the
|
|
105
|
+
cache directory can no longer redirect the write to another file, and two
|
|
106
|
+
writes of the same entry no longer break each other. An entry that is not
|
|
107
|
+
a regular file is ignored.
|
|
108
|
+
- The CLI's one-line error message is masked by wrapkit too. pyfred
|
|
109
|
+
already masked the key in HTTP and transport errors, so this is a second
|
|
110
|
+
layer; the output is unchanged.
|
|
111
|
+
- Also from v0.2.7 and v0.2.8:
|
|
112
|
+
- Month bounds written `2024-6`, `06/2024`, `Jun 2024` or `2024.06` now
|
|
113
|
+
cover the whole month; as an `end` they used to stop at the month's
|
|
114
|
+
first day.
|
|
115
|
+
- The SDMX month spelling `2024-M06` now means June 2024. It was read as
|
|
116
|
+
1 January 2024, so an `end` bound kept only that day.
|
|
117
|
+
- With `--log-file`, the traceback of a failed command now has the key
|
|
118
|
+
masked as the log lines do. pyfred already re-raises transport errors
|
|
119
|
+
with the key masked, so this too is a second layer.
|
|
120
|
+
- A failed TLS certificate check now fails at once. It used to be retried
|
|
121
|
+
four times, about 15 s of waiting, before the same error.
|
|
122
|
+
- A cache lifetime of 0 now always refetches. An entry written a moment
|
|
123
|
+
earlier could still be served when its file time was a hair ahead of
|
|
124
|
+
the clock.
|
|
125
|
+
- `--out ./data.csv` now writes to the current directory, as a path with
|
|
126
|
+
a folder should; it used to land in `outputs/data.csv`.
|
|
127
|
+
|
|
128
|
+
## [0.1.2] - 2026-11-04
|
|
129
|
+
|
|
130
|
+
### Fixed
|
|
131
|
+
|
|
132
|
+
- wrapkit is now pinned at v0.2.6 (was v0.2.2), which brings these fixes:
|
|
133
|
+
- Codes such as `"NA"` (Namibia) stay text when the stored CSV is read back;
|
|
134
|
+
they used to turn blank, so those rows were re-added as duplicates.
|
|
135
|
+
- Stored numbers read back exactly, so on pandas before 3.1 unchanged values
|
|
136
|
+
no longer count as revisions and rewrite the file on every run.
|
|
137
|
+
- Comparing a column that goes between missing and a value no longer crashes
|
|
138
|
+
the update.
|
|
139
|
+
- A numeric key matches whether it reads `110` or `110.0`, so a revised row
|
|
140
|
+
replaces the stored one instead of being added next to it.
|
|
141
|
+
- A cache entry left half-written by a crash is fetched again instead of
|
|
142
|
+
raising.
|
|
143
|
+
|
|
144
|
+
## [0.1.1] - 2026-11-03
|
|
145
|
+
|
|
146
|
+
### Changed
|
|
147
|
+
|
|
148
|
+
- `.gitignore` now also ignores LaTeX build files (`*.aux`, `*.log`,
|
|
149
|
+
`*.synctex.gz`, `*.fdb_latexmk` and the like) and Jupyter checkpoints
|
|
150
|
+
(`.ipynb_checkpoints/`). No change to the package.
|
|
151
|
+
|
|
152
|
+
## [0.1.0] - 2026-11-03
|
|
153
|
+
|
|
154
|
+
### Added
|
|
155
|
+
|
|
156
|
+
- `FredClient` for the FRED and ALFRED API of the Federal Reserve Bank of
|
|
157
|
+
St. Louis: `observations`, `series`, `search`, `vintage_dates`, `category`,
|
|
158
|
+
`categories`, `category_series`, `releases`, `release`, `release_series`,
|
|
159
|
+
`tags`, any other endpoint (`raw`), the `to_csv`/`to_excel`/`to_parquet`/
|
|
160
|
+
`to_json` writers, `new_observations` and `update_csv`.
|
|
161
|
+
- Observations of several series at once (one request each), with FRED's
|
|
162
|
+
`units` transformations (`UNITS`), `frequency` aggregation (`FREQUENCIES`,
|
|
163
|
+
`AGGREGATIONS`) and inclusive observation periods (`2024`, `2024-Q2`,
|
|
164
|
+
`2024-06`, a day).
|
|
165
|
+
- ALFRED real-time data: `realtime_start`/`realtime_end` (`EARLIEST`,
|
|
166
|
+
`LATEST`), `vintage_dates` (sent 2,000 at a time) and `output_type` 1 to 4
|
|
167
|
+
(`OUTPUT_TYPES`); real-time frames carry the real-time period of every
|
|
168
|
+
value, with `realtime_end` NaT for "still current".
|
|
169
|
+
- Typed frames: values as float64 (FRED's `.` as NaN), days as timestamps,
|
|
170
|
+
`last_updated`/`created` as UTC timestamps; a tidy long frame
|
|
171
|
+
(`tidy=True`) with the unit from the series metadata and the
|
|
172
|
+
transformation; polars output (`as_polars=True`, `polars` extra).
|
|
173
|
+
- Paging at each endpoint's documented maximum `limit` (100,000
|
|
174
|
+
observations, 10,000 vintage dates, 1,000 for the listings).
|
|
175
|
+
- The API key from `api_key` or `FRED_API_KEY`, with a clear error when it
|
|
176
|
+
is missing. It is never logged (log lines are built without it; a redaction
|
|
177
|
+
filter masks it on the package and HTTP loggers), never part of a cache key
|
|
178
|
+
or file name and never quoted in an error message (error answers and
|
|
179
|
+
transport errors are redacted).
|
|
180
|
+
- Incremental CSV updates (long or tidy) that re-fetch a look-back window
|
|
181
|
+
(two years by default) and upsert on series and date, plus
|
|
182
|
+
`realtime_start` for real-time extracts.
|
|
183
|
+
- On-disk JSON cache (12 h), a client-side throttle under FRED's 120 requests
|
|
184
|
+
a minute, retries with back-off.
|
|
185
|
+
- python-fire CLI (`fred-api`) with `observations`, `series`, `search`,
|
|
186
|
+
`vintage-dates`, `category`, `categories`, `category-series`, `releases`,
|
|
187
|
+
`release`, `release-series`, `tags`, `raw` and `update-csv`, `--out` to
|
|
188
|
+
CSV/Excel/Parquet/JSON, `--log-level` and `--log-file`.
|
|
189
|
+
- Shared plumbing from [wrapkit](https://github.com/hmorao95/wrapkit) v0.2.2
|
|
190
|
+
(logging and redaction, cache, retries and throttle, tidy and polars
|
|
191
|
+
helpers, incremental upserts, writers, the CLI runner).
|
|
192
|
+
- Network-mocked test suite with fixtures modelled on the documented
|
|
193
|
+
examples, one opt-in live test (needs a key), Sphinx docs.
|
|
194
|
+
|
|
195
|
+
[Unreleased]: https://github.com/hmorao95/pyfred-client/compare/v0.2.0...HEAD
|
|
196
|
+
[0.2.0]: https://github.com/hmorao95/pyfred-client/compare/v0.1.4...v0.2.0
|
|
197
|
+
[0.1.4]: https://github.com/hmorao95/pyfred-client/compare/v0.1.3...v0.1.4
|
|
198
|
+
[0.1.3]: https://github.com/hmorao95/pyfred-client/compare/v0.1.2...v0.1.3
|
|
199
|
+
[0.1.2]: https://github.com/hmorao95/pyfred-client/compare/v0.1.1...v0.1.2
|
|
200
|
+
[0.1.1]: https://github.com/hmorao95/pyfred-client/compare/v0.1.0...v0.1.1
|
|
201
|
+
[0.1.0]: https://github.com/hmorao95/pyfred-client/releases/tag/v0.1.0
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it using these metadata."
|
|
3
|
+
title: "pyfred-client"
|
|
4
|
+
abstract: >-
|
|
5
|
+
A small Python wrapper for the FRED and ALFRED API of the Federal Reserve Bank of St. Louis. It fetches economic time series into typed long or tidy pandas or polars DataFrames, with FRED's unit transformations and frequency aggregation, real-time periods and vintage dates for revision histories, series search and the category, release and tag listings, incremental CSV updates and a command-line interface.
|
|
6
|
+
type: software
|
|
7
|
+
authors:
|
|
8
|
+
- family-names: "Morão"
|
|
9
|
+
given-names: "Hugo"
|
|
10
|
+
email: "132693995+hmorao95@users.noreply.github.com"
|
|
11
|
+
version: "0.2.0"
|
|
12
|
+
date-released: "2026-12-06"
|
|
13
|
+
license: MIT
|
|
14
|
+
repository-code: "https://github.com/hmorao95/pyfred-client"
|
|
15
|
+
url: "https://github.com/hmorao95/pyfred-client"
|
|
16
|
+
keywords:
|
|
17
|
+
- fred
|
|
18
|
+
- alfred
|
|
19
|
+
- federal reserve
|
|
20
|
+
- economic data
|
|
21
|
+
- real-time data
|
|
22
|
+
- vintages
|
|
23
|
+
- macroeconomics
|
|
24
|
+
- python
|
|
25
|
+
references:
|
|
26
|
+
- type: data
|
|
27
|
+
title: "FRED, Federal Reserve Economic Data, and ALFRED, Archival FRED"
|
|
28
|
+
authors:
|
|
29
|
+
- name: "Federal Reserve Bank of St. Louis"
|
|
30
|
+
url: "https://fred.stlouisfed.org/"
|
|
31
|
+
notes: "Underlying data accessed through this wrapper."
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hugo Morão
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|