stdnum.es.cups

CUPS (Código Unificado de Punto de Suministro, Spanish meter point number).

CUPS codes are used in Spain as unique identifier for energy supply points. They are used both for electricity and pipelined gas.

The format is set by the Energy Ministry, and individual codes are issued by each local distribution company. The number consist or 20 or 22 digits and is built up as follows:

  • LL: (letters) country (always ‘ES’ since it is a national code)

  • DDDD: (numbers) distribution company code (numeric)

  • CCCC CCCC CCCC: identifier within the distribution company (numeric)

  • EE: (letters) check digits

  • N: (number) border point sequence

  • T: (letter) kind of border point

More information:

>>> validate('ES 1234-123456789012-JY')
'ES1234123456789012JY'
>>> validate('ES 1234-123456789012-JY 1T')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> validate('ES 1234-123456789012-XY 1F')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> format('ES1234123456789012JY1F')
'ES 1234 1234 5678 9012 JY 1F'
stdnum.es.cups.calc_check_digits(number: str) str

Calculate the check digits for the number.

stdnum.es.cups.compact(number: str) str

Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.es.cups.format(number: str) str

Reformat the number to the standard presentation format.

stdnum.es.cups.is_valid(number: str) bool

Check if the number provided is a valid CUPS.

stdnum.es.cups.validate(number: str) str

Check if the number provided is a valid CUPS. This checks length, formatting and check digits.