Skip to main content

Python client for UK Power Networks Open Data

Project description

ukpyn

PyPI version Python 3.11+ License: CC BY 4.0

ukpyn is the official Python client for UK Power Networks Open Data Portal. It provides simple, ergonomic access to distribution network data to support energy sector analysis and decarbonisation efforts.

This README is intentionally concise for PyPI. Full guides and reference pages are published via GitHub Pages docs.

Documentation

Mission

ukpyn is built for accessibility to UK Power Networks open data:

  • If you are new to coding: start with clear defaults, copy-paste examples, and tutorials.
  • If you are experienced: use typed APIs, async workflows, exports, and low-level client control.

The package is designed to reduce friction without hiding power.

Features

  • Simple orchestrator-based API - Access data by category (LTDS, flexibility, GIS, powerflow, etc.)
  • Beginner-friendly defaults - Useful defaults for common queries, then optional filtering
  • Both sync and async support - Use whichever fits your workflow
  • Export to multiple formats - CSV, JSON, Excel, GeoJSON, Parquet, and more
  • Jupyter notebook friendly - Works in notebooks and scripts
  • Type hints throughout - Full IDE support with autocompletion

Installation

Recommended workflow: uv + your preferred environment

1) Create and activate an environment

Option A: conda

# Create and activate a Python 3.11 environment
conda create -n ukpyn python=3.11 -y
conda activate ukpyn

Option B: venv

# Create a virtual environment
python -m venv .venv

# Activate on macOS / Linux
source .venv/bin/activate

# Activate on Windows PowerShell
.venv\Scripts\Activate.ps1

2) Install uv

pip install uv

3) Install from this repository

# Clone and enter the repository (if you haven't already)
git clone https://github.com/UKPN-DSO/ukpyn.git
cd ukpyn

# Recommended: install using the lockfile
uv sync

Alternative uv pip installs:

# Editable install (base)
uv pip install -e .

# Editable install with dev tools
uv pip install -e ".[dev]"

# Editable install with all optional extras
uv pip install -e ".[all]"

Or install from PyPI with extras:

uv pip install ukpyn

uv pip install "ukpyn[dev]"

uv pip install "ukpyn[optional]"

uv pip install "ukpyn[all]"

Shell note: use double quotes for extras in PowerShell and bash. In Windows CMD, prefer uv pip install -e .[all].

Quick Start

1. Get an API key

  1. Create an account at UK Power Networks Open Data Portal
  2. Go to your profile and navigate to API keys
  3. Generate a new key

2. Set up your API key

Create a .env file in your project root:

UKPN_API_KEY=your_api_key_here

Or set it as an environment variable:

# macOS / Linux
export UKPN_API_KEY=your_api_key_here

# Windows PowerShell
$env:UKPN_API_KEY="your_api_key_here"

# Windows CMD
set UKPN_API_KEY=your_api_key_here

3. Start using ukpyn

Beginner path (first working call)

from ukpyn import ltds

# Fetch LTDS Table 3A with one filter
table_3a = ltds.get_table_3a(licence_area="EPN")
print(f"Rows returned: {len(table_3a.records)}")

Advanced path (multi-domain workflow)

from ukpyn import ltds, flexibility, gis, powerflow, curtailment

# Get LTDS Table 3A (observed peak demand at primary substations)
table_3a = ltds.get_table_3a(licence_area='EPN')

# Get flexibility dispatch events
dispatches = flexibility.get_dispatches(start_date='2024-01-01')

# Get primary substation locations
substations = gis.get_primary_substations(licence_area='SPN')

# Get 132kV circuit time series
circuits = powerflow.get_circuit_timeseries(voltage='132kv', granularity='half_hourly')

# Get curtailment events
events = curtailment.get_events(start_date='2024-01-01')

Learning Paths

Note: To run the tutorials, install the full set of dependencies with uv pip install "ukpyn[all]" (or pip install "ukpyn[all]").

Supported Domains

ukpyn provides themed orchestrators for each major data category on the UK Power Networks Open Data Portal:

  • ltds — Long Term Development Statement tables, published twice yearly: circuit data, transformer specs, observed and forecast demand, fault levels, distributed generation, connection queues, operational restrictions, infrastructure projects, and CIM network models.
  • dfes — Distribution Future Energy Scenarios: network capacity headroom by scenario and local authority, and peak demand forecasts.
  • dnoa — Distribution Network Options Assessment: reinforcement and flexibility option assessments and low-voltage DNOA results.
  • network — Aggregated network performance metrics: annual statistics, network losses, power quality indicators, and IIS interruption data.
  • flexibility — Flexibility market records: dispatch events (when services were called) and tender procurement data.
  • curtailment — Site-specific curtailment event records: when generation or demand was curtailed by network instruction.
  • ders (alias: resources) — Distributed Energy Resources: embedded capacity register (≥ 1 MW and < 1 MW), large demand customer list, and embedded power stations.
  • gis — Geospatial / infrastructure assets: substation sites and coverage areas, overhead lines by voltage, poles and towers, licence boundaries, and IDNO areas.
  • powerflow — Half-hourly and monthly operational time series for circuits and transformers at 132 kV, 33 kV (split by EPN/SPN), and primary (33/11 kV).

