xippios-comtrade 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xippios_comtrade-0.1.0/.gitignore +23 -0
- xippios_comtrade-0.1.0/CHANGELOG.md +123 -0
- xippios_comtrade-0.1.0/LICENSE +201 -0
- xippios_comtrade-0.1.0/PKG-INFO +176 -0
- xippios_comtrade-0.1.0/README.md +147 -0
- xippios_comtrade-0.1.0/docs/upstream/FETCHED.md +65 -0
- xippios_comtrade-0.1.0/docs/upstream/apidocs/comtrade.json +2908 -0
- xippios_comtrade-0.1.0/docs/upstream/apidocs/comtradeAsync.json +784 -0
- xippios_comtrade-0.1.0/docs/upstream/apidocs/comtradeTools.json +1192 -0
- xippios_comtrade-0.1.0/docs/upstream/apidocs/comtradebulk.json +1167 -0
- xippios_comtrade-0.1.0/docs/upstream/apidocs/public.json +2239 -0
- xippios_comtrade-0.1.0/docs/upstream/help/data-availability.md +143 -0
- xippios_comtrade-0.1.0/docs/upstream/help/data.md +107 -0
- xippios_comtrade-0.1.0/docs/upstream/help/how-do-i-use-wildcards-to-query-data.md +22 -0
- xippios_comtrade-0.1.0/docs/upstream/help/list-of-references-parameter-codes.md +25 -0
- xippios_comtrade-0.1.0/docs/upstream/help/metadata.md +23 -0
- xippios_comtrade-0.1.0/docs/upstream/help/second-partner-country.md +23 -0
- xippios_comtrade-0.1.0/docs/upstream/help/subscriptions.md +55 -0
- xippios_comtrade-0.1.0/docs/upstream/help/trade-flows-in-un-comtrade.md +115 -0
- xippios_comtrade-0.1.0/docs/upstream/help/un-comtrade-api.md +136 -0
- xippios_comtrade-0.1.0/docs/upstream/help/what-is-data-preview.md +17 -0
- xippios_comtrade-0.1.0/docs/upstream/reference/ListofReferences.json +172 -0
- xippios_comtrade-0.1.0/docs/upstream/reference/TradeDataItems.json +405 -0
- xippios_comtrade-0.1.0/pyproject.toml +98 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/__init__.py +38 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/_client.py +155 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/_version.py +10 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/__init__.py +25 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/_query.py +21 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/get.py +151 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/get_da.py +72 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/get_live_update.py +25 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/get_metadata.py +50 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/api/reference.py +55 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/enums.py +204 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/errors.py +62 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/http.py +14 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/mcp.py +29 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/models.py +656 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/params.py +801 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/py.typed +0 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/README.md +52 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/Reporters.csv +256 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/TradeDataItems.csv +51 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/aggregateBy.json +14 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/breakdownMode.json +9 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/clCode.json +140 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/country_area_code_iso.csv +313 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/customsCode.json +24 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/flowCode.json +31 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/freqCode.json +9 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/mosCode.json +13 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/motCode.json +25 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/partnerAreas.csv +311 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/qtyUnitCode.json +48 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/tables.json +26 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/reference/typeCode.json +9 -0
- xippios_comtrade-0.1.0/src/xippios/comtrade/tasks.py +780 -0
- xippios_comtrade-0.1.0/tests/conftest.py +124 -0
- xippios_comtrade-0.1.0/tests/fixtures/README.md +9 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/bilateral_ch_us_2022_2023.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/bilateral_ch_us_202301_202302.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023_ag2_aggregate_by_cmd_code.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023_ag2_aggregate_by_partner_code_cmd_code.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023_breakdown_mode_classic.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023_breakdown_mode_plus.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023_include_desc.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/ch_exports_2023_totals.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_13_periods.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_aggregate_by_cmd_code.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_aggregate_by_partner_code_cmd_code.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_breakdown_mode_classic.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_breakdown_mode_plus.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_ch_exports_2023.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_ch_exports_2023_ag2.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_ch_exports_2023_totals.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_b4.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_b5.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_be.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_be5.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_eb.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_eb02.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_eb10.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_eb10s.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h0.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h1.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h2.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h3.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h4.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h5.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h6.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h6_cmd_code_01.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h6_retried.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h6_retried_later.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_h6_usa.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_s1.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_s2.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_s3.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_s4.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_ss.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cl_code_tm.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cmd_code_999999.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cmd_code_absent.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_cmd_code_wildcard.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_flow_code_mif.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_flow_code_unknown.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_flow_code_xif.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_not_a_reporter_756.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_over_limit.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_partner2_code_0.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_period_malformed.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_rate_limited.json +34 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_services_eb10_mos_code_0.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_services_eb10_mos_code_1.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_services_eb10_mos_code_mode_1.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_services_eb10_total.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_services_eb_mos_code_0.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_services_eb_total.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/count_zero_ch_1900.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/invalid_key.json +26 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/over_limit_max_records.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/partners_ch_total_2023.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/series_ch_27_2010_2021.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/series_ch_27_2022_2023.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/services_ch_exports_2023_eb10.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/unknown_reporter.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get/world_27_2023_imports.json +74 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_da/all_reporters_2023.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_da/ch_13_periods.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_da/ch_2023.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_da/ch_published_2024.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_da/nobody_1900.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_da/services_ebsdmx.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_live_update/latest.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_metadata/ch_2023.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_metadata/ch_2023_h6.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/get_metadata/ch_all_periods.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/reference/b4.json +94 -0
- xippios_comtrade-0.1.0/tests/fixtures/reference/be_absent.json +66 -0
- xippios_comtrade-0.1.0/tests/fixtures/reference/eb10s.json +94 -0
- xippios_comtrade-0.1.0/tests/test_adapters.py +72 -0
- xippios_comtrade-0.1.0/tests/test_layout.py +20 -0
- xippios_comtrade-0.1.0/tests/test_live.py +138 -0
- xippios_comtrade-0.1.0/tests/test_scripts.py +33 -0
- xippios_comtrade-0.1.0/tests/test_tasks.py +1797 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# environments and caches
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
.mypy_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.hypothesis/
|
|
9
|
+
|
|
10
|
+
# build artefacts
|
|
11
|
+
dist/
|
|
12
|
+
build/
|
|
13
|
+
*.egg-info/
|
|
14
|
+
|
|
15
|
+
# local secrets are never files, but belt and braces
|
|
16
|
+
.env
|
|
17
|
+
.env.*
|
|
18
|
+
.envrc
|
|
19
|
+
.envrc.*
|
|
20
|
+
|
|
21
|
+
# editors
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/) (pre-1.0: breaking changes bump the minor).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-10-23
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Four task-shaped slices on `data/v1/get`, MCP tools `comtrade_get_bilateral_flows`,
|
|
14
|
+
`comtrade_get_commodity_series`, `comtrade_get_world_trade` and
|
|
15
|
+
`comtrade_get_top_partners`: `get_bilateral_flows(reporter, partner, commodities,
|
|
16
|
+
periods, flow)`, `get_commodity_series(reporter, commodity, flow, periods)` (partner
|
|
17
|
+
World, 12 periods per call, at most 120 periods, rows by period),
|
|
18
|
+
`get_world_trade(commodity, period, flow)` (every reporter, partner World, largest
|
|
19
|
+
first) and `get_top_partners(reporter, commodity, period, flow, n)` (every partner
|
|
20
|
+
ranked by `primary_value`, World dropped as the total, `n` in `meta.request`), each
|
|
21
|
+
with `cl_code="HS"` (EB*, BE and TM accepted but untested with `typeCode` C). Every
|
|
22
|
+
call pins `typeCode` C, `breakdownMode` classic, `partner2Code` 0, `motCode` 0,
|
|
23
|
+
`customsCode` C00 and `includeDesc` true (`params.SLICE_PINS`); rows are
|
|
24
|
+
`TradeFlowRecord`, a projection of `TradeDataRecord` under upstream names with the
|
|
25
|
+
`is_qty_estimated` and `is_net_wgt_estimated` flags. At TOTAL and chapter level the
|
|
26
|
+
recorded rows are mostly UNSD aggregates (`is_aggregate` true, `is_reported` false)
|
|
27
|
+
without a quantity. The slices are bounded by their arguments and make no count call;
|
|
28
|
+
a bound over 100,000 raises `QueryTooLarge` before the call (`bound=True`, kept on the
|
|
29
|
+
exception).
|
|
30
|
+
- `params.validate_slice`: a reporter or partner as UN Comtrade's code or ISO alpha-3
|
|
31
|
+
(`"CHE"` is 757, `"USA"` as partner 842, `"W00"` World), resolved before the call;
|
|
32
|
+
periods of one format set `freqCode` (`YYYY` annual, `YYYYMM` monthly); a mix, an
|
|
33
|
+
unknown code, a level such as `AG2`, a wildcard or a period or product code named twice
|
|
34
|
+
is refused with the closest value.
|
|
35
|
+
- `search` on `list_reporters`, `list_partners` and `list_commodities`: a case-insensitive
|
|
36
|
+
substring of the code, the ISO alpha-3 code (reporters, partners) or the text; it goes
|
|
37
|
+
into `meta.request`. The MCP result cap (200 rows or 64 KB) hides most of each list, so
|
|
38
|
+
the docstrings tell agents to search.
|
|
39
|
+
- Six recorded fixtures under `tests/fixtures/get/` for the slices (bilateral annual and
|
|
40
|
+
monthly, the two calls of a 14-year series, world trade, every partner) and four live
|
|
41
|
+
smoke tests, one keyed call each.
|
|
42
|
+
- `get_data_availability` on `data/v1/getDa`, `get_metadata` on `data/v1/getMetadata` and
|
|
43
|
+
`get_live_update` on `data/v1/getLiveUpdate`, MCP tools `comtrade_get_data_availability`,
|
|
44
|
+
`comtrade_get_metadata` and `comtrade_get_live_update`. Rows mirror the spec's schemas
|
|
45
|
+
under upstream names and carry their own dates (`first_released`/`last_released`,
|
|
46
|
+
`publication_date`, `started_at`/`completed_at`/`last_updated`/`queued_at`), typed;
|
|
47
|
+
`meta.published_at` stays `None`. `get_metadata` takes `reporter_code` and `period`,
|
|
48
|
+
which the spec omits and upstream honours. getLiveUpdate has no `publishedDate`; its
|
|
49
|
+
times are read without the process locale, and one that does not parse becomes `None`
|
|
50
|
+
for that field (only Released/Success rows were recorded).
|
|
51
|
+
- Every `clCode` value and `flowCode`'s `XIF` rest on a recorded count
|
|
52
|
+
(`reference/clCode.json`, `flowCode.json`); `H6` answered HTTP 500 to all five tries.
|
|
53
|
+
The docstrings of `get_counts` and `get_data` say what the recorded answers established
|
|
54
|
+
for `breakdownMode` (default `plus`), `aggregateBy`, `includeDesc` and services totals.
|
|
55
|
+
- `list_reporters` and `list_partners`, MCP tools `comtrade_list_reporters` and
|
|
56
|
+
`comtrade_list_partners`: UN Comtrade's `Reporters.json` (255 rows) and
|
|
57
|
+
`partnerAreas.json` (310 rows) as packaged with this version, every column under its
|
|
58
|
+
upstream name, without an upstream call; `meta.vintage` is the day they were fetched.
|
|
59
|
+
- `list_commodities(cl_code)`, MCP tool `comtrade_list_commodities`: the product codes of
|
|
60
|
+
one classification from upstream's public `<clCode>.json` (no key, no quota), kept for
|
|
61
|
+
the process by core's GET cache on `reference_client` (`REFERENCE_CACHE`). `cl_code` is
|
|
62
|
+
checked against the 19 classifications with a file; `BE` and `TM` have none (HTTP 404).
|
|
63
|
+
- Packaged tables `Reporters.csv`, `partnerAreas.csv`, `country_area_code_iso.csv` (UN
|
|
64
|
+
Comtrade's code to ISO alpha-3) and `TradeDataItems.csv`, written by
|
|
65
|
+
`scripts/refresh_reference.py` with upstream's columns, their provenance in
|
|
66
|
+
`reference/tables.json`; packaged lists `mosCode` (`ModeOfSupply.json`) and
|
|
67
|
+
`qtyUnitCode` (`QuantityUnits.json`) with the StrEnums `MosCode` and `QtyUnitCode`.
|
|
68
|
+
- `api.reference_rows`: a reference file's rows as upstream sent them.
|
|
69
|
+
- `scripts/refresh_reference.py --help` prints usage and fetches nothing. A list can carry
|
|
70
|
+
a `note`: `mosCode.json` and `MosCode` say they hold `ModeOfSupply.json`'s ids, not
|
|
71
|
+
proven parameter values (`data/v1/get` refused `Mode 1`).
|
|
72
|
+
- Replay tests check the request that goes out carries the placeholder key, never the
|
|
73
|
+
shell's (ported from sdk-template).
|
|
74
|
+
- `get_counts` and `get_data` on `data/v1/get/{typeCode}/{freqCode}/{clCode}`, MCP tools
|
|
75
|
+
`comtrade_get_counts` and `comtrade_get_data`. `get_data` counts first with
|
|
76
|
+
`countOnly`: zero returns an empty result without a second call, more than 100,000
|
|
77
|
+
records raises `QueryTooLarge` (an `InvalidRequestError`, HTTP 422) before any data
|
|
78
|
+
call, because upstream truncates silently at 100,000 rows (observed 2026-10-23).
|
|
79
|
+
Rows are `TradeDataRecord`, every field of upstream's schema, values and quantities as
|
|
80
|
+
`Decimal`.
|
|
81
|
+
- Arguments are checked before any call (`params.validate_get`): coded parameters against
|
|
82
|
+
packaged lists, periods (at most 12) and product codes by shape.
|
|
83
|
+
- Packaged lists `typeCode`, `freqCode`, `clCode`, `flowCode`, `customsCode`, `motCode`,
|
|
84
|
+
`aggregateBy`, `breakdownMode` in `reference/` with their origin, and the matching
|
|
85
|
+
StrEnums in `enums.py`, written by `scripts/refresh_reference.py` from the public
|
|
86
|
+
reference files (fetched without a key through `api.reference`) and the spec snapshot.
|
|
87
|
+
Where the spec documents more than a reference file, the script reconciles them and
|
|
88
|
+
records each exception with its evidence: `flowCode` adds the spec's `MIF` and `XIF`;
|
|
89
|
+
`clCode` adds the spec's `BE` and `TM`, which upstream accepted, and leaves out `BE5`,
|
|
90
|
+
which upstream refused.
|
|
91
|
+
- `_client.classify`: an HTTP 400 `ErrorResponse` becomes `InvalidRequestError` with
|
|
92
|
+
upstream's message; a 403 that mentions a quota becomes `RateLimitError` (API
|
|
93
|
+
Management's text, not observed). The rate limit never bursts. The read
|
|
94
|
+
timeout is 180 s, since a broad count can take over a minute.
|
|
95
|
+
- Fifteen recorded fixtures under `tests/fixtures/get/` and live smoke tests for both
|
|
96
|
+
tasks. Replay tests always send a placeholder key, whatever the shell holds.
|
|
97
|
+
- Scaffold from [sdk-template](https://github.com/xippios/sdk-template): configured
|
|
98
|
+
client for UN Comtrade, empty task layer, MCP server and FastAPI router
|
|
99
|
+
wired to it, test harness, CI and publishing.
|
|
100
|
+
- Upstream documentation snapshot in `docs/upstream/`: the five ApiDocs product specs
|
|
101
|
+
(OpenAPI: Public, Comtrade, Comtrade Tools, Comtrade Bulk, Comtrade Async), ten Help
|
|
102
|
+
Center articles as Markdown and two reference files, listed in `FETCHED.md`.
|
|
103
|
+
`.gitattributes` marks `docs/upstream/**` as `-text`, so git never converts the line
|
|
104
|
+
endings of the files kept byte for byte (the CRLF specs, one mixed-endings file).
|
|
105
|
+
- `scripts/refresh_upstream.py`: regenerates the snapshot reproducibly, discovering the
|
|
106
|
+
ApiDocs products from the page's bundle (`uv run scripts/refresh_upstream.py`).
|
|
107
|
+
|
|
108
|
+
### Changed
|
|
109
|
+
|
|
110
|
+
- Calls are spaced 1.5 s apart (`RATE_LIMIT = RateLimit(per_minute=40, burst=1)`): at
|
|
111
|
+
exactly 1.0 s, 9 of 18 calls drew HTTP 429 "Rate limit is exceeded" (2026-10-23).
|
|
112
|
+
- `reporter_code` is checked against the packaged `Reporters.csv`, `partner_code` and
|
|
113
|
+
`partner2_code` against `partnerAreas.csv`, each member of a comma-separated list. An
|
|
114
|
+
unknown code raises `InvalidRequestError` before any call, naming the same area's code
|
|
115
|
+
where `country_area_code_iso.json` knows it (`756` names `757`, Switzerland), or saying
|
|
116
|
+
that a code belongs to the other table (`0` World is a partner only). Upstream itself
|
|
117
|
+
answers a code that is no reporter with an empty result.
|
|
118
|
+
- Template updated to sdk-template v0.1.5 (`/add-endpoint` asks for
|
|
119
|
+
`Field(validation_alias=...)`, not `alias=`; `/refresh-reference-data` formats the
|
|
120
|
+
regenerated `enums.py`; `/refresh-upstream` runs `scripts/refresh_upstream.py` where it
|
|
121
|
+
exists; `.gitignore` covers `.env.*` and `.envrc.*`; the MCP instructions name the
|
|
122
|
+
`comtrade_list_*` tools; `_client.__all__` exports `auth`). `.copier-answers.yml` now
|
|
123
|
+
records `rate_limit_per_minute: 40`, the limit `RATE_LIMIT` already applies.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: xippios-comtrade
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed client, MCP tools and HTTP routes for UN Comtrade
|
|
5
|
+
Project-URL: Homepage, https://github.com/xippios/sdk-comtrade
|
|
6
|
+
Project-URL: Upstream, https://comtradeplus.un.org
|
|
7
|
+
Project-URL: Changelog, https://github.com/xippios/sdk-comtrade/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/xippios/sdk-comtrade/issues
|
|
9
|
+
Author: XIPPIOS GmbH
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: comtrade,httpx,international-trade,mcp,pydantic,sdk
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: xippios-core>=0.1.0
|
|
22
|
+
Provides-Extra: http
|
|
23
|
+
Requires-Dist: xippios-core[http]>=0.1.0; extra == 'http'
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: xippios-core[mcp]>=0.1.0; extra == 'mcp'
|
|
26
|
+
Provides-Extra: testing
|
|
27
|
+
Requires-Dist: xippios-core[testing]>=0.1.0; extra == 'testing'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# xippios-comtrade
|
|
31
|
+
|
|
32
|
+
Typed Python client, MCP server and FastAPI routes for
|
|
33
|
+
[UN Comtrade](https://comtradeplus.un.org), part of the
|
|
34
|
+
[xippios SDK family](https://github.com/xippios). Names and semantics follow the
|
|
35
|
+
upstream documentation; every response carries release metadata (source, endpoint,
|
|
36
|
+
retrieved_at, published_at, vintage).
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv add xippios-comtrade # client only
|
|
42
|
+
uv add "xippios-comtrade[mcp]" # + MCP server
|
|
43
|
+
uv add "xippios-comtrade[http]" # + FastAPI router
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Set `COMTRADE_API_KEY` in the environment. Nothing is read from files.
|
|
47
|
+
|
|
48
|
+
## 30-second example
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from xippios.comtrade import get_counts, get_data
|
|
52
|
+
|
|
53
|
+
# Switzerland (reporter 757) exports to the World (partner 0) in 2023, all products.
|
|
54
|
+
query = {
|
|
55
|
+
"reporter_code": "757",
|
|
56
|
+
"partner_code": "0",
|
|
57
|
+
"period": "2023",
|
|
58
|
+
"cmd_code": "TOTAL",
|
|
59
|
+
"flow_code": "X",
|
|
60
|
+
}
|
|
61
|
+
get_counts("C", "A", "HS", **query).data # 32: every customs procedure and mode of transport
|
|
62
|
+
result = get_data("C", "A", "HS", **query)
|
|
63
|
+
total = next(r for r in result.data if (r.customs_code, r.mot_code) == ("C00", 0))
|
|
64
|
+
total.primary_value # Decimal('419922543423.509'); JSON: a number
|
|
65
|
+
result.meta.endpoint, result.meta.request # 'data/v1/get', the arguments above
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Parameters are upstream's (`typeCode`, `reporterCode`, ...) in snake_case and take
|
|
69
|
+
upstream's codes, several of them comma-separated as upstream takes them (`"757,842"`).
|
|
70
|
+
Reporter and partner codes are UN Comtrade's, not ISO numeric: Switzerland is 757.
|
|
71
|
+
Every argument is checked before the call: coded ones (`type_code`, `cl_code`,
|
|
72
|
+
`flow_code`, `customs_code`, `mot_code`, `aggregate_by`, `breakdown_mode`) against
|
|
73
|
+
the lists packaged from upstream's reference files and spec (`xippios.comtrade.enums`),
|
|
74
|
+
`reporter_code` against the packaged copy of upstream's `Reporters.json`
|
|
75
|
+
(`reference/Reporters.csv`) and `partner_code` and `partner2_code` against that of
|
|
76
|
+
`partnerAreas.json`, the others by shape; a mistake raises
|
|
77
|
+
`InvalidRequestError` naming the closest valid value (`756` names `757`, Switzerland).
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from xippios.comtrade import list_commodities, list_partners, list_reporters
|
|
81
|
+
|
|
82
|
+
list_reporters().data # 255 reporters, packaged with this version: no call
|
|
83
|
+
list_reporters(search="switz").data # code, ISO alpha-3 or name, any case: 757
|
|
84
|
+
list_partners().data # 310 partner areas, 0 World among them
|
|
85
|
+
list_commodities("HS", search="coffee").data # from 8,262 HS codes, fetched keyless once
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Four task-shaped slices answer the common questions in one call each (the series in one
|
|
89
|
+
call per 12 periods), at the total of every breakdown, one row per reporter × partner ×
|
|
90
|
+
product code × period. Areas are UN Comtrade's codes or ISO alpha-3 codes; `YYYY` periods
|
|
91
|
+
ask for annual data, `YYYYMM` for monthly:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from xippios.comtrade import (
|
|
95
|
+
get_bilateral_flows,
|
|
96
|
+
get_commodity_series,
|
|
97
|
+
get_top_partners,
|
|
98
|
+
get_world_trade,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
get_bilateral_flows("CHE", "USA", "TOTAL,27", "2022,2023", "X").data # 4 rows
|
|
102
|
+
years = ",".join(str(year) for year in range(2010, 2024))
|
|
103
|
+
get_commodity_series("757", "27", "X", years).data # 14 years, two calls, by period
|
|
104
|
+
get_world_trade("27", "2023", "M").data[0].reporter_desc # 'China': largest first
|
|
105
|
+
[r.partner_desc for r in get_top_partners("CHE", "TOTAL", "2023", "X", 3).data]
|
|
106
|
+
# ['USA', 'Germany', 'China']: World, the total, is dropped
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Release dates are per dataset, so they sit on the rows, not in `meta.published_at`:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from xippios.comtrade import get_data_availability, get_live_update, get_metadata
|
|
113
|
+
|
|
114
|
+
[dataset] = get_data_availability("C", "A", "HS", reporter_code="757", period="2023").data
|
|
115
|
+
dataset.first_released, dataset.last_released # first publication and latest revision
|
|
116
|
+
notes = get_metadata("C", "A", "HS", reporter_code="757", period="2023").data[0].notes
|
|
117
|
+
[note.publication_date for note in notes] # "New Data", then each "Revised Data"
|
|
118
|
+
get_live_update().data # the 50 most recent releases, newest first
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`get_data` counts first with upstream's `countOnly`: a count of zero returns an empty
|
|
122
|
+
result without a second call, and a count above 100,000 raises `QueryTooLarge` with the
|
|
123
|
+
count before anything is fetched, because upstream would cut the answer at 100,000 rows
|
|
124
|
+
without saying so. A free key allows 1 call per second and 500 calls per day, and
|
|
125
|
+
`countOnly` calls count; the client spaces calls 1.5 s apart (upstream's gateway refuses
|
|
126
|
+
some calls spaced exactly 1 s apart), the daily quota is yours to track.
|
|
127
|
+
|
|
128
|
+
## MCP
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"mcpServers": {
|
|
133
|
+
"comtrade": {
|
|
134
|
+
"command": "uvx",
|
|
135
|
+
"args": ["--from", "xippios-comtrade[mcp]", "xippios-comtrade-mcp"],
|
|
136
|
+
"env": { "COMTRADE_API_KEY": "..." }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Tools are read-only and named `comtrade_<verb>_<noun>`. Results are capped at
|
|
143
|
+
200 rows or 64 KB with a note on how to narrow the query. Unfiltered,
|
|
144
|
+
`comtrade_list_reporters`, `comtrade_list_partners` and `comtrade_list_commodities` show
|
|
145
|
+
the first rows of their table only (200 of 255 reporters, in upstream's alphabetical
|
|
146
|
+
order), so they take `search`: `{"search": "switz"}` returns 757 Switzerland. `--http`
|
|
147
|
+
serves streamable HTTP instead of stdio.
|
|
148
|
+
|
|
149
|
+
## Status
|
|
150
|
+
|
|
151
|
+
| Upstream operation | Task function | MCP tool | Status |
|
|
152
|
+
| --- | --- | --- | --- |
|
|
153
|
+
| `data/v1/get/{typeCode}/{freqCode}/{clCode}` with `countOnly=true` | `get_counts(type_code, freq_code, cl_code, *, reporter_code=, partner_code=, ...)` | `comtrade_get_counts` | alpha |
|
|
154
|
+
| `data/v1/get/{typeCode}/{freqCode}/{clCode}` | `get_data(type_code, freq_code, cl_code, *, reporter_code=, partner_code=, ...)` | `comtrade_get_data` | alpha |
|
|
155
|
+
| `data/v1/getDa/{typeCode}/{freqCode}/{clCode}` | `get_data_availability(type_code, freq_code, cl_code, *, reporter_code=, period=, published_date_from=, published_date_to=)` | `comtrade_get_data_availability` | alpha |
|
|
156
|
+
| `data/v1/getMetadata/{typeCode}/{freqCode}/{clCode}` | `get_metadata(type_code, freq_code, cl_code, *, reporter_code=, period=)` | `comtrade_get_metadata` | alpha |
|
|
157
|
+
| `data/v1/getLiveUpdate` | `get_live_update()` | `comtrade_get_live_update` | alpha |
|
|
158
|
+
| `data/v1/get/C/{A,M}/{clCode}`, total row, one reporter and partner | `get_bilateral_flows(reporter, partner, commodities, periods, flow, *, cl_code="HS")` | `comtrade_get_bilateral_flows` | alpha |
|
|
159
|
+
| `data/v1/get/C/{A,M}/{clCode}`, total row, partner World, 12 periods per call, at most 120 | `get_commodity_series(reporter, commodity, flow, periods, *, cl_code="HS")` | `comtrade_get_commodity_series` | alpha |
|
|
160
|
+
| `data/v1/get/C/{A,M}/{clCode}`, total row, every reporter, partner World | `get_world_trade(commodity, period, flow, *, cl_code="HS")` | `comtrade_get_world_trade` | alpha |
|
|
161
|
+
| `data/v1/get/C/{A,M}/{clCode}`, total row, every partner, ranked | `get_top_partners(reporter, commodity, period, flow, n, *, cl_code="HS")` | `comtrade_get_top_partners` | alpha |
|
|
162
|
+
| `files/v1/app/reference/Reporters.json`, packaged | `list_reporters(search=None)` | `comtrade_list_reporters` | alpha |
|
|
163
|
+
| `files/v1/app/reference/partnerAreas.json`, packaged | `list_partners(search=None)` | `comtrade_list_partners` | alpha |
|
|
164
|
+
| `files/v1/app/reference/{clCode}.json`, keyless | `list_commodities(cl_code, search=None)` | `comtrade_list_commodities` | alpha |
|
|
165
|
+
|
|
166
|
+
All twelve are covered in 0.1.0, the first release. Alpha: the public surface may change
|
|
167
|
+
in a minor version before 1.0; `CHANGELOG.md` lists every change.
|
|
168
|
+
|
|
169
|
+
## Upstream terms and attribution
|
|
170
|
+
|
|
171
|
+
Data comes from UN Comtrade (https://comtradeplus.un.org) under its own terms of use;
|
|
172
|
+
this package adds no rights to it. Documentation snapshot: `docs/upstream/`.
|
|
173
|
+
|
|
174
|
+
## Licence
|
|
175
|
+
|
|
176
|
+
Apache-2.0. See [LICENSE](LICENSE).
|