Skip to main content

A parsing library for the UK's MPAN energy standard

Project description

Limejump logo

mpan

Black

mpan is a library to help you parse the UK energy industry's MPAN number format.

How it works

from mpan import InvalidMPANError, MPAN


mpan = MPAN("018011002012345678385")

print(mpan.core)  # 2012345678385
print(mpan.identifier)  # 12345678
print(mpan.is_short)  # False
print(mpan.profile_class.description)  # "Domestic unrestricted"
print(mpan.distributor.is_dno)  # True
print(mpan.distributor.area)  # "Southern England"

if mpan.is_valid:
    print("Looks good to me!")

try:
    mpan.check()
except InvalidMPANError:
    print("This MPAN is broken")

There's also a shortcut if you just want validation:

from mpan import is_valid


if is_valid("<an MPAN string>"):
    print("Looks good to me too!")

Installation

It's on PyPI:

$ pip install mpan

Requirements

This is a pure-python module with no external dependencies. However, you'll need to be running Python 3.8 or higher.

Development

Setting up a Local Development Environment

We're using Poetry, so if you want to make some changes, you should install that and then just run poetry install. This will pull in all the development dependencies like pytest, isort, etc.

Deployment/Releases

To build, use Poetry:

$ poetry build

To publish a new release, use Poetry for that too:

$ poetry publish

Testing

When inside your virtualenv, just run:

$ pytest

External Documentation

This is based largely on the Wikipedia article on the MPAN standard. The validation code for example is cribbed right from there.

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

mpan-1.0.0.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

mpan-1.0.0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

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