Skip to content

About

UK open data in Python for civil society, from charities and community groups to researchers and students.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

uk-open-data

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

Map of Lewisham and Greenwich. Each neighbourhood is shaded by how many
people a charity reached there, from fewer than 5 to 50 or more.

People reached, by neighbourhood, drawn by this package. Real neighbourhoods of Lewisham and Greenwich; the counts are invented.

Try it

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.

What is in it

  • Data modules. uk_open_data.geo loads boundaries from the ONS Geoportal, uk_open_data.ons loads statistics from the Nomis API, uk_open_data.postcodes turns postcodes into geography codes, and uk_open_data.imd loads 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 run runs 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.

Installation

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 pandas

To 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.

Quick start

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     301037

postcodes_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.

Examples

Interactive notebooks you can run in the browser:

Notebook Description
Open in molab Browse and load ONS datasets from the NOMIS API
Open in molab Explore UK geographic boundaries
Open in molab Join boundaries with statistics

Case studies

End-to-end reproductions of DataKind UK charity projects, each chaining several connectors on geography_code:

Notebook Case study
Open in molab Smart Works — women's unemployment vs service reach (Census 2021 + LAD boundaries)
Open in molab Citizens Advice Lewisham — deprivation vs service usage (postcodes + IMD + LSOA boundaries)
Open in molab Sobus — mental-health referrals of ethnic minorities in Hammersmith & Fulham (outcodes + Census ethnicity)
Open in molab Starlight — hospital play provision vs need across ICBs
Open in molab Material Focus — travel time to the nearest recycling point (LAD boundaries + population)

See the case studies in the docs for the full write-ups and figures.

For students and researchers

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.

Use it from an AI assistant

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.

Development

See DEVELOPERS.md for development setup and workflow instructions.

Licence

Apache-2.0. See LICENSE and NOTICE. Version 0.1.0 was published under the MIT License; its notice is kept in NOTICE.

About

UK open data in Python for civil society, from charities and community groups to researchers and students.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages