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.1.1.tar.gz (9.8 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.1.1-py3-none-any.whl (97.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ukpyn-1.1.1.tar.gz
Algorithm Hash digest
SHA256 a8bcb61f37eeeb65429ca1973b320a36d5171991e3811e4c008e375662665d05
MD5 68eefa988c204db6b1dd2e24b0cf22e8
BLAKE2b-256 da6f07a8834ce1612621823002cb67e821af953fbd8244a63881f97710218763

See more details on using hashes here.

Provenance

The following attestation bundles were made for ukpyn-1.1.1.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.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for ukpyn-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d171059616fa5d8b6d478c3f14d4a5146e3bd5b70cb6f855af65c07579475103
MD5 ee4b98b5a61fb8007b994a506ea4dad0
BLAKE2b-256 c236cba4beb0a2afb53c11c7ce3e9cc407222f421c9e946e8cc9dd99f249d236

See more details on using hashes here.

Provenance

The following attestation bundles were made for ukpyn-1.1.1-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