Analytics via the CLI¶
The analytics command runs typed analytics on a stored dataset
(file path or DuckDB table). Output is the same tuple of frozen
dataclasses the Python facade returns — serialised to JSON, CSV,
Markdown, table, or text.
Purpose¶
This page covers the analytics sub-subcommands, their flags, and
shell-composition patterns.
Prerequisites¶
- A stored dataset (CSV, JSON, Parquet, or DuckDB). See CLI → Storage to create one.
- The
un-comtradescript on yourPATH.
Walkthrough¶
Top partners¶
Top HS codes¶
Global balance¶
Country trend¶
un-comtrade analytics country-trend \
--input india_exports_history.parquet \
--reporter 699 \
--granularity year
Country comparison¶
un-comtrade analytics country-vs-country \
--inputs india_exports_2022.parquet,china_exports_2022.parquet \
--labels India,China \
--breakdown-by commodity
Sector summaries¶
Examples¶
A Markdown report:
un-comtrade analytics top-partners \
--input india_exports_2022.parquet \
--by exports --limit 10 \
--output-format markdown > report.md
Pipe analytics output to jq:
un-comtrade analytics top-partners \
--input india_exports_2022.parquet \
--by exports --limit 5 \
--output-format json \
| jq -r '.[] | "\(.partner_label): \(.value)"'
Drill-down: top partner → their HS codes:
top_partner=$(un-comtrade analytics top-partners \
--input india_exports_2022.parquet \
--by exports --limit 1 \
--output-format json | jq -r '.[0].partner_code')
un-comtrade trade exports --reporter 699 --period 2022 --partner "$top_partner" \
--output-format json \
| un-comtrade analytics top-hs-codes --input - --limit 5
Related Recipes¶
- RECIPE-099 — Drive analytics commands from the CLI.
Related Guides¶
- CLI → Trade — produces a dataset.
- CLI → Storage — persists a dataset.
- Python SDK → Analytics — equivalent Python API.
Next steps¶
- CLI → Storage — round-trip analytics through storage.
- Python SDK → Analytics — full Python API surface.