compare_countries
Compare health indicators across countries, regions, or income groups for a given period, with filtering by sex and other dimensions, output as rows or CSV.
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 full dimension combination, preserving every population.
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. This is not a per-country allowance: an
earlier country can consume a chunk and omit later countries.
Check missing_requested_codes and truncation flags.
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 |
|---|---|---|---|
| sex | No | ||
| top | No | ||
| format | No | rows | |
| year_end | No | ||
| countries | No | ||
| year_start | No | ||
| dim_filters | No | ||
| latest_only | No | ||
| country_group | No | ||
| indicator_code | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||