Comtrade Trade Data
comtrade_trade_dataAUTHORITATIVE bilateral trade data between two countries from UN Comtrade — the official international-trade statistics database (every country's customs filings, harmonized). Returns trade values USD, quantities, and HS commodity-level detail for imports and exports between reporter + partner. Use for "how much X did US import from China in 2024", "what does Germany export to Brazil", "Mexico's top trade partners by commodity", or "how did Saudi–Egypt trade move this year" (pass frequency="monthly" for month-by-month, not just last year's annual total). UN Comtrade reporter/partner codes (842=US — Comtrade uses 842, NOT the ISO 840; 156=China, 276=Germany, 0=World — see comtrade_country_codes). Defaults to ANNUAL data (lags ~3 months from reporting period); pass frequency="monthly" for month-level data (lags more and some reporters never file monthly — a missing month is simply absent from the result, never shown as a zero). Every response states its own "frequency" so a monthly figure is never mistaken for an annual one.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hs | No | Alias for hs_code — HS commodity code. Use this OR hs_code, not both. | |
| flow | No | Trade flow: "M" for imports, "X" for exports. Optional — defaults to both "M,X". | |
| year | Yes | Trade period. For frequency="annual" (default): a year, e.g. "2024". For frequency="monthly": year+month as YYYYMM, e.g. "202401" for January 2024. | |
| hs_code | No | HS commodity code at 2/4/6 digit level (e.g., "8471" for computers, "2603" for copper ores). Optional — omit for all commodities. Aliases accepted: commodity_code, commodity, hs, cmd_code (pass exactly one of hs_code/commodity_code/commodity/hs/cmd_code — do not need hs_code as well). | |
| cmd_code | No | Alias for hs_code — HS commodity code. Use this OR hs_code, not both. | |
| commodity | No | Alias for hs_code — HS commodity code. Use this OR hs_code, not both. | |
| frequency | No | Data frequency: "annual" (default) for yearly totals, or "monthly" for month-level data. Monthly coverage is thinner than annual — not every reporter files monthly, and recent months lag by reporter; a country-month with no filing is simply omitted from the results, not returned as zero. When "monthly", pass `year` as YYYYMM. | |
| partner_code | Yes | Partner country name (e.g. "China") or UN code (156=China, 0=World). Optional — defaults to World (0). Names resolved automatically. | |
| reporter_code | Yes | Country name (e.g. "USA", "China", "Germany") or UN numeric code (US=842, China=156). Names are resolved automatically. | |
| commodity_code | No | Alias for hs_code — HS commodity code (e.g. "2603" for copper ores). Use this OR hs_code, not both. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | No | Trade year queried | |
| count | No | Number of trade records returned | |
| records | No |