Microproduct data guidebeginner

ONS Statistics API

Official UK statistical datasets for building local labour, prices, and population tools from Office for National Statistics.

At a glance

Difficulty
Beginner — comfortable for a first prototype
Size
Small · ≤0.2 GB
Formats
JSON, CSV
Access
API or Download
API key
Not required
Provider
Office for National Statistics
Updates
Monthly

From source to product signal

Test a product idea in four steps

The ONS API returns dataset metadata and observations. Start with one edition of CPIH or a labour dataset and a few observations. UK statistics have geography codes that do not match U.S. FIPS, and some tables are still Excel-only.

1

Check the setup

  • Python 3.10 or newer
  • A notebook environment such as Jupyter or Google Colab
  • An internet connection
2

Access the data

  1. 1.Open the ONS developer hub and pick one dataset id.
  2. 2.Request the latest edition metadata, then a small observation slice.
  3. 3.Cite ONS under the Open Government Licence.
Open official source
3

Run the Python example

Install the packages, then run the notebook cell.

python -m pip install pandas requests

import pandas as pd
import requests

response = requests.get(
    "https://api.beta.ons.gov.uk/v1/datasets/cpih01/editions/time-series/versions/1/observations",
    params={"time": "latest", "geography": "K02000001"},
    timeout=30,
)
response.raise_for_status()
observations = pd.json_normalize(response.json().get("observations", []))
observations["retrieved_at_utc"] = pd.Timestamp.now(tz="UTC")
print(observations.head())
4

Test a useful signal

Read a UK CPIH observation

Test whether the ONS API can power a bounded UK prices card.

  1. 01Confirm an observation value returned for the selected dataset and geography.
  2. 02Record the edition version and observation time used.
  3. 03Cite ONS under OGL and explain that UK geography codes are not U.S. FIPS and that editions are versioned.

Dataset details

Office for National Statistics is a government source. Last verified 2026-08-18. Temporal coverage: dataset-specific ONS time series.

Theme

Demographics & Development

Domains

DemographicsLabor EconomicsInternational Statistics

Data types

Time SeriesTabular

Tasks

Local StatisticsCountry ComparisonTrend Analysis

Geography

United Kingdom

Formats

JSONCSV

Provider

Office for National Statistics

Data terms

Open Government Licence v3.0