Additional dataset groups are accessible directly via the registry (no dedicated orchestrator required):

  • Equipment — Grid, primary, secondary, and super-grid transformer specifications and secondary site utilisation.
  • Connections — Connection queue insights, GSP-level status and narratives, wide area planning status, and modification applications.
  • Operations — Real-time constraint meter readings, constraint breach history, EHV outages, live faults, and rota disconnection schedules.
  • Sensitivity — Network sensitivity factors for import and export.
  • Smart Meter & LCT — Smart meter consumption at substation and LV feeder level, installation volumes, and low carbon technology deployment by LSOA and secondary substation.
  • Profiles — Standard electricity demand profiles, technology-specific generation profiles, and data centre demand profiles.
  • Appendix G — Active Network Management (ANM) configuration: settings, aggregated views, project progression, and site-specific conditions.
  • Reference — Supporting metadata: local authority boundaries, business glossary, data roadmap, data maturity scores, and EV chargepoint register.

See full API usage patterns in the docs site: https://ukpn-dso.github.io/ukpyn/

Licence Areas

UK Power Networks operates three distribution licence areas:

  • EPN - Eastern Power Networks (East of England)
  • LPN - London Power Networks (Greater London)
  • SPN - South Eastern Power Networks (South East England)

Many datasets can be filtered by licence area using the licence_area parameter. Use the abbreviation EPN/SPN/LPN

Contributing

We welcome contributions from beginners and experienced developers.

See Contributing Guidelines for full details.

  • Found a bug or have a question? Please open an issue — it helps us improve ukpyn for everyone.
  • Have ideas for better utilities? Our ukpyn.utils module provides time series, statistical, and powerflow helpers — if you think we're missing something or could improve what's there, tell us in an issue. Community input shapes what we build next.
  • Open a pull request with focused changes and tests.
  • If you are new to open source, small documentation improvements are a great first contribution.

Development Setup

# Clone the repository
git clone https://github.com/UKPN-DSO/ukpyn.git
cd ukpyn

# Install development dependencies
pip install ukpyn[dev]

# (Optional) install full optional feature set as well
pip install ukpyn[optional]

# Install dependencies with uv
uv sync

# Run tests
pytest

# Run linter
ruff check .

# Fix linting issues
ruff check --fix .

# Run pre-commit hooks
pre-commit run --all-files

Git Workflow

  • main - Protected branch for releases only
  • dev - Integration branch for development
  • feature/* - Feature branches for all work

Automated Registry Triage

  • Daily registry audit runs via GitHub Actions to detect new unmanaged ODP datasets.
  • When new unmanaged datasets are found, automation opens a triage issue assigned to copilot.
  • The issue includes standardized tasks: decide orchestrator/registry placement, implement support, add a tutorial example, and open a PR into dev with maintainers assigned for review.

Security

Please see SECURITY.md for our security policy.

Important: Never commit API keys or .env files to version control.

Acknowledgements

The vision for ukpyn as an accessible Python interface for UK Power Networks open data, along with the value proposition and initial scope, was developed with consultation from Dr Daniel Donaldson, Electronic, Electrical and Systems Engineering, University of Birmingham, Birmingham, United Kingdom.

License

This project is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0) - see the LICENSE file for details.

Redistributions and derivative works should retain attribution notices, including the NOTICE file, to acknowledge UK Power Networks Distribution System Operator.

Links

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

ukpyn-1.0.17.tar.gz (8.9 MB view details)

Uploaded Source

Built Distribution

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

ukpyn-1.0.17-py3-none-any.whl (95.5 kB view details)

Uploaded Python 3

File details

Details for the file ukpyn-1.0.17.tar.gz.

File metadata

  • Download URL: ukpyn-1.0.17.tar.gz
  • Upload date:
  • Size: 8.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ukpyn-1.0.17.tar.gz
Algorithm Hash digest
SHA256 921749b45aab9e933eb87614fa0df0d7dbf3a6847d55c00b2c2d1e89846daca9
MD5 eb81979d6d4959d2d6aaa4527e48d9e5
BLAKE2b-256 7354f0d5cc1200615fd8e53b4ca868e6cae380884cf066153a2d9e279f7fe716

See more details on using hashes here.

Provenance

The following attestation bundles were made for ukpyn-1.0.17.tar.gz:

Publisher: publish-pypi.yml on UKPN-DSO/ukpyn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ukpyn-1.0.17-py3-none-any.whl.

File metadata

  • Download URL: ukpyn-1.0.17-py3-none-any.whl
  • Upload date:
  • Size: 95.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ukpyn-1.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 1998b05fb44244f74cf9b50df1403e6c26f3bc0dd1cedda96829f3910318f1e5
MD5 aa4cd26e3598c9b11e3f53c931e4fbf9
BLAKE2b-256 4ab34a20e7e5487cf6a43ae034bdb38fe9ea7986a8e98ceea6d0560c9b164628

See more details on using hashes here.

Provenance

The following attestation bundles were made for ukpyn-1.0.17-py3-none-any.whl:

Publisher: publish-pypi.yml on UKPN-DSO/ukpyn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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