Check the setup
- Python 3.10 or newer
- A notebook environment such as Jupyter or Google Colab
- A free EIA API key saved in the EIA_API_KEY environment variable
Weekly U.S. petroleum stocks and related series for building fuel-inventory monitors and energy-market dashboards.
From source to product signal
EIA's petroleum weekly stocks route returns inventory series used in the Weekly Petroleum Status Report. Start with U.S. crude stocks and a short length. These are inventory statistics, not retail pump prices, unless you choose a price route.
Install the packages, then run the notebook cell.
python -m pip install pandas requests
import os
import pandas as pd
import requests
response = requests.get(
"https://api.eia.gov/v2/petroleum/stoc/wstk/data/",
params={
"api_key": os.environ["EIA_API_KEY"],
"frequency": "weekly",
"data[0]": "value",
"facets[duoarea][]": "NUS",
"facets[product][]": "EPC0",
"length": 20,
},
timeout=30,
)
response.raise_for_status()
stocks = pd.DataFrame(response.json()["response"]["data"])
stocks["period"] = pd.to_datetime(stocks["period"])
stocks["value"] = pd.to_numeric(stocks["value"], errors="coerce")
stocks["retrieved_at_utc"] = pd.Timestamp.now(tz="UTC")
print(stocks[["period", "duoarea", "product-name", "value", "units"]].head())Test a useful signal
Test whether a short crude-stocks window can power an inventory-change alert.
U.S. Energy Information Administration is a government source. Last verified 2026-08-17. Temporal coverage: weekly petroleum series with history varying by product.