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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file mpan-1.0.0.tar.gz.

File metadata

  • Download URL: mpan-1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.0-43-generic

File hashes

Hashes for mpan-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3d90b2aa90a42c97937ffe8ccd0812245ad7a51099067ca03d8bbcdc2b3f3463
MD5 7ec95009d8604d4948c056d13a36a1e0
BLAKE2b-256 60c851ec06fca1622997784e2d5f5c242faf07bf9666e3df80dbac8d8f607cc4

See more details on using hashes here.

File details

Details for the file mpan-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mpan-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.0-43-generic

File hashes

Hashes for mpan-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73dedac067c2dcce75db7742457bb8da3161a3c95d1e439997a1e1738720828c
MD5 ac9182821580fcb00552f15965bae9c0
BLAKE2b-256 4c67e627c940a8bf77e18b5dda820f4440086e3217dd9620cde49f1a473fd183

See more details on using hashes here.

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