Microproduct data guidebeginner

legislation.gov.uk

Consolidated UK legislation in machine-readable form for building statute lookup, citation, and change-monitoring tools.

At a glance

Difficulty
Beginner — comfortable for a first prototype
Size
Medium · ≤5 GB
Formats
XML, HTML, JSON
Access
API or Download
API key
Not required
Provider
The National Archives
Updates
Daily

From source to product signal

Test a product idea in four steps

legislation.gov.uk publishes consolidated UK Acts and statutory instruments through a documented HTTP API. Start with one well-known Act and its XML representation. The service is free to reuse commercially under OGL v3.0; some EU-derived items carry an additional Commission reuse notice.

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 developer zone and read the Open Government Licence attribution requirement.
  2. 2.Request the Data Protection Act 2018 as XML.
  3. 3.Keep the official URI when you cite a section in any downstream product.
Open official source
3

Run the Python example

Install the packages, then run the notebook cell.

python -m pip install pandas requests

import xml.etree.ElementTree as ET
import pandas as pd
import requests

response = requests.get(
    "https://www.legislation.gov.uk/ukpga/2018/12/data.xml",
    timeout=30,
)
response.raise_for_status()
root = ET.fromstring(response.content)
ns = {"a": "http://www.legislation.gov.uk/namespaces/legislation"}
title = root.findtext(".//a:Title", default="", namespaces=ns)
sections = [
    {
        "number": item.findtext("a:Number", default="", namespaces=ns),
        "title": item.findtext("a:Title", default="", namespaces=ns),
    }
    for item in root.findall(".//a:P1group", ns)[:20]
]
print(title)
print(pd.DataFrame(sections).head())
4

Test a useful signal

Extract section titles from one UK Act

Test whether legislation.gov.uk URIs can power a bounded statute browser.

  1. 01Parse the Data Protection Act 2018 XML and keep official section numbers.
  2. 02List the first twenty section titles and flag any missing numbers.
  3. 03Attribute Crown copyright under OGL v3.0 and note that EU-origin items may need a second acknowledgement.

Dataset details

The National Archives is a government source. Last verified 2026-08-18. Temporal coverage: historic and in-force UK legislation.

Theme

Government & Policy

Domains

LegislationPublic PolicyRegulation

Data types

DocumentsLegal Text

Tasks

Document SearchChange MonitoringCitation Research

Geography

United Kingdom

Formats

XMLHTMLJSON

Provider

The National Archives

Data terms

Open Government Licence v3.0