Skip to main content

QUEENS (Queryable Energy National Statistics) — ETL + API + CLI for UK energy data.

Project description

QUEENS

PyPI version PyPI - Python Version License: MIT

QUEENS (QUEryable Energy National Statistics) is a Python package that:

  • ingests UK energy National Statistics Excel tables into SQLite,
  • stages a consistent snapshot (one version per table at a time),
  • serves the staged data via FastAPI,
  • exposes a CLI and Python facade for querying and export.

Think of it as the royal counterpart to DUKES — a principled, machine-readable layer over DESNZ publications (DUKES, Energy Trends etc.).

There is a live demo hosted on Render, with a sample database (all of DUKES 2025).

See examples in this notebook!


Why this exists

I used to work in the Energy Statistics team, collaborating at the publication of DUKES and related collections. We constantly received requests from policy colleagues and modellers for data and insights that required considerable manual manipulation of the published tables.

I always wished there was a queryable counterpart to the public-facing Excel files — something that preserved the authority of the published stats, but removed the drudgery.

QUEENS is the result of that mindset: reproducible ingestion, strict schema validation, data versioning, and a simple API so analysts can focus on insight rather than wrangling — all while ensuring consistency with the official published numbers.

Another driver was that whenever we provided figures externally, we were obliged to use the published versions (since they were the “true” source), even though internal files were easier to handle but often out of sync. With QUEENS, the published spreadsheets become directly usable, versioned, and queryable.


Customisable and extendable

Although QUEENS ships ready-made for DUKES and related DESNZ tables, it isn’t limited to them.
Users can extend it to other collections by providing their own table templates and schema definitions.

Because ingestion is versioned, you can safely ingest multiple vintages of the same tables and then stage whichever version you wish.
This makes it straightforward to track revisions, compare snapshots across releases, or reproduce results tied to a specific publication date.

In this way, QUEENS can serve as a general-purpose bridge between human-readable official spreadsheets and clean, queryable datasets — one that not only structures the data, but also preserves its history.


Install

pip install queens

10-second quickstart

CLI

# ingest a table (or omit --table to ingest all)
queens ingest dukes --table 5.6

# stage the latest snapshot
queens stage dukes

# run the API (defaults to http://127.0.0.1:8000)
queens serve

Python

import queens as q

q.setup_logging(level="info") # optional
q.ingest("dukes", tables="6.1")
q.stage("dukes")
df = q.query("dukes", "6.1", filters={"year": {"gte": 2020}})
print(df.head())

Full walkthroughs (config, filters, pagination, exports, etc.): see demo notebooks in examples/.


Documentation


Key ideas (at a glance)

  • Read from GOV.UK: data are sourced directly from the official source, ensuring consistency with the publicly available version.
  • RAW → PROD: raw ingests are versioned; staging creates a consistent snapshot per table in *_prod.
  • Strict validation: schema and dtypes enforced; duplicates rejected; metadata (_metadata) is rebuilt on stage.
  • Queryable API: /data/{collection} with JSON filters (flat or nested, $or supported), cursor pagination by rowid.
  • Portable: SQLite under the hood; exports to CSV/Parquet/Excel.

Notes

  • Data sources are public National Statistics from DESNZ pages. QUEENS automates access and reshaping; it does not alter official figures beyond deterministic formatting (long/flat) and indexing (mapping out to nested indexes).
  • For Parquet, install pyarrow or fastparquet.
  • The CLI serve command uses sensible defaults; if you expose host/port, ensure flags match your installed version.

Future development.

  • Extension to other data collections (Energy Trends, Energy Emissions statistics...).
  • Handling schema evolution of templates - e.g. if a table changes format at some point, being able to ingest both versions.

Version history

0.1.1 - 24 August 2025:
    First release
    
0.1.2 - 29 August 2025:
    Deployed a live demo on Render
    Fix: bug in CLI method serve that prevented passing custom host

Aythor and contacts

Alessandro Bigazzi (maintainer).

If you find a bug, please open an issue. For other enquiries, please e.mail me.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queens-0.1.2.tar.gz (254.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

queens-0.1.2-py3-none-any.whl (255.7 kB view details)

Uploaded Python 3

File details

Details for the file queens-0.1.2.tar.gz.

File metadata

  • Download URL: queens-0.1.2.tar.gz
  • Upload date:
  • Size: 254.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for queens-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fab05d4773e041ffabcef2775f5793e23eaaa820ecb54d014911ef381e3d5da4
MD5 4f0eec16d89777eafd1fad2b364f5b07
BLAKE2b-256 dcf51d9d0f35d64ceef8ad4cfaa9f4cde01cf68290adf06dd4c3b8a9ea538ae2

See more details on using hashes here.

File details

Details for the file queens-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: queens-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 255.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for queens-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1ea8f0c11c29712497a6000bdeb26a551e7061dbb5dfe0600d0121e3d2181b99
MD5 b8c4fcb4d217ace2c15f6dfa94942cb0
BLAKE2b-256 f620bcbce8a9ec4ef83ef711f1828776fc6d16de72dc75bd421dc63f8c0349cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page