Skip to main content

A Python package to handle compression and decompression of GS1 digital links

Project description

GS1 Digital Link Decompression Prototype in Python

This package is a Python conversion of the GS1 digital link compression prototype in Javascript.

Background

The GS1 identification system is widely used worldwide within product barcodes, as well as within barcodes for shipments, assets, locations and so on.

Further information about GS1 can be found at https://www.gs1.org

Details about the GS1 identification system and GS1 Application Identifiers can be found in the GS1 General Specifications at https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf and a searchable list of GS1 Application Identifiers is at https://www.gs1.org/standards/barcodes/application-identifiers?lang=en

GS1 Digital Link is a new Web URI syntax for expressing GS1 Application Identifiers and their values in a Web-friendly format, to make it easier to connect identifiers of products, shipments, locations, assets etc. to related online information and services on the Web via simple Web redirects using Web resolver infrastructure.

The GS1 Digital Link syntax is defined in https://www.gs1.org/standards/Digital-Link/1-0

A demonstration tool is available at https://id.gs1.org/uritool although it does not currently use this toolkit

See also https://github.com/gs1/digital-link.js for a related toolkit for GS1 Digital Link

Examples

The following example uses the all-numeric application identifier 01 to indicate GTIN.

https://id.gs1.org/01/09780345418913

The following example uses short texts gtin lot and expdt to indicate GTIN, lot number and expiry date. A non-GS1 key-value pair {'k1': 'v1'} also appeared in this example.

https://id.gs1.org/gtin/05412345000013/lot/ABC%26%2B123?expdt=1903061658&k1=v1

Installation

To install, make sure Python3 is installed, and installation in a virtual environment is preferred.

$ pip install --upgrade gs1-compression

Usage

Decompression

To decompress a compressed GS1 Digital Link URI, import decompress_gs1_digital_link:

>>> from gs1 import decompress_gs1_digital_link

An example of decompression:

>>> compressed_uri = "https://id.gs1.org/ARHKVAdpQg"
>>> original_link = decompress_gs1_digital_link(compressed_uri, use_short_text=False)
>>> print("Original Link: " + original_link)
    Original Link: https://id.gs1.org/01/09780345418913

The decompress_gs1_digital_link function has two parameters.

Set the second parameter, use_short_text=True if you prefer the GS1 Digital Link URI to use alphabetic mnemonic short names as defined in the GS1 Digital Link standard, e.g. /gtin/. Set it False if you prefer the GS1 Digital Link URI to use all-numeric GS1 application identifiers, e.g. /01/.

Compression

To compress a full-length GS1 digital link, import compress_gs1_digital_link:

>>> from gs1 import compress_gs1_digital_link

A code snippet of GS1 digital link compression:

>>> full_uri = "https://id.gs1.org/gtin/9421902960055/lot/2010005828/ser/xyz1234"
>>> compressed_link = compress_gs1_digital_link(digital_link_uri=full_uri, use_optimizations=False, compress_other_key_value_pairs=False)
>>> print("Compressed Link: " + compressed_link)
    Compressed Link: https://id.gs1.org/AREjalurbiAUO-cgohCz45Z67b8A

There are four parameters in the function:

  • Pass the full length URI in the digital_link_uri parameter.

  • Pass the URI prefix in the uri_stem parameter. Normally you might want to be the same as the full-length URI's prefix.

  • Set use_optimizations=True if you would like to use optimized encoding of GS1 application identifiers and save more characters in the compressed string. By default, it's set to be False.

  • Set compress_other_key_value_pairs=True if you would like to compress non-GS1 key-value pairs in the full URI. By default, it's set to be False.

Contributors

Sponsors

  • Trust Codes Limited : Using anti-counterfeit solutions and supply-chain traceability, Trust Codes® data-driven software connects brands to consumers with item level serialisation and world leading algorithms.

Disclaimer

Legal Notice

In addition to the terms of the licence, this source code is provided by Trust Codes Limited, a New Zealand company, on an as-is basis, with no warranty expressed or implied. Neither Trust Codes Limited nor the contributors accept any liability for its use nor for any damages caused through its use. Trust Codes® is a registered trademark of Trust Codes Limited in New Zealand.

All Rights Reserved.

© Trust Codes Limited 2021.

License

Apache-2.0 License

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

gs1-compression-0.1.3.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

gs1_compression-0.1.3-py2.py3-none-any.whl (50.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gs1-compression-0.1.3.tar.gz.

File metadata

  • Download URL: gs1-compression-0.1.3.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for gs1-compression-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ce17af64b9e2beb619b60948467b3949094d789761c01b5e39044a384b4d8dfd
MD5 306e00e02c456e97cb2994a92c18ea84
BLAKE2b-256 903d55dae20da661f8a600f9bc994af564f61eb26e0f4f252f143ff8c70b72a6

See more details on using hashes here.

File details

Details for the file gs1_compression-0.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: gs1_compression-0.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 50.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for gs1_compression-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 502cc87017774bd64a52f49bcee24202a4bb3cc0cd78b0851851956f474c1d5e
MD5 8a5d50c88f96fcf42392b18bc6076cf0
BLAKE2b-256 3c4600a7c650c0aa813684972bf74c79f776a6db4edc542932ef10beca132097

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