UK open data in Python for civil society: load public data, join it to your own, and get figures you can check.
Docs · Questions and ideas · Contribute
People reached, by neighbourhood, drawn by this package. Real neighbourhoods of Lewisham and Greenwich; the counts are invented.
You need uv. These lines install the
uk-open-data command, list the six analyses and run one on a spreadsheet of
your own.
uv tool install --with pandas uk-open-data
uk-open-data analysis list
uk-open-data postcodes download
uk-open-data analysis run reach-deprivation clients.csv --column postcode="Client postcode"Put your own file in place of clients.csv, and the name of your postcode
column in place of Client postcode. postcodes download fetches a table of
postcodes once, so the analysis looks them up on your machine and sends none
out. The report holds totals only.
Made by KindTech UK. Up to version 0.1 the
package was called kindtech, which gets no new releases. The first datasets
are geographic boundaries, official statistics, postcodes and deprivation
indices, with more on the way.
- Data modules.
uk_open_data.geoloads boundaries from the ONS Geoportal,uk_open_data.onsloads statistics from the Nomis API,uk_open_data.postcodesturns postcodes into geography codes, anduk_open_data.imdloads the deprivation indices. Bring your own DataFrame backend, pandas or polars. - Analyses. Each analysis answers one question a charity asks of its own data, such as "Are we reaching people in the most deprived neighbourhoods?". It returns totals, the working, the sources and what a person must check. Nothing in a result describes one person.
- A command line.
uk-open-data analysis runruns an analysis on a file without writing any Python. - A connector for chat assistants. The same analyses and data as tools for an assistant such as Claude or ChatGPT. The assistant sees totals, never rows.
These analyses follow work first done by DataKind UK volunteers with charities.
Install uk-open-data from PyPI with
a DataFrame library, pandas or polars. uv add needs a uv project, so make one
first if you are not in one:
uv init
uv add uk-open-data pandasTo try it without a project, uv run --with uk-open-data --with pandas python
opens Python with both installed.
The uk-open-data package includes uk_open_data.geo, uk_open_data.ons,
uk_open_data.postcodes, and uk_open_data.imd. See the
package FAQ for how these
subpackages are installed and released together.
import pandas as pd # or polars
from uk_open_data import (
geodata_to_properties,
load_geodata,
load_ons,
postcodes_to_geography,
)
# Local authority boundaries from the ONS Geoportal
geojson = load_geodata(geography_type="LAD", year="2025", boundary_type="BUC")
areas = pd.DataFrame(geodata_to_properties(geojson, "LAD", 2025))
# Population of each local authority from Nomis: all persons, all ages
population = load_ons(
"population",
geography_type="LAD",
time="latest",
measures=20100,
gender=0,
c_age=200,
select=["geography_code", "obs_value"],
)
# Every dataset has a geography_code column, so they join directly
areas = areas.merge(population, on="geography_code")
# Your own postcodes, placed in the same local authorities
located = postcodes_to_geography(["SE13 7HX", "SE6 4RU"], geography_type="LAD")
located.merge(population, on="geography_code")
# postcode geography_code geography_name obs_value
# 0 SE13 7HX E09000023 Lewisham 301037
# 1 SE6 4RU E09000023 Lewisham 301037postcodes_to_geography sends the postcodes to postcodes.io, even when the
postcode table is installed. To keep postcodes on your machine, run an analysis
after uk-open-data postcodes download.
The user guide covers each module.
Interactive notebooks you can run in the browser:
| Notebook | Description |
|---|---|
| Browse and load ONS datasets from the NOMIS API | |
| Explore UK geographic boundaries | |
| Join boundaries with statistics |
End-to-end reproductions of DataKind UK charity
projects, each chaining several connectors on geography_code:
See the case studies in the docs for the full write-ups and figures.
The same loaders work for coursework, a dissertation or a research project. Each one fetches from an official source, and Data sources explains the APIs behind them. The notebooks above run in the browser with nothing to install.
Students and researchers are welcome to contribute: a new data source, a worked analysis, or a fix to the docs. The guides to adding a data source and adding an analysis walk through each one. Read the contributing guide and DEVELOPERS.md, then open an issue to say what you would like to work on.
In Claude Code, install the plugin:
/plugin marketplace add KindTechUK/plugins
/plugin install uk-open-data@kindtech
For other assistants, the connector offers the analyses and data over the Model Context Protocol. Coding agents can read the docs as Markdown: llms.txt lists every page, and llms-full.txt holds them all in one file.
See DEVELOPERS.md for development setup and workflow instructions.
Apache-2.0. See LICENSE and NOTICE. Version 0.1.0 was published under the MIT License; its notice is kept in NOTICE.
