Check the setup
- Python 3.10 or newer
- A notebook environment such as Jupyter or Google Colab
- A free Census Data API key saved in the CENSUS_API_KEY environment variable
Monthly U.S. import and export statistics for building commodity and partner trade monitors from a bounded Census extract.
From source to product signal
The Census International Trade API returns monthly U.S. imports and exports by HS code and partner. Start with one commodity chapter, one month, and total partners. Values are revised, and a chapter total is not a shipment record.
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.census.gov/data/timeseries/intltrade/imports/hs",
params={
"get": "CTY_NAME,I_COMMODITY,GEN_VAL_MO",
"YEAR": "2024",
"MONTH": "12",
"COMM_LVL": "HS2",
"I_COMMODITY": "27",
"key": os.environ["CENSUS_API_KEY"],
},
timeout=30,
)
response.raise_for_status()
rows = response.json()
trade = pd.DataFrame(rows[1:], columns=rows[0])
trade["GEN_VAL_MO"] = pd.to_numeric(trade["GEN_VAL_MO"], errors="coerce")
trade["retrieved_at_utc"] = pd.Timestamp.now(tz="UTC")
print(trade.head(20))Test a useful signal
Test whether a single HS chapter extract can power a bounded import-dependency monitor.
U.S. Census Bureau is a government source. Last verified 2026-08-17. Temporal coverage: 2010-present monthly statistics.