Microproduct Data GuideBeginner

ONS Statistics API

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

Report a Problem

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
Last Verified
Aug 18, 2026
Source Type
Government Source
  • Python Syntax Checked
  • Runnable Notebook

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.

Formats

Provider

Office for National Statistics

Data Terms

Open Government Licence v3.0

Send Feedback