A yfinance-style Python client for policyuncertainty.com data
Project description
economicpolicyuncertainty
A Python client for policyuncertainty.com. Fetch any EPU index as a pandas DataFrame, cached locally in SQLite so repeat calls don't re-hit the source.
Installation
pip install economicpolicyuncertainty
With the optional REST server:
pip install economicpolicyuncertainty[server]
Quick start
import economicpolicyuncertainty as pu
import datetime as dt
data = pu.download("UK_DAILY", refresh=True ,start="2021-01-01", end=dt.datetime.now())
print(data)
start
import economicpolicyuncertainty as pu
pu.available() # DataFrame of every series
pu.download("UK_DAILY", refresh=True) # fetch + return DataFrame indexed by date
pu.download("ALL_COUNTRIES_MONTHLY", column="UK") # one country from the panel file
s = pu.Series("UK_DAILY")
s.info # registry metadata dict
s.history(start="2020-01-01", end="2020-12-31") # filtered DataFrame
s.columns() # for wide series, list available columns
s.latest() # most recent record as a dict
s.refresh() # force re-fetch from source
pu.refresh_all() # refresh every series; failures are isolated
Indicators
| Key | Description | Frequency | Coverage |
|---|---|---|---|
US_MONTHLY |
Baker, Bloom & Davis US EPU index | Monthly | 1985 – present |
US_DAILY |
Multi-variant daily US EPU index | Daily | 1985 – present |
UK_DAILY |
UK daily EPU index | Daily | 2001 – present |
ALL_COUNTRIES_MONTHLY |
~24-country EPU panel + global GEPU | Monthly | 1985 – present |
US_CATEGORICAL |
US EPU broken out by policy category | Monthly | 1985 – present |
TRADE_POLICY_UNCERTAINTY |
Daily US trade policy uncertainty (TPU) | Daily | 1985 – present |
MONETARY_POLICY_UNCERTAINTY |
Baker-Bloom-Davis US monetary policy uncertainty | Monthly | 1985 – present |
CLIMATE_POLICY_UNCERTAINTY |
Gavriilidis et al. climate policy uncertainty | Monthly | 1985 – present |
US_STATE_EPU |
State-level EPU, one column per US state | Monthly | 1985 – present |
US_CHINA_TENSION |
Rogers, Sun & Sun US-China tension index | Monthly | 1993 – present |
Multi-column series
ALL_COUNTRIES_MONTHLY, US_CATEGORICAL, and US_STATE_EPU each contain many
columns in a single file. Use column= to filter to one, or .columns() to see
what's available:
s = pu.Series("ALL_COUNTRIES_MONTHLY")
s.columns()
# ['australia', 'brazil', 'canada', 'chile', 'china', 'france',
# 'gepu_current', 'gepu_ppp', 'germany', 'greece', 'india', 'ireland',
# 'italy', 'japan', 'korea', 'mainland_china', 'mexico', 'pakistan',
# 'russia', 'scmp_china', 'singapore', 'spain', 'uk', 'us']
pu.download("ALL_COUNTRIES_MONTHLY", column="uk")
s = pu.Series("US_CATEGORICAL")
s.columns()
# ['1_economic_policy_uncertainty', '2_monetary_policy', '3_taxes',
# '4_government_spending', '5_health_care', '6_national_security',
# '7_entitlement_programs', '8_regulation', '9_trade_policy',
# '10_sovereign_debt_currency_crises', 'financial_regulation',
# 'fiscal_policy_taxes_or_spending']
Column names are lowercased and have spaces replaced with underscores. Pass
either the raw name ("United Kingdom") or the sanitized form ("uk") —
both work.
API reference
pu.available() → DataFrame
Returns a DataFrame listing every series and its metadata (key, frequency, shape, url, notes).
pu.download(key, start=None, end=None, column=None, refresh=False) → DataFrame
Returns the series as a DataFrame indexed by date. Reads from the local cache
by default; pass refresh=True to fetch fresh data first.
pu.Series(key)
Object-oriented interface to a single series.
| Method | Returns |
|---|---|
.history(start, end, column) |
DataFrame |
.columns() |
list of column names (wide series only) |
.latest(column) |
most recent record as a dict |
.refresh() |
re-fetches from source, returns stats dict |
.info |
registry metadata dict |
pu.refresh_all() → list[dict]
Refreshes every series. Each failure is caught individually so one bad URL doesn't block the rest.
Local REST API (optional)
Useful for accessing data from non-Python environments.
python server.py # runs at http://127.0.0.1:5000
Refreshes all series on startup, then daily at 06:00 local time
(REFRESH_HOUR / REFRESH_MINUTE env vars to change it).
| Endpoint | Description |
|---|---|
GET /api/series |
all series + metadata |
GET /api/series/<key> |
data as JSON (?start=&end=&column=) |
GET /api/series/<key>/columns |
available columns for wide series |
GET /api/series/<key>/latest |
most recent record |
POST /api/series/<key>/refresh |
force re-fetch of one series |
POST /api/refresh-all |
force re-fetch of everything |
Handling the source's bot check
The site occasionally serves a JavaScript challenge page to automated requests.
Every fetch tries a browser-header requests session first, then falls back to
cloudscraper. If both fail, download the file manually and feed it in:
from economicpolicyuncertainty import fetch, db, registry
entry = registry.get("UK_DAILY")
with open("UK_Daily_Policy_Data.csv", "rb") as f:
rows = fetch.parse(f.read(), entry)
db.upsert_rows(entry["key"], rows, shape=entry["shape"])
Verifying sources
If a series stops returning data, run:
python check_sources.py
It reports OK <rows> or FAILED <error> for every registry entry. A broken
URL is a one-line fix in policyuncertainty/registry.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file economicpolicyuncertainty-0.1.2.tar.gz.
File metadata
- Download URL: economicpolicyuncertainty-0.1.2.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be5ba12b34d59a2f6368b5868040dbd9de7da275b3e30260bea10aa3771fa4a
|
|
| MD5 |
6f274713f00926271b3efca67e674c47
|
|
| BLAKE2b-256 |
8aaebad69c7436eb6fe2d1c0fe87ca4146b728a04e09cb48bb2775d624e04edc
|
Provenance
The following attestation bundles were made for economicpolicyuncertainty-0.1.2.tar.gz:
Publisher:
publish.yml on conorzen/economicpolicyuncertainty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
economicpolicyuncertainty-0.1.2.tar.gz -
Subject digest:
8be5ba12b34d59a2f6368b5868040dbd9de7da275b3e30260bea10aa3771fa4a - Sigstore transparency entry: 2144648615
- Sigstore integration time:
-
Permalink:
conorzen/economicpolicyuncertainty@eb0f2f2cb3e9602d82a8f65933a9c9e235f6b5df -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/conorzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eb0f2f2cb3e9602d82a8f65933a9c9e235f6b5df -
Trigger Event:
release
-
Statement type:
File details
Details for the file economicpolicyuncertainty-0.1.2-py3-none-any.whl.
File metadata
- Download URL: economicpolicyuncertainty-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c7fb34bf8c93fc868924ef3c930a538a90f4fa9fb19363ba0173eaadd3913a5
|
|
| MD5 |
6190741f8853a7663743084e06b73475
|
|
| BLAKE2b-256 |
f022a54f267cc825296bbd0b3e98ab743acfb8ae22f6b5614076e4e5ae055523
|
Provenance
The following attestation bundles were made for economicpolicyuncertainty-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on conorzen/economicpolicyuncertainty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
economicpolicyuncertainty-0.1.2-py3-none-any.whl -
Subject digest:
6c7fb34bf8c93fc868924ef3c930a538a90f4fa9fb19363ba0173eaadd3913a5 - Sigstore transparency entry: 2144648685
- Sigstore integration time:
-
Permalink:
conorzen/economicpolicyuncertainty@eb0f2f2cb3e9602d82a8f65933a9c9e235f6b5df -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/conorzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eb0f2f2cb3e9602d82a8f65933a9c9e235f6b5df -
Trigger Event:
release
-
Statement type: