UK Gov Data

Government API · Works in UK · UK Government · 40,000+ datasets

TL;DR

Data.gov.uk is the UK government's open data portal with over 40,000 datasets from central government departments, devolved administrations, and local authorities. The CKAN-based REST API provides access to data on economy, crime, education, health, transport, environment, housing, and government spending. Key data sources include the Office for National Statistics (ONS), HM Revenue & Customs, Department for Transport, Department for Education, Ministry of Justice, and the Environment Agency. The API supports full CKAN v3 actions: package_search, package_show, organization_list, tag_list, and resource_show. Data is available in CSV, XLS, JSON, XML, and RDF formats with some datasets also providing direct API endpoints.

Quick start: https://data.gov.uk/api/3/action/package_list

No API key needed — just make a request!

How to Use This API

1. Search Datasets by Keyword

https://data.gov.uk/api/3/action/package_search?q=transport&rows=5
https://data.gov.uk/api/3/action/package_search?q=crime+statistics&rows=10&start=0

Full-text search with pagination using rows and start. Results include dataset title, notes, organization, resources, and metadata.

2. Get Dataset Details

https://data.gov.uk/api/3/action/package_show?id=road-accidents-safety-data
https://data.gov.uk/api/3/action/package_show?id=house-price-index

Returns full metadata including all resource URLs for downloading data files.

3. List Government Departments (Organizations)

https://data.gov.uk/api/3/action/organization_list?all_fields=true

Shows all publishing departments: Department for Transport, Ministry of Justice, NHS Digital, ONS, etc.

4. List All Tags

https://data.gov.uk/api/3/action/tag_list
https://data.gov.uk/api/3/action/tag_list?all_fields=true&query=health

Browse available tags to refine search queries.

5. Filter by Department

https://data.gov.uk/api/3/action/package_search?q=&fq=organization:department-for-transport
https://data.gov.uk/api/3/action/package_search?q=&fq=organization:office-for-national-statistics

6. Response Format

{
  "success": true,
  "result": {
    "count": 1200,
    "results": [
      {
        "id": "abc-123",
        "name": "road-accidents-safety-data",
        "title": "Road Accidents and Safety Data",
        "notes": "Detailed data about road traffic accidents...",
        "organization": {"name": "department-for-transport", "title": "Department for Transport"},
        "resources": [
          {"name": "2024 Accidents CSV", "format": "CSV", "url": "https://.../accidents.csv"}
        ],
        "tags": [{"name": "roads"}, {"name": "accidents"}]
      }
    ]
  }
}

7. JavaScript — Fetch UK Crime Data

fetch('https://data.gov.uk/api/3/action/package_search?q=crime+statistics&rows=3')
  .then(r => r.json())
  .then(d => {
    d.result.results.forEach(ds => {
      const title = ds.title.replace(/<[^>]*>/g, '');
      console.log(title);
      console.log(`  Updated: ${ds.metadata_modified?.slice(0, 10)}`);
      console.log(`  Formats: ${ds.resources.map(r => r.format).join(', ')}`);
    });
  });

8. Python — Search Department Data

import requests

params = {
    'q': 'house prices',
    'fq': 'organization:hm-land-registry',
    'rows': 5
}
resp = requests.get('https://data.gov.uk/api/3/action/package_search', params=params)
data = resp.json()
for ds in data['result']['results']:
    print(f"{ds['title']}")
    for res in ds.get('resources', []):
        print(f"  [{res['format']}] {res.get('name', 'Resource')}")

9. Python — Get Resource Download URLs

import requests

resp = requests.get(
    'https://data.gov.uk/api/3/action/package_show',
    params={'id': 'road-accidents-safety-data'}
)
data = resp.json()
for res in data['result']['resources']:
    if res['format'] == 'CSV':
        print(f"Download: {res['url']}")
Try it: https://data.gov.uk/api/3/action/package_search?q=transport&rows=3

Frequently Asked Questions

What types of datasets are available on data.gov.uk?
Economic indicators (GDP, inflation, trade from ONS), crime statistics by region and type (Ministry of Justice), school performance data (DfE), NHS health data (waiting times, prescriptions), transport networks (DfT), house prices (Land Registry), environmental data (Environment Agency), benefits and HMRC data, and more.
How do I find data from a specific government department?
Use fq=organization:department-for-transport in your query. Get organization names from /api/3/action/organization_list?all_fields=true. Common orgs: department-for-transport, ministry-of-justice, office-for-national-statistics, environment-agency.
What file formats are available?
CSV, XLS/XLSX, JSON, XML, and RDF are the most common. Some datasets provide API endpoints for direct querying without downloading files. Check the format field in each resource for available formats.
Can I access ONS data through this API?
Yes, the Office for National Statistics publishes many datasets on data.gov.uk covering population, economy, and society. ONS also has its own dedicated API for some datasets, but the CKAN API is a good starting point for discovery.
How current is the data?
Update frequency varies: ONS economic data is monthly or quarterly, crime data is annual, NHS data is monthly. Each dataset has a metadata_modified field showing the last update, and many include temporal coverage in their notes.
What is the rate limit on the CKAN API?
No specific rate limit is documented for data.gov.uk. Reasonable use is expected — avoid very high-frequency polling. For bulk data access, use direct resource downloads rather than repeated API queries.

What You Can Build