class canlib.EAN(source)[source]

Helper object for dealing with European Article Numbers

Depending on the format the ean is in, EAN objects are created in different ways;

For strings:


For integers:


For iterables of integers:

EAN([7, 3, 3, 0, 1, 3, 0, 0, 1, 2, 3, 4, 5])

For BCD-coded bytes or bytearrays (str in python 2):


For “hi-lo” format, i.e. two 32-bit integers containing half the ean each, both BCD-coded:

EAN.from_hilo([eanHi, eanLo])

The various representations can then be produced from the resulting object:

>>> str(ean)
>>> int(ean)
>>> tuple(ean)  # or list(), or any other sequence type
(7, 3, 3, 0, 1, 3, 0, 0, 1, 2, 3, 4, 5)
>>> ean.bcd()
>>> ean.hilo()
(805380933, 471809)

Sometimes it is easier to only use the last six digits of the ean, the product code and check digit. This is supported when working with string representations; the constructor supports six-digit (seven-character) input:


In that cases, the country and manufacturer code is assumed to be that of Kvaser AB (73-30130).

A string containing only the product code and check digit can also be retrieved:


Instances can also be indexed which yields specific digits as integers:

>>> ean[7]
>>> ean[7:]
(0, 1, 2, 3, 4, 5)


The byteorder is currently always assumed to be ‘little’.


Return a binary-coded bytes object with this EAN

fmt = '##-#####-#####-#'
classmethod from_bcd(bcd_bytes)[source]

Create an EAN object from a binary coded bytes-like object

The EAN is automatically shortened to the correct length.

classmethod from_hilo(hilo)[source]

Create an EAN object from a pair of 32-bit integers, (eanHi, eanLo)

classmethod from_string()

Create an EAN object from a specially formatted string

Deprecated since version 1.6: Use the constructor, EAN(ean_string), instead.


Return a pair of 32-bit integers, (eanHi, eanLo), with this EAN

num_digits = 13

Return only the product code and check digit of the string representation