Trade via the CLI¶
The trade command fetches the canonical trade data from the UN
Comtrade API. Four sub-subcommands cover exports, imports, balance,
and tariffline.
Purpose¶
This page covers each trade sub-subcommand in detail, with flags,
output formats, and shell-composition patterns.
Prerequisites¶
un-comtrade-sdkinstalled.- The
un-comtradescript on yourPATH. - For authenticated endpoints,
UN_COMTRADE_KEYset.
Walkthrough¶
Fetch exports¶
Output (json default):
{
"records": [
{
"ref_period_id": 2022,
"reporter_code": 699,
"partner_code": 0,
"flow_code": "X",
"cmd_code": "TOTAL",
"primary_value": "452684213646.747"
}
],
"aggregate_total": "452684213646.747"
}
Fetch imports¶
Fetch the trade balance¶
Fetch tariffline data¶
Period range¶
HS chapter filter¶
Output formats¶
See CLI → Output formats for the five formats.
Examples¶
A Markdown table of 2022 exports:
A two-decade trend in CSV:
for year in $(seq 2010 2023); do
un-comtrade trade exports --reporter 699 --period $year --partner 0 \
--output-format csv \
| tail -n +2
done > india_exports_2010_2023.csv
A partner-specific drill-down:
un-comtrade trade exports --reporter 699 --period 2022 --partner 842 \
--output-format json \
| jq '.aggregate_total'
# → "78310876432.18"
Related Recipes¶
- RECIPE-095 — Drive trade commands from the CLI.
Related Guides¶
- CLI → Metadata — uses the country catalogue.
- CLI → Storage — pipes trade output to a storage backend.
- Python SDK → Trade — equivalent Python API.
Next steps¶
- CLI → Storage — persist trade output.
- CLI → Analytics — drill into the stored dataset.