Skip to content

UN Comtrade — international trade

The integration provides bilateral merchandise trade (type C), exports/imports, annual or monthly periods and HS classification. The mirror compares export declarations with reverse imports. See the API selectors and the dataset contract 3.0 (the source validates comercio_bilateral 2.1).

Routes and options

Layer Delivery
Public preview No key, one period per request and an independent count
Authenticated acquisition Optional key transport and full preview replanning on 401/403, with a warning pointing to AGROBR_COMTRADE_API_KEY and api_key=
Bilateral Explicit World or all published partners; individual HS, agricultural alias or textual list
Mirror Outer 1:1 join, numeric identity and each declaration's HS revision
Semantic dataset Same selectors, full contract including empty output, metadata, sync and Polars

Routes: https://comtradeapi.un.org/public/v1/preview/C/{freq}/HS and https://comtradeapi.un.org/data/v1/get/C/{freq}/HS. The client uses async httpx, timeouts, retries, rate limits and Pydantic validation. Credentials do not enter resources or metadata.

Coverage and limits

Example: the BR/X/2023 preview with five HS codes and all partners returns 500 rows against an independent count of 516; the union of disjoint HS queries returns all 516 records, including the missing 16. Soybeans return one explicit World row versus 63 published partners when the parameter is omitted. These are examples, not global database counts.

A single period/HS may still exceed available access. require_complete=True rejects such output; the default warns and records coverage. Revisions and failed blocks do not become successful empty responses. Limits with a key are not guaranteed.

Availability depends on country, period and classification. Services, tariffs, bulk, a dynamic country catalog, transport/customs detail, harmonization and frozen revision history are outside the integration.

The Brazil side comes from Brazil's declaration to Comtrade and may diverge from ComexStat, which is revised: for corn to China in 2024, Comtrade has 2,285,068 t and ComexStat 2,227,000 t (+2.6%), probably because SECEX revised the data after the submission. For soybean and soybean meal in 2024 and 2025 and for corn in 2025, the difference was at most 0.06%. The difference may also come from UN estimation: for chicken in 2024 (HS 020711 to 020714), Comtrade's weight exceeds ComexStat's by 0.88%, with FOB practically equal (+0.007%), because the net weight of 020714 is estimated by the UN. The peso_liquido_estimado column and the MetaInfo warning show when this happens.

The internal license category is restrito; see Licenses. Technical references: preview and the official SDK with countOnly. The classification preserves the UN policy's explicit redistribution exceptions.

Requested years must be between 1962 and the current year. Invalid periods raise InvalidParameterError before network access. The source keeps its technical selectors and columns; the dataset contract describes the Portuguese dataset names. Text uses the installed pandas default, including empty results.