Check the setup
- Python 3.10 or newer
- A notebook environment such as Jupyter or Google Colab
- An internet connection
Official merchandise trade statistics for building partner and commodity monitors from a bounded Comtrade extract.
From source to product signal
Comtrade preview returns up to 500 trade records without a key. Start with one reporter, one year, and total merchandise trade. Mirror statistics disagree, confidential HS lines are suppressed, and a preview is not a complete bulk extract.
Install the packages, then run the notebook cell.
python -m pip install pandas requests
import pandas as pd
import requests
response = requests.get(
"https://comtradeplus.un.org/api/preview/C/A/HS",
params={
"reporterCode": 842,
"period": 2023,
"partnerCode": 0,
"cmdCode": "TOTAL",
"flowCode": "X,M",
"maxRecords": 100,
},
timeout=60,
)
response.raise_for_status()
payload = response.json()
trade = pd.DataFrame(payload.get("data", payload))
trade["retrieved_at_utc"] = pd.Timestamp.now(tz="UTC")
print(trade.head())Test a useful signal
Test whether a preview extract can power a bounded trade-balance sketch.
United Nations Statistics Division is an intergovernmental source. Last verified 2026-08-18. Temporal coverage: reporter-specific annual and monthly trade statistics.