CUPS (Código Unificado de Punto de Suministro, Supply Point Unified Code)

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

Calculate the check digits for the number.

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

Reformat the number to the standard presentation format.

Check if the number provided is a valid CUPS.

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