pip install datapungi_fed
datapungi_fed
datapungi_fed is a Python interface to the
FRED and
GeoFRED APIs. It fetches Federal Reserve
economic data and returns clean pandas DataFrames, together with the raw
request and a reproducible code snippet upon demand.
Key features
- One-line access to any FRED time series:
dpf.ts('GDP') - Full access to all FRED and GeoFRED endpoints through quick entry points tracking FRED's structure (eg. "dpf.series.tags('GDP')")
- Optional verbose output: DataFrame + raw
requests.Response+ reproducible code - API keys handled through environment variables, or passed strings.
Quick start
The FRED API is built around a dataset called "series" of hundreds of thousands of time-series. This package provides a quick access to it:
import datapungi_fed as dpf
# Can request one or more variables at once
series = dpf.ts('GDP')
print(series.tail())
series = dpf.ts(['GDP','GNP'])
print(series.tail())
# some metadata is already provided
print(series.attrs['meta']) # response metadata
Output:
GDP
2024-01-01 27939.0
2024-04-01 28202.8
2024-07-01 28488.5
2024-10-01 28949.2
Setting up the API key
You need a free FRED API key from https://research.stlouisfed.org/docs/api/api_key.html.
Recommended: environment variable
export API_KEY_FED=your_key_here
Pass directly
import datapungi_fed as dpf
client = dpf.Client(api_key='your_key_here')
Use an environment variable
import datapungi_fed as dpf
client = dpf.Client() # reads API_KEY_FED from the environment
Store in a file
import json
import datapungi_fed as dpf
with open('/path/to/key.json') as f:
client = dpf.Client(api_key=json.load(f)['API_KEY_FED'])
Module-level shortcuts like dpf.ts('GDP') still work as long as
API_KEY_FED is set in the environment.
Working with data
Available database groups:
| FRED database group | description |
|---|---|
| categories | Categories of datasets - 8 top categories (eg, National Accounts, Prices) that break down into subgroups |
| releases | Release groups of data - about 300 (eg, Western Hemisphere Regional Economic Outlook, Penn World Table) |
| series | About 600,000 time series provided by various sources |
| sources | List of data sources - about 90 data providers (eg, IMF and Bank of Mexico) |
| tags | Tags applied to time series (eg, location, data source, frequency) - about 5,000 tags |
| geo | Harvest data and shape files found in GeoFRED |
| datasetlist | list of all (FRED and GeoFRED) databases |
The above "dpf.ts('GDP')" calls are quick taps to the "dpf.series" data.
series
The series datasets provides data and metadata information on a specific time-series, besides searching tools.
Available databases in the series group:
| database | Description |
|---|---|
| series | metadata of a series |
| search | search for a series |
| observations | actual series data |
| categories | FED categories associated to the series |
| release | The release table of the series |
| tags | Tags associated to the series |
| updates | List of series updated (at given parameters) |
| vintagedates | Dates when a series were updated |
For example:
# the following are the same, they all call dpf.series.observations:
dpf.ts('gdp')
dpf.series('gdp')
dpf.series.observations('gdp')
# metadata
dpf.series.series('gdp')
# search
dpf.series.search('GDP deflator for the US')
dpf.series.search(search_text='monetary+service+index')
dpf.series.search.tags(series_search_text='monetary+service+index')
dpf.series.search.related_tags(series_search_text='mortgage+rate', tag_names='30-year;frb')
See what is available
import datapungi_fed as dpf
dpf.datasetlist()
Explore categories, releases, sources, and tags
There are hundreds of thousands of time-series available at the FRED API, navigating them is non-trivial. Navigate via internal FED classification scheme
import datapungi_fed as dpf
# This is a graph, with starting point "0" which you can navigate with:
# - use the children function to find the category of interest
# - once there, use the series function to get the list of series of that category
dpf.category.children(0) #get the children categories of the starting point,
dpf.category.series(32442)
dpf.category(32442) # get info on the 32442 category
Navigate via information on the release information
import datapungi_fed as dpf
dpf.release() # all 337 or so release sources (eg, id=1132, name = Dallas Fed Energy Survey)
Explore also via tags and sources with "dpf.tag" and "dpf.source"
dpf.tags.tags(tag_names='monetary+aggregates;weekly')
dpf.tags.related_tags(tag_names='monetary+aggregates;weekly')
dpf.tags.tags.series(tag_names='slovenia;food;oecd')
Get GeoFRED data
import datapungi_fed as dpf
dpf.geo(series_id='WIPCPI')
dpf.geo.shapes('bea')
dpf.geo.meta(series_id='SMU56000000500000001')
dpf.geo(series_id='WIPCPI', start_date='2012-01-01')
dpf.geo.data(series_group='882', date='2013-01-01', region_type='state', units='Dollars', frequency='a', season='NSA')
Code snippets
Use verbose=True to get the raw request and a standalone code snippet:
import datapungi_fed as dpf
result = dpf.series('GNP', verbose=True)
result['dataFrame'] # pandas DataFrame
result['request'] # requests.Response
result['code'] # string of code that reproduces the query
Running tests
The tests are recorded with pytest-recording/vcrpy. Cassettes are
committed, so the suite runs without a real API key by default.
# Run the full test suite (no API key needed)
pytest datapungi_fed/tests
# CI-friendly subset
pytest -q datapungi_fed/tests/test_driversCI.py
# Full suite
pytest datapungi_fed/tests/test_drivers.py
# Re-record cassettes (requires a real key)
API_KEY_FED=your_key pytest datapungi_fed/tests
Or from Python:
import datapungi_fed as dpf
dpf.tests.runTests() # opens HTML report in a browser
Requirements
- Python >= 3.13
- requests, pandas, pyyaml
License
MIT
Metadata
Release files for datapungi-fed 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datapungi_fed-0.5.0.tar.gz | 1.2 MB | Without provenance | Details for datapungi_fed-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datapungi_fed-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for datapungi_fed-0.5.0-py3-none-any.whl |
Total release size: 2.6 MB
Release files / datapungi_fed-0.5.0.tar.gz
| Download URL | datapungi_fed-0.5.0.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb41e9ba6612b86841fed14be102c8b2beea09a5dde8ae127d8e1e9edfb6845e
|
|
BLAKE2b-256 checksum How to use checksums |
8fb0da4c192d4cf5c21a4168491077dc8d85f7f4c8335b48b9d81ebbd274ae19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.34.2
|
Release files / datapungi_fed-0.5.0-py3-none-any.whl
| Download URL | datapungi_fed-0.5.0-py3-none-any.whl |
|---|---|
| Size | 1.4 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d71d3472d7d8346a663bbd7f91847fc6611f8393df46d169ea0ecaa08bd2b39e
|
|
BLAKE2b-256 checksum How to use checksums |
cba41a5eba3880c6f4e369034a4a0e9ab33a33275bafbc8dcae37686f797f568
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.34.2
|
Security for datapungi-fed 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.