UN data in Python, without the guessing: an unofficial client for the UN System Data Commons (data.un.org), with SDG progress analysis, publication-ready charts and an MCP connector for AI assistants.
pip install undata==0.4.3 Copy PIP instructions
Try it in your browser, no install → · Twelve use cases, with real output → · Six two-minute videos → · API reference →
Type a country's name, get a table. undata is a Python package for the UN System Data Commons, which holds statistics from 26 UN System entities. It is written for colleagues who need numbers for a report, not a course in APIs.
Alpha. It works today; the API may still change before 1.0. Unofficial. A Nerd Lab experiment, not affiliated with or endorsed by the United Nations. The data belongs to the agencies that publish it.
pip install undata import undata as un table = un.get("undata/sdg/SH_STA_MORT.SEX--F", ["Bangladesh", "Viet Nam"]) un.save(table, "maternal-mortality.xlsx") # data on one sheet, citations on the next New to Python? Open the first-table notebook in Google Colab: it runs in your browser, with nothing to install, and walks from a question to a chart and an Excel file in five minutes. In your own Colab notebook, run !pip install undata in the first cell. For the latest unreleased changes: pip install "git+https://github.com/nerd-factory/undata".
Don't know the indicator's id? un.search("maternal mortality") lists matching indicators with their names. Copy the id from the first column.
Wherever a function asks for countries you can write names the way you would in an email ("Viet Nam", "Vietnam", "VNM"), a list of them, a region such as "Southern Asia" or "Africa", or a UN group: "LDCs", "LLDCs", "SIDS". Wherever it asks for an indicator, an SDG number such as "3.1.1" works when one series reports it. Every function explains itself: help(un.get), and the API reference documents every parameter.
undata search "maternal mortality" undata totals 3.1.1 World LDCs SIDS --latest undata change 3.1.1 "Southern Asia" --start 2015 --end 2023 --describe undata get 3.1.1 LDCs --years 2015-2023 --to maternal-mortality.xlsx undata powerquery 3.1.1 "Southern Asia" > query.m Every table has the same columns:
country iso3 year value unit indicator_name indicator source source_url The country list is the UN's own Countries, regions and groups come from UN M49, the UN Statistics Division's standard, shipped with the package and checked against the UN's current table every night. Tables use official UN names, regions follow M49, and the LDC, LLDC and SIDS groups are the current UN lists (44, 32 and 53 countries), not the platform's older copies. Places the platform holds outside M49 are left out of every list, region and group; they can still be asked for by platform code, such as country/XKS.
table = un.progress("3.1.1", "LDCs", better="lower", target=70) un.chart(table, "ldc-progress.png") print(un.describe(table))
un.progress follows the UN Statistics Division's Technical Note for Progress Assessment step by step. It takes each country's growth rate since 2015 and projects it to 2030. With a target, it compares the projected change with the change the target needs; without one, it scores the growth rate. Each country then lands in the five categories the SDG Report uses, from "on track" to "regression", with the method cited in the table. un.profile, un.gap, un.trend, un.benchmark and un.availability cover the other questions that come up in every country analysis and progress report, and each has a chart made for it.
un.chart(table) looks at the table and picks the chart: ranked bars, lines, small multiples when there are too many lines, before-and-after dot plots, a scatter for two indicators, a heatmap of who reports what, a tile map with one equal square per country, or the progress, profile and gap charts above. Every chart carries its title, unit and source line, labels its marks directly, and uses palettes checked for colour blindness. PNG at 300 dpi, or SVG and PDF with text left editable. context="slides" sizes it for a presentation, interactive=True returns a Plotly chart with hover (pip install "undata[interactive]"), and un.style() gives your own matplotlib and seaborn charts the same look. Tile maps avoid drawing borders, so they take no position on disputed boundaries.
undata is also an MCP connector, so an AI assistant such as Claude can search UN indicators, fetch data and run the analyses itself, with the sources, years and gaps in every answer. Ask it "Which least developed countries are on track to bring maternal mortality below 70 by 2030? Show me a chart." and it calls the same functions you would.
It needs uv, which fetches Python and the package on first use. In Claude Desktop, open Settings → Developer → Edit Config and add:
{ "mcpServers": { "undata": { "command": "uvx", "args": ["--from", "undata[mcp]", "undata-mcp"] } } } In Claude Code: claude mcp add undata -- uvx --from "undata[mcp]" undata-mcp. Any other MCP client can run undata-mcp (after pip install "undata[mcp]") over stdio, or undata-mcp --http for Streamable HTTP on http://127.0.0.1:8000/mcp.
Every tool only reads, needs no account or key, and answers with a table, a summary sentence, the data-quality notes and the sources. The analysis tools can also return their chart as an image.
table = un.latest("3.1.1", "LDCs", within=10) un.ai_pack(table, "maternal-mortality.zip") # upload, then paste prompt.md print(un.for_ai(table, task="brief")) # or paste this as one message The pack holds data.csv, metadata.md (what each column means; each indicator's unit, source and citation; how complete the data is; the caveats) and prompt.md (rules that keep the assistant to these numbers, and a task). Tasks: explain, brief, trends, gaps, chart.
Each behaviour is pinned by a test in tests/live/ that runs against the real platform every night and opens an issue if the platform changes. Most of them were found while writing the UN Data Commons Field Guide.
Twelve requests as they arrive in UN work, each a runnable script in examples/ that ends with a sentence ready for the report:
They run against the live platform every night. The use-cases page shows each with its code, a chart, the real output and the sentence.
The friendly functions sit on three layers you can use directly: undata.Transport (the only code that touches the network), undata._endpoints (one thin wrapper per API route), and undata.dcid (the identifier grammar). PLAN.md covers the design and the road to 1.0.
git clone https://github.com/nerd-factory/undata && cd undata uv sync # Python 3.11+, installs dev tools uv run pytest # unit tests and doctests, offline uv run pytest -m live # pins the live platform's behaviour (network) uv run ruff check . && uv run ruff format --check . && uv run mypy See CONTRIBUTING.md. Questions that feel too basic are welcome in Nerd Lab Discussions; they are not too basic.
If you use undata in published work, cite it and the agency that published the data. GitHub shows a ready citation under Cite this repository, from CITATION.cff, and un.cite(table) writes the citation for the data itself:
Islam, M. undata: a Python client for the UN System Data Commons. https://github.com/nerd-factory/undata
undata was created and is maintained by Mafizul Islam, as a Nerd Lab project.
api-client data-commons data-visualization mcp model-context-protocol official-statistics open-data pandas sdg statistics sustainable-development-goals un-data united-nations
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.




