compare_countries
Compare health indicators across countries, regions, or income groups for a specified year range. Returns tidy data or CSV with auto-resolved codes and names.
Instructions
One indicator × N spatial units × year range, returned as tidy rows or CSV.
Workhorse for comparative analysis. Country names, ISO3 codes, region codes, and income-group codes all auto-resolve. Row labels resolve human titles for regions and income groups, not just countries.
For large country sets (e.g. country_group="LAC" with 33 sovereign
states), the request is automatically chunked into multiple parallel
HTTP calls of up to 10 spatial units each, then merged. This avoids the
HTTP 400 the GHO API returns when an $filter carries too many
SpatialDim eq '...' or ... clauses. The number of underlying requests
is returned as chunk_count and chunks run in parallel via asyncio.
Args:
indicator_code: e.g. "WHOSIS_000001".
countries: List of ISO3 codes, country names, region codes
(AFR/AMR/SEAR/EUR/EMR/WPR/GLOBAL), or income-group codes
(WB_HI/WB_UMI/WB_LMI/WB_LI).
country_group: Curated grouping code (e.g. "LAC", "OECD", "LDC",
"SSA"). Resolves to ISO3 members and merges with countries
if both are passed. See list_curated_country_groups for
available groups.
year_start: Inclusive lower bound on year.
year_end: Inclusive upper bound on year.
sex: "BTSX"/"both", "MLE"/"male", "FMLE"/"female", or raw SEX_* codes.
dim_filters: Extra dimension filters as {field: value}, e.g.
{"Dim2": "WEALTHQUINTILE_QUINTILE5"}. Use
describe_indicator_dimensions first to discover available types
and values. Cannot include "Dim1" if sex is also passed.
latest_only: If true, keep only the most recent year per spatial unit
(and per sex when disaggregated).
top: Per-request row cap, default 1000, max 5000. Applied to each
chunk of ≤10 spatial units, so the merged total may reach
top × chunk_count. With the default top=1000 and chunk_size=10
this gives ~100 rows per spatial unit, enough headroom that
$orderby=SpatialDim,TimeDim desc will not starve later codes
in a chunk before latest_only filtering.
format: "rows" (default) returns a list of dicts under the "rows" key;
"csv" returns a CSV string under the "csv" key.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indicator_code | Yes | ||
| countries | No | ||
| country_group | No | ||
| year_start | No | ||
| year_end | No | ||
| sex | No | ||
| dim_filters | No | ||
| latest_only | No | ||
| top | No | ||
| format | No | rows |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||