owid-catalog: Data APIs¶
The Data API provides unified access to OWID's published data through a simple client interface.
Quick Reference¶
The API library is centered around the Client class, which provides quick access to different data APIs: IndicatorsAPI, TablesAPI, and ChartsAPI. Each API provides methods search() and fetch() for discovering and retrieving data, respectively.
For example to fetch a table by its path:
from owid.catalog import Client
client = Client()
tb = client.tables.fetch("garden/un/2024-07-12/un_wpp/population")
For convenience, the library provides functions for the most common use cases:
from owid.catalog import search, fetch
# Search for charts (default)
results = search("population")
tb = results[0].fetch()
# Direct fetch (by chart slug or table path)
tb = fetch("life-expectancy")
tb = fetch("garden/un/2024-07-12/un_wpp/population")
Lazy Loading¶
All fetch() methods return Table-like objects, which resemble pandas.DataFrame with the addition of metadata attributes that describe the data.
tb = client.charts.fetch("life-expectancy")
tb.metadata # Available immediately
tb["life_expectancy_0"].metadata # Column metadata available
Optionally, you can defer data loading until it's actually needed, by using the load_data=False parameter in fetch() methods.
Path Formats¶
Different APIs use different path conventions:
- Charts:
"life-expectancy"(simple slug),"years-of-schooling?metric_type=expected_years_schooling&level=primary&sex=boys"(with query params), or"https://ourworldindata.org/grapher/life-expectancy"(full URL) - Tables:
"garden/un/2024-07-12/un_wpp/population"(channel/namespace/version/dataset/table) - Indicators:
"garden/un/2024-07-12/un_wpp/population#population"(table path + #column)
API Reference¶
owid.catalog.api.quick
¶
Quick access functions for data discovery and retrieval.
For more complex use cases, refer to the full API.
This module provides two convenience functions that separate discovery from download:
- search(): Browse available data without downloading anything.
- fetch(): Download data by slug, URL, or catalog path.
Search for available data (no download)
Fetch specific data by path
>>> from owid.catalog import fetch
>>> tb = fetch("life-expectancy") # Chart slug auto-detected
>>> tb = fetch("years-of-schooling?metric_type=expected_years_schooling&level=primary&sex=boys") # Slug with query params
>>> tb = fetch("https://ourworldindata.org/grapher/life-expectancy") # Full URL
>>> tb = fetch("garden/un/2024-07-12/un_wpp/population") # Table path
>>> tb_ind = fetch("garden/un/2024-07-12/un_wpp/population#population") # Indicator
Functions:
-
search–Search for available data without downloading (for browsing/discovery).
-
fetch–Fetch data directly by path (auto-detects tables, indicators, or charts).
search
¶
search(
name: str | None = None,
*,
kind: Literal["table", "indicator", "chart"] = "chart",
limit: int = 10,
namespace: str | None = None,
version: str | None = None,
dataset: str | None = None,
channel: str | None = None,
match: Literal[
"exact", "contains", "regex", "fuzzy"
] = "fuzzy",
fuzzy_threshold: int = 70,
case: bool = False,
latest: bool = False,
) -> (
ResponseSet[TableResult]
| ResponseSet[IndicatorResult]
| ResponseSet[ChartResult]
)
Search for available data without downloading (for browsing/discovery).
This function searches for data in the catalog and returns a ResponseSet of results without downloading the actual data. Use this to explore and find the exact path or slug, then use fetch() to download the data.
Parameters:
-
name(str | None, default:None) –Name or pattern to search for (e.g., "population", "gdp", "life-expectancy"). Required for indicators and charts. Optional for tables (can filter by other params).
-
kind(Literal['table', 'indicator', 'chart'], default:'chart') –What to search for (default: "chart"):
- "chart": Search published charts (returns ResponseSet[ChartResult])
- "table": Search catalog tables (returns ResponseSet[TableResult])
- "indicator": Search indicators/variables (returns ResponseSet[IndicatorResult])
-
limit(int, default:10) –Maximum number of results to return (default: 10)
-
namespace(str | None, default:None) –Filter by namespace (e.g., "un", "worldbank"). Only for tables.
-
version(str | None, default:None) –Filter by specific version (e.g., "2024-01-15"). Only for tables.
-
dataset(str | None, default:None) –Filter by dataset name. Only for tables.
-
channel(str | None, default:None) –Filter by channel (e.g., "garden", "grapher"). Only for tables, and
namefield. -
match(Literal['exact', 'contains', 'regex', 'fuzzy'], default:'fuzzy') –Matching mode (default: "fuzzy" for typo-tolerance) (only for tables, and
namefield):- "fuzzy": Typo-tolerant similarity matching
- "exact": Exact string match
- "contains": Substring match
- "regex": Regular expression
-
fuzzy_threshold(int, default:70) –Minimum similarity score 0-100 for fuzzy matching (default: 70). Only for tables, and
namefield. -
case(bool, default:False) –Case-sensitive search (default: False). Only for tables.
-
latest(bool, default:False) –If True, keep only the latest version of each result (grouped by namespace/dataset/table or indicator). Only for tables and indicators. Note: results without a version are dropped when this is enabled.
Returns:
-
ResponseSet[TableResult] | ResponseSet[IndicatorResult] | ResponseSet[ChartResult]–Search results. Results can be indexed, iterated, and provide access to metadata without downloading data.
Example
# Search for charts (default)
results = search("population")
print(f"Found {len(results)} charts")
print(results[0].slug) # Access chart slug without downloading data
# Search for tables
results = search("population", kind="table")
print(results[0].path)
# Search for indicators
results = search("gdp", kind="indicator")
print(results[0].title)
# Exact match for tables
results = search("population", kind="table", match="exact")
# Filter tables by namespace and version
results = search("wdi", kind="table", namespace="worldbank_wdi", version="2024-01-10")
# Then fetch the data you need:
tb = results[0].fetch()
Warning
For indicators and charts, filtering parameters (namespace, version, dataset, channel) are ignored as they don't apply to those search types.
Source code in lib/catalog/owid/catalog/api/quick.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
fetch
¶
Fetch data directly by path (auto-detects tables, indicators, or charts).
This function downloads the data associated with the given path. It auto-detects whether you're accessing a table, indicator, or chart based on the path format.
Parameters:
-
path(str) –Path to the data resource:
- Table: "channel/namespace/version/dataset/table"
- Indicator: "channel/namespace/version/dataset/table#variable"
- Chart slug: "life-expectancy"
- Chart URL: "https://ourworldindata.org/grapher/life-expectancy"
- Chart slug with query params: "years-of-schooling?metric_type=expected_years_schooling&level=primary&sex=boys"
- Explorer URL: "https://ourworldindata.org/explorers/energy"
Returns:
-
Table | ChartTable–Table (for tables or indicators) or CharTable (for charts)
Raises:
-
ValueError–If path format is invalid or resource not found
Example
# Fetch table
tb = fetch("garden/un/2024-07-12/un_wpp/population")
print(tb.shape)
print(tb.metadata)
# Fetch indicator as Table (single column)
tb = fetch("garden/un/2024-07-12/un_wpp/population#population")
print(tb.columns)
# Fetch chart data (slug auto-detected)
tb = fetch("life-expectancy")
print(tb.metadata.title)
# Fetch chart with query params
tb = fetch("years-of-schooling?metric_type=expected_years_schooling&level=primary&sex=boys")
# Fetch chart by full URL
tb = fetch("https://ourworldindata.org/grapher/life-expectancy")
# Fetch from grapher channel
tb = fetch("grapher/demography/2025-10-22/life_expectancy/life_expectancy_at_birth")
Source code in lib/catalog/owid/catalog/api/quick.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
owid.catalog.api.Client
¶
Client(
timeout: int = 30,
catalog_url: str = DEFAULT_CATALOG_URL,
site_url: str = DEFAULT_SITE_URL,
indicators_search_url: str = DEFAULT_INDICATORS_SEARCH_URL,
site_search_url: str = DEFAULT_SITE_SEARCH_URL,
)
Unified client for all OWID data APIs.
Provides access to our main APIs:
- ChartsAPI: Fetch and search for published charts
- IndicatorsAPI: Semantic search for data indicators
- TablesAPI: Query and load tables from the data catalog
Attributes:
-
charts(ChartsAPI) –ChartsAPI instance for chart operations and search.
-
indicators(IndicatorsAPI) –IndicatorsAPI instance for indicator search.
-
tables(TablesAPI) –TablesAPI instance for catalog operations.
Example
from owid.catalog import Client
client = Client()
# Charts: Published visualizations
results = client.charts.search("climate change")
chart = client.charts.fetch("life-expectancy")
# Tables: Catalog datasets
results = client.tables.search(table="population", namespace="un")
tb = client.tables.fetch("garden/un/2024-07-12/un_wpp/population")
# Indicators: Semantic search for data series
results = client.indicators.search("renewable energy")
variable = client.indicators.fetch("garden/un/2024-07-12/un_wpp/population#population")
# Custom URLs (e.g., for staging environments)
staging_client = Client(catalog_url="https://staging-catalog.example.com/")
Initialize the client with all API interfaces.
Parameters:
-
timeout(int, default:30) –HTTP request timeout in seconds. Default 30.
-
catalog_url(str, default:DEFAULT_CATALOG_URL) –Base URL for the catalog. Default: https://catalog.ourworldindata.org/
-
site_url(str, default:DEFAULT_SITE_URL) –Base URL for the OWID website. Default: https://ourworldindata.org
-
indicators_search_url(str, default:DEFAULT_INDICATORS_SEARCH_URL) –URL for indicators search API. Default: https://search.owid.io/indicators
-
site_search_url(str, default:DEFAULT_SITE_SEARCH_URL) –URL for site search API. Default: https://ourworldindata.org/api/search
Source code in lib/catalog/owid/catalog/api/client.py
owid.catalog.api.charts.ChartsAPI
¶
API for accessing OWID chart data and metadata.
Provides methods to fetch data and metadata from published charts on ourworldindata.org. Also includes search functionality to find charts by keywords.
Example
from owid.catalog import Client
client = Client()
# Fetch chart data as ChartTable
tb = client.charts.fetch("life-expectancy")
print(tb.head())
print(tb["life_expectancy_0"].metadata.unit)
print(tb.metadata.chart_config.get("title")) # Access chart config
# Search for charts
results = client.charts.search("gdp per capita")
tb = results[0].fetch() # Fetch chart data as ChartTable
Initialize the ChartsAPI.
Parameters:
-
client(Client) –The Client instance.
-
site_url(str) –Base URL for the OWID website (e.g., "https://ourworldindata.org").
Methods:
-
search–Search for charts matching a query.
-
fetch–Fetch chart data as a ChartTable with rich metadata.
Attributes:
Source code in lib/catalog/owid/catalog/api/charts.py
search
¶
search(
query: str,
*,
countries: list[str] | None = None,
topics: list[str] | None = None,
require_all_countries: bool = False,
limit: int = 10,
page: int = 0,
timeout: int | None = None,
) -> ResponseSet[ChartResult]
Search for charts matching a query.
Parameters:
-
query(str) –Search query string.
-
countries(list[str] | None, default:None) –Optional list of country names to filter by.
-
topics(list[str] | None, default:None) –Optional list of topic names to filter by.
-
require_all_countries(bool, default:False) –If True, only return charts with ALL specified countries. Default False (any country matches).
-
limit(int, default:10) –Maximum results to return (1-100). Default 20.
-
page(int, default:0) –Page number for pagination (0-indexed). Default 0.
-
timeout(int | None, default:None) –HTTP request timeout in seconds. Defaults to client timeout.
Returns:
-
ResponseSet[ChartResult]–ResponseSet containing ChartResult objects, sorted by popularity (most viewed first).
-
ResponseSet[ChartResult]–Each result includes a
popularityfield (0.0-1.0) based on analytics views.
Example
# Basic search (sorted by popularity)
results = client.charts.search("life expectancy")
for chart in results:
print(f"{chart.title}: popularity={chart.popularity:.3f}")
# Filter by countries
results = client.charts.search(
"gdp",
countries=["France", "Germany"],
require_all_countries=True
)
# Get data from search results
tb = results[0].fetch()
Source code in lib/catalog/owid/catalog/api/charts.py
fetch
¶
fetch(
slug_or_url: str,
*,
type: ChartType | None = None,
load_data: bool = True,
timeout: int | None = None,
) -> ChartTable
Fetch chart data as a ChartTable with rich metadata.
Accepts a chart slug, a slug with query parameters, or a full URL. The slug, query parameters, and chart type are extracted automatically.
Parameters:
-
slug_or_url(str) –One of:
- Chart slug:
"life-expectancy" - Slug with query params:
"education-spending?level=primary&spending_type=gdp_share" - Full grapher URL:
"https://ourworldindata.org/grapher/life-expectancy?tab=table" - Full explorer URL:
"https://ourworldindata.org/explorers/covid?Metric=Cases"
- Chart slug:
-
type(ChartType | None, default:None) –Override the chart type. Defaults to
"chart"(grapher). Use"explorerView"for explorer views. Auto-detected from full URLs. -
load_data(bool, default:True) –If True (default), load full chart data. If False, load only structure (columns and metadata) without rows.
-
timeout(int | None, default:None) –HTTP request timeout in seconds. Defaults to client timeout.
Returns:
-
ChartTable–ChartTable with chart data and chart_config. Column metadata (unit, description, etc.)
-
ChartTable–is populated from the chart's metadata.json. Chart config is accessible via .metadata.chart_config.
Note
Explorer views are best-effort. Some explorers may return 503 or other errors from their CSV endpoint.
Example
# Fetch a grapher chart by slug
tb = client.charts.fetch("life-expectancy")
# Fetch with query params (e.g., a multiDim view)
tb = client.charts.fetch("education-spending?level=primary&spending_type=gdp_share")
# Fetch from a full URL (type and query params auto-detected)
tb = client.charts.fetch("https://ourworldindata.org/explorers/covid?Metric=Cases")
# Explicitly fetch an explorer view
tb = client.charts.fetch("covid?Metric=Cases", type="explorerView")
Source code in lib/catalog/owid/catalog/api/charts.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
owid.catalog.api.tables.TablesAPI
¶
API for querying and loading tables from the OWID catalog.
Provides methods to search for tables by various criteria and load table data from the catalog.
Example
from owid.catalog import Client
client = Client()
# Search for tables
results = client.tables.search(table="population", namespace="un")
# Load the first result
table = results[0].fetch()
# Fetch table directly by path
tb = client.tables.fetch("garden/un/2024-07-12/un_wpp/population")
print(tb.head())
Initialize the TablesAPI.
Parameters:
-
client(Client) –The Client instance.
-
catalog_url(str) –Base URL for the catalog (e.g., "https://catalog.ourworldindata.org/").
Methods:
Attributes:
-
catalog_url(str) –Base URL for the catalog (read-only).
Source code in lib/catalog/owid/catalog/api/tables.py
search
¶
search(
table: str | None = None,
namespace: str | None = None,
version: str | None = None,
dataset: str | None = None,
channel: str | None = None,
case: bool = False,
match: Literal[
"exact", "contains", "regex", "fuzzy"
] = "exact",
fuzzy_threshold: int = 70,
timeout: int | None = None,
refresh_index: bool = False,
latest: bool = False,
) -> ResponseSet[TableResult]
Search the catalog for tables matching criteria.
Parameters:
-
table(str | None, default:None) –Table name pattern to search for
-
namespace(str | None, default:None) –Filter by namespace (exact match)
-
version(str | None, default:None) –Filter by version (exact match)
-
dataset(str | None, default:None) –Dataset name pattern to search for
-
channel(str | None, default:None) –Filter by channel (exact match). Defaults to 'garden' if not specified.
-
case(bool, default:False) –Case-sensitive search (default: False)
-
match(Literal['exact', 'contains', 'regex', 'fuzzy'], default:'exact') –How to match table/dataset names (default: "exact"): - "fuzzy": Typo-tolerant similarity matching - "exact": Exact string match - "contains": Substring match - "regex": Regular expression pattern
-
fuzzy_threshold(int, default:70) –Minimum similarity score 0-100 for fuzzy matching. Only used when match="fuzzy". (default: 70)
-
timeout(int | None, default:None) –HTTP request timeout in seconds for catalog loading. Defaults to client timeout.
-
refresh_index(bool, default:False) –If True, force re-download of the catalog index. Default False.
-
latest(bool, default:False) –If True, keep only the latest version of each table (grouped by namespace, dataset, table, channel). Default False. Note: results without a version are dropped when this is enabled.
Returns:
-
ResponseSet[TableResult]–ResponseSet containing matching TableResult objects, sorted by popularity (most viewed first).
-
ResponseSet[TableResult]–If match="fuzzy", results are sorted by fuzzy relevance score instead.
-
ResponseSet[TableResult]–Each result includes a
popularityfield (0.0-1.0) based on analytics views.
Example
# Exact match (default) - searches garden channel by default
results = client.tables.search(table="population")
# Substring match
results = client.tables.search(table="pop", match="contains")
# Regex search
results = client.tables.search(table="population.*density", match="regex")
# Fuzzy search sorted by relevance
results = client.tables.search(table="populaton", match="fuzzy")
# Case-sensitive fuzzy search with custom threshold
results = client.tables.search(table="GDP", match="fuzzy", case=True, fuzzy_threshold=85)
# Filter by namespace and version
results = client.tables.search(
table="wdi",
namespace="worldbank_wdi",
version="2025-09-08",
)
# Search in a specific channel
results = client.tables.search(
table="wdi",
namespace="worldbank_wdi",
version="2025-09-08",
channel="meadow",
)
# Load a specific result
tb = results[0].fetch()
Source code in lib/catalog/owid/catalog/api/tables.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
fetch
¶
fetch(
path: str,
*,
load_data: bool = True,
formats: list[str] | None = None,
is_public: bool = True,
timeout: int | None = None,
) -> Table
Fetch a table by catalog path.
Loads the table directly from the catalog.
Parameters:
-
path(str) –Full catalog path (e.g., "garden/un/2024-07-12/un_wpp/population").
-
load_data(bool, default:True) –If True (default), load full table data. If False, load only table structure (columns and metadata) without rows.
-
formats(list[str] | None, default:None) –List of formats to try. If None, tries all supported formats.
-
is_public(bool, default:True) –Whether the table is publicly accessible. Default True.
-
timeout(int | None, default:None) –HTTP request timeout in seconds (currently unused, reserved for future).
Returns:
-
Table–Table with data and metadata (or just metadata if load_data=False).
Raises:
-
ValueError–If path format is invalid.
-
KeyError–If table not found at path.
Example
Source code in lib/catalog/owid/catalog/api/tables.py
owid.catalog.api.indicators.IndicatorsAPI
¶
API for semantic search of OWID indicators.
Uses the search.owid.io service to find indicators using natural language queries and vector embeddings.
Example
from owid.catalog import Client
client = Client()
# Search for indicators
results = client.indicators.search("solar power generation")
for ind in results:
print(f"{ind.title} (score: {ind.score:.2f})")
# Fetch the indicator data as a single-column Table
tb = results[0].fetch()
# Or fetch the full table containing the indicator
full_table = results[0].fetch_table()
Initialize the IndicatorsAPI.
Parameters:
-
client(Client) –The Client instance.
-
search_url(str) –URL for the indicators search API (e.g., "https://search.owid.io/indicators").
-
catalog_url(str) –Base URL for the catalog (e.g., "https://catalog.ourworldindata.org/").
Methods:
-
search–Search for indicators using natural language.
-
fetch–Fetch a specific indicator by catalog path.
Attributes:
-
search_url(str) –URL for the indicators search API (read-only).
-
catalog_url(str) –Base URL for the catalog (read-only).
Source code in lib/catalog/owid/catalog/api/indicators.py
search
¶
search(
query: str,
*,
limit: int = 10,
show_legacy: bool = False,
latest: bool = False,
sort_by: Literal[
"relevance", "similarity"
] = "relevance",
timeout: int | None = None,
) -> ResponseSet[IndicatorResult]
Search for indicators using natural language.
Uses semantic search to find indicators that match the meaning of your query, not just keyword matching.
Parameters:
-
query(str) –Natural language search query (e.g., "renewable energy capacity", "child mortality rate").
-
limit(int, default:10) –Maximum number of results to return. Default 10.
-
show_legacy(bool, default:False) –If True, show pre-ETL indicators only. Default False.
-
latest(bool, default:False) –If True, keep only the latest version of each indicator (grouped by namespace, dataset, column_name). Default False. Note: results without a version are dropped when this is enabled.
-
sort_by(Literal['relevance', 'similarity'], default:'relevance') –How to sort results (default: "relevance"):
- "relevance": Combined score blending semantic similarity (60%) and popularity (40%).
- "similarity": Sort by semantic similarity score only.
-
timeout(int | None, default:None) –HTTP request timeout in seconds. Defaults to client timeout.
Returns:
-
ResponseSet[IndicatorResult]–SearchResults containing IndicatorResult objects, sorted according to
sort_by. -
ResponseSet[IndicatorResult]–Each result includes a
popularityfield (0.0-1.0) based on analytics views.
Example
# Search for indicators (sorted by relevance by default)
results = client.indicators.search("CO2 emissions per capita")
# View results
for ind in results:
print(f"{ind.title}")
print(f" Score: {ind.score:.3f}")
print(f" Popularity: {ind.popularity:.3f}")
# Load data from top result
tb = results[0].fetch()
# Sort by semantic similarity only (original behavior)
results = client.indicators.search("CO2 emissions", sort_by="similarity")
Source code in lib/catalog/owid/catalog/api/indicators.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
fetch
¶
Fetch a specific indicator by catalog path.
Parameters:
-
path(str) –Catalog path in format "channel/namespace/version/dataset/table#column"
-
load_data(bool, default:True) –If True (default), load full indicator data. If False, load only structure (columns and metadata) without rows.
-
timeout(int | None, default:None) –HTTP request timeout in seconds (reserved for future use).
Returns:
-
Table–Table with a single indicator column (plus index). Metadata is preserved.
Raises:
-
ValueError–If path format is invalid, table not found, or column doesn't exist.
Example
Source code in lib/catalog/owid/catalog/api/indicators.py
API result types¶
Result objects returned by fetch() and search() methods.
owid.catalog.api.models.ResponseSet
¶
Bases: BaseModel, Generic[T]
Generic container for API responses.
Provides iteration, indexing, and conversion to CatalogFrame for backwards compatibility.
Attributes:
-
items(list[T]) –List of result objects.
-
query(str) –The query that produced these results.
-
total_count(int) –Total number of results available (may be more than len(items)).
Methods:
-
latest–Get the most recent result.
-
to_frame–Convert results to a DataFrame.
-
to_dict–Convert results to a list of plain dictionaries.
-
filter–Filter results by predicate function.
-
sort_by–Sort results by attribute name or key function.
-
set_ui_advanced–Switch to advanced display showing all fields (type, slug, popularity, etc.).
-
set_ui_basic–Switch to basic display showing only key fields (title, description, url).
latest
¶
latest(by: str | None = None) -> T
Get the most recent result.
Returns the single item with the highest value for the sort key.
Parameters:
-
by(str | None, default:None) –Attribute name to sort by. If None (default), auto-detects: - ChartResult: uses last_updated (as ISO string with time) - TableResult/IndicatorResult: uses version
Returns:
-
T–Single item with the highest value for the specified field.
Raises:
-
ValueError–If no results are available.
-
AttributeError–If the specified attribute doesn't exist on the results.
Example
Source code in lib/catalog/owid/catalog/api/models.py
to_frame
¶
to_frame(all_fields: bool | None = None) -> DataFrame
Convert results to a DataFrame.
Parameters:
-
all_fields(bool | None, default:None) –If True, show all fields. If False, show only key fields. If None (default), use the instance's _ui_advanced setting.
Returns:
-
DataFrame–DataFrame with one row per result.
Source code in lib/catalog/owid/catalog/api/models.py
to_dict
¶
Convert results to a list of plain dictionaries.
Useful for serializing results for AI/LLM context windows or any scenario where you need simple dict representations.
Returns:
Example
Source code in lib/catalog/owid/catalog/api/models.py
filter
¶
filter(predicate: Callable[[T], bool]) -> ResponseSet[T]
Filter results by predicate function.
Returns a new ResponseSet with only items that match the predicate. The predicate should return True for items to keep.
Parameters:
-
predicate(Callable[[T], bool]) –Function that takes an item of results (e.g. ChartResult) and returns True/False.
Returns:
-
ResponseSet[T]–New ResponseSet with filtered results.
Example
Source code in lib/catalog/owid/catalog/api/models.py
sort_by
¶
sort_by(
key: str | Callable[[T], Any], *, reverse: bool = False
) -> ResponseSet[T]
Sort results by attribute name or key function.
Returns a new ResponseSet with items sorted by the specified key.
Parameters:
-
key(str | Callable[[T], Any]) –Either an attribute name (string) or a function that extracts a comparison key from each item.
-
reverse(bool, default:False) –If True, sort in descending order (default: False).
Returns:
-
ResponseSet[T]–New ResponseSet with sorted results.
Example
>>> # Sort by version (ascending)
>>> results.sort_by('version')
>>> # Sort by version (descending - latest first)
>>> results.sort_by('version', reverse=True)
>>> # Sort by custom function (e.g., by score)
>>> results.sort_by(lambda r: r.score, reverse=True)
>>> # Chain sorting and filtering
>>> results.filter(lambda r: r.version > '2024').sort_by('version', reverse=True)
Source code in lib/catalog/owid/catalog/api/models.py
set_ui_advanced
¶
set_ui_advanced() -> ResponseSet[T]
Switch to advanced display showing all fields (type, slug, popularity, etc.).
Returns:
-
ResponseSet[T]–Self (for chaining).
Source code in lib/catalog/owid/catalog/api/models.py
set_ui_basic
¶
set_ui_basic() -> ResponseSet[T]
Switch to basic display showing only key fields (title, description, url).
Returns:
-
ResponseSet[T]–Self (for chaining).
Source code in lib/catalog/owid/catalog/api/models.py
owid.catalog.api.charts.ChartResult
¶
Bases: BaseModel
An OWID chart (from fetch or search).
Fields populated depend on the source: - fetch(): Provides config and metadata - search(): Provides subtitle, available_entities, num_related_articles, published_at, last_updated, popularity
Core fields (slug, title, url) are always populated.
Attributes:
-
slug(str) –Chart URL identifier (e.g., "life-expectancy").
-
title(str) –Chart title.
-
url(str) –Full URL to the interactive chart.
-
config(dict[str, Any]) –Raw grapher configuration dict (from fetch).
-
metadata(dict[str, Any]) –Chart metadata dict including column info (from fetch).
-
subtitle(str) –Chart subtitle/description (from search).
-
available_entities(list[str]) –List of entities/countries in the chart (from search).
-
num_related_articles(int) –Number of related articles (from search).
-
published_at(datetime | None) –When the chart was first published (from search).
-
last_updated(datetime | None) –When the chart was last updated (from search).
-
popularity(float) –Popularity score (0.0 to 1.0) based on analytics views (from search).
Methods:
-
fetch–Fetch chart data as ChartTable with rich metadata.
chart_base_url
property
¶
chart_base_url: str
Base URL for this chart type (grapher or explorer, derived from site_url and type).
url
property
¶
url: str
Full URL to the interactive chart (built from chart_base_url, slug, and query_params).
fetch
¶
fetch(*, load_data: bool = True) -> ChartTable
Fetch chart data as ChartTable with rich metadata.
Parameters:
-
load_data(bool, default:True) –If True (default), load full chart data. If False, load only structure (columns and metadata) without rows.
Returns:
-
ChartTable–ChartTable with chart data and chart_config. Column metadata (unit, description, etc.)
-
ChartTable–is populated from the chart's metadata.json.
Note
Explorer views (type="explorerView") are best-effort. Some explorers
may return 503 or other errors from their CSV endpoint. In those cases an
:class:ExplorerFetchError is raised with details.
Example
Source code in lib/catalog/owid/catalog/api/charts.py
owid.catalog.api.indicators.IndicatorResult
¶
Bases: BaseModel
An indicator found via semantic search.
Attributes:
-
title(str) –Indicator title/name.
-
indicator_id(int | None) –Unique indicator ID.
-
path(str | None) –Path in the catalog (e.g., "grapher/un/2024-07-12/un_wpp/population#population").
-
channel(str | None) –Data channel (parsed from path).
-
namespace(str | None) –Data provider namespace (parsed from path).
-
version(str | None) –Version string (parsed from path).
-
dataset(str | None) –Dataset name (parsed from path).
-
column_name(str) –Column name in the table.
-
description(str) –Full indicator description.
-
unit(str) –Unit of measurement.
-
score(float) –Semantic similarity score (0-1).
-
n_charts(int | None) –Number of charts using this indicator.
-
popularity(float) –Popularity score (0.0 to 1.0) based on analytics views.
Methods:
-
fetch–Fetch indicator data as a single-column Table.
-
fetch_table–Fetch the full table containing this indicator.
fetch
¶
Fetch indicator data as a single-column Table.
Parameters:
-
load_data(bool, default:True) –If True (default), load full indicator data. If False, load only structure (columns and metadata) without rows.
Returns:
-
Table–Table with the indicator column (plus index). Metadata is preserved.
Example
Source code in lib/catalog/owid/catalog/api/indicators.py
fetch_table
¶
Fetch the full table containing this indicator.
Parameters:
-
load_data(bool, default:True) –If True (default), load full table data. If False, load only structure (columns and metadata) without rows.
Returns:
-
Table–Table with all columns including this indicator.
Example
Source code in lib/catalog/owid/catalog/api/indicators.py
owid.catalog.api.tables.TableResult
¶
Bases: BaseModel
A table found in the catalog.
Attributes:
-
table(str) –Table name.
-
path(str) –Full path to the table.
-
channel(str) –Data channel (garden, meadow, etc.).
-
namespace(str) –Data provider namespace.
-
version(str) –Version string.
-
dataset(str) –Dataset name.
-
dimensions(list[str]) –List of dimension columns.
-
title(str | None) –Human-readable title (from table or dataset metadata).
-
description(str | None) –Detailed description (from table or dataset metadata).
-
is_public(bool) –Whether the data is publicly accessible.
-
formats(list[str]) –List of available formats.
-
popularity(float) –Popularity score (0.0 to 1.0) based on analytics views.
Methods:
-
fetch–Fetch table data.
fetch
¶
Fetch table data.
Parameters:
-
load_data(bool, default:True) –If True (default), load full table data. If False, load only structure (columns and metadata) without rows.
Returns:
-
Table–Table with data and metadata (or just metadata if load_data=False).