| name | fetch-chart-data |
| description | This skill describes how to fetch data for an Our World In Data chart, once the relevant chart URL has been identified. Consult this skill to understand the possible query params to get the best results and to understand the response. Use it you need to fetch data and have already identified the relevant chart URL. |
| allowed-tools | ["Bash(curl:*)","Bash(cat:*)","Bash(jq:*)"] |
Once you have identified a chart url like https://ourworldindata.org/grapher/literate-and-illiterate-world-population, there are two key artifacts you can retrieve: the metadata json file, and the data csv file. The urls for both are $CHARTURL.metadata.json and $CHARTURL.csv respectively.
Always fetch the metadata first before fetching the data as it gives important context. Pay special attention to the descriptionKey field if it is given.
Query Parameters
Both endpoints support these query parameters to filter data and reduce response size:
| Parameter | Description | Example |
|---|
useColumnShortNames | Use short column names without spaces | true |
csvType | Use filtered to respect country/time filters | filtered |
country | Filter to specific countries (ISO3 codes joined with ~) | USA~GBR~CHN |
time | Filter to time range | 2000..2020 or 2015 |
tab | Chart visualization type | map, line, table |
Recommended base parameters: ?useColumnShortNames=true&csvType=filtered
Example with filters:
https://ourworldindata.org/grapher/life-expectancy.csv?useColumnShortNames=true&csvType=filtered&country=USA~GBR&time=2000..2020
Token Optimization
To reduce token usage when working with the data:
-
Remove the Entity column - The CSV has both "Entity" (country name) and "Code" (ISO3). The Code column is sufficient for analysis and joining. Remove Entity to save tokens:
curl -s "$URL" | cut -d',' -f2-
-
Filter metadata - The full metadata is verbose. Key fields to extract:
chart.title, chart.subtitle, chart.note, chart.citation
columns.*.titleShort, columns.*.descriptionShort, columns.*.unit, columns.*.shortUnit
Skip these verbose fields: titleLong, citationLong, fullMetadata, owidVariableId, lastUpdated, nextUpdate
Metadata
The metadata outlines key information about the chart, as well as information on each time series used in the chart, each of which will be one column in the data file.
The typescript type of the metadata json file is as follows:
export type MetadataColumn = {
titleShort: string
titleLong: string
descriptionShort?: string
descriptionKey?: string[]
descriptionProcessing?: string
shortUnit?: string
unit?: string
timespan?: string
tolerance?: number
type?: string
conversionFactor?: number
shortName?: string
lastUpdated?: string
nextUpdate?: string
citationShort: string
citationLong: string
fullMetadata: string
}
export type ChartMetadata = {
title?: string
subtitle?: string
note?: string
xAxisLabel?: string
yAxisLabel?: string
citation: string
originalChartUrl?: string
selection: string[]
}
export type GrapherMetadataResponse = {
chart: ChartMetadata
columns: Record<string, MetadataColumn>
dateDownloaded: string
activeFilters?: Record<string, string>
}
CSV Structure
The high level structure of the CSV file is that each row is an observation for an entity (usually a country or region) and a timepoint (usually a year).
The first two columns in the CSV file are "Entity" and "Code". "Entity" is the name of the entity (e.g. "United States"). "Code" is the OWID internal entity code that we use if the entity is a country or region. For normal countries, this is the same as the iso alpha-3 code of the entity (e.g. "USA") - for non-standard countries like historical countries these are custom codes.
The third column is either "Year" or "Day". If the data is annual, this is "Year" and contains only the year as an integer. If the column is "Day", the column contains a date string in the form "YYYY-MM-DD".
The other columns are the data columns, which are the time series that power the chart.
Prefer to download the CSV and metadata into a file and process it from there.