stdnum.gs1_128

GS1-128 (Standard to encode product information in Code 128 barcodes).

The GS1-128 (also called EAN-128, UCC/EAN-128 or UCC-128) is an international standard for embedding data such as best before dates, weights, etc. with Application Identifiers (AI).

The GS1-128 standard is used as a product identification code on bar codes. It embeds data with Application Identifiers (AI) that defines the kind of data, the type and length. The standard is also known as UCC/EAN-128, UCC-128 and EAN-128.

GS1-128 is a subset of Code 128 symbology.

More information:

>>> compact('(01)38425876095074(17)181119(37)1 ')
'013842587609507417181119371'
>>> encode({'01': '38425876095074'})
'0138425876095074'
>>> info('0138425876095074')
{'01': '38425876095074'}
>>> validate('(17)181119(01)38425876095074(37)1')
'013842587609507417181119371'
stdnum.gs1_128.compact(number)

Convert the GS1-128 to the minimal representation.

This strips the number of any valid separators and removes surrounding whitespace. For a more consistent compact representation use validate().

stdnum.gs1_128.encode(data, separator='', parentheses=False)

Generate a GS1-128 for the application identifiers supplied.

The provided dictionary is expected to map application identifiers to values. The supported value types and formats depend on the application identifier.

If a separator is provided it will be used as FNC1 representation, otherwise variable-sized values will be expanded to their maximum size with appropriate padding.

If parentheses is set the application identifiers will be surrounded by parentheses for readability.

stdnum.gs1_128.info(number, separator='')

Return a dictionary containing the information from the GS1-128 code.

The returned dictionary maps application identifiers to values with the appropriate type (str, int, Decimal, datetime.date or datetime.datetime).

If a separator is provided it will be used as FNC1 to determine the end of variable-sized values.

stdnum.gs1_128.is_valid(number, separator='')

Check if the number provided is a valid GS1-128.

stdnum.gs1_128.validate(number, separator='')

Check if the number provided is a valid GS1-128.

This checks formatting of the number and values and returns a stable representation.

If a separator is provided it will be used as FNC1 for both parsing the provided number and for encoding the returned number.