Skip to main content

A Python module for creation, validation, and transformation of EPC representations as defined in GS1's EPC Tag Data Standard (https://www.gs1.org/standards/rfid/tds).

Project description

EPCPY

Code style: black License: MIT

A Python module for creation, validation, and transformation of EPC representations as defined in GS1's EPC Tag Data Standard (https://www.gs1.org/standards/rfid/tds).

Table of contents

Requirements

  • Python >= 3.7

Scheme types

Every scheme is an instance of the EPCScheme class, which allows scheme initialization using a constructor which accepts a EPC pure identity such as urn:epc:id:sgtin:00000950.01093.Serial or using the class method from_epc_uri. Aside from this base class, schemes can also be instances of the GS1Keyed, GS1Element and/or TagEncodable classes. These provide the following methods:

EPCScheme

  • constructor
  • from_epc_uri

GS1Element / GS1Keyed

  • from_gs1_element_string
  • gs1_element_string
  • gs1_key (if GS1Keyed)

TagEncodable

  • from_binary
  • from_hex
  • from_base64
  • from_tag_uri
  • binary
  • hex
  • base64
  • tag_uri

An example highlighting the different options for the SGTIN scheme can be found later in this document .

Available schemes

Scheme GS1 element GS1 keyed Tag encodable
ADI :heavy_check_mark:
BIC
CPI :heavy_check_mark: :heavy_check_mark:
GDTI :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
GIAI :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
GID :heavy_check_mark:
GINC :heavy_check_mark: :heavy_check_mark:
GRAI :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
GSIN :heavy_check_mark: :heavy_check_mark:
GSRN :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
GSRNP :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
IMOVN
ITIP :heavy_check_mark: :heavy_check_mark:
PGLN :heavy_check_mark: :heavy_check_mark:
SGCN :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
SGLN :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
SGTIN :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
SSCC :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
UPUI :heavy_check_mark:
USDOD :heavy_check_mark:

Generic parsers

The following generic parser functions are available

  • base64_to_epc
  • binary_to_epc
  • hex_to_epc
  • tag_uri_to_epc
  • epc_pure_identity_to_gs1_keyed
  • epc_pure_identity_to_scheme
  • epc_pure_identity_to_tag_encodable

Example usage

SGTIN

Pure identity

Given an SGTIN in EPC URI representation, urn:epc:id:sgtin:00000950.01093.Serial, an epcpy SGTIN object can be created as follows

from epcpy.epc_schemes.sgtin import SGTIN

sgtin = SGTIN.from_epc_uri("urn:epc:id:sgtin:00000950.01093.Serial")

# Alternatively
sgtin = SGTIN("urn:epc:id:sgtin:00000950.01093.Serial")

sgtin.epc_uri
# urn:epc:id:sgtin:00000950.01093.Serial

GS1Keyed

Since SGTIN is GS1Keyed, several elements can be derived using

sgtin.gs1_element_string()
# (01)00000095010939(21)Serial

sgtin.gs1_key()
# 00000095010939

from epcpy.epc_schemes.sgtin import GTIN_TYPE
sgtin.gs1_key(gtin_type=GTIN_TYPE.GTIN8) # GTIN14 is the default
# 95010939

Additionaly, an SGTIN can also be constructed from a GS1 element string if a company prefix length is provided

SGTIN.from_gs1_element_string("(01)00000095010939(21)Serial", company_prefix_length=8)

Tag encoded

With some additional information an SGTIN can be encoded into a tag, subsequently the tag can for example be represented as tag uri, hexadecimal, base64 or binary string

sgtin.tag_uri(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)
# urn:epc:tag:sgtin-198:1.00000950.01093.Serial

sgtin.hex(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)
# 36300001DB011169E5E5A70EC000000000000000000000000000


sgtin.base64(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)
# NjAAAdsBEWnl5acOwAAAAAAAAAAAAAAAAAA

sgtin.binary(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)
# 001101100011000000000000000000...

Similary, given a SGTIN tag in hex 36300001DB011169E5E5A70EC000000000000000000000000000, an SGTIN can be constructed

SGTIN.from_hex("36300001DB011169E5E5A70EC000000000000000000000000000")

# from_binary, from_base64 and from_tag_uri are available as well

Generic parsing

When dealing with arbitrary tags epcpy also provides generic parsing options

from epcpy import hex_to_epc

hex_to_epc("36300001DB011169E5E5A70EC000000000000000000000000000")

Development

This project uses Poetry for project management. Poetry must be installed and available in $PATH. After cloning run poetry install to install (development) dependencies.

Testing

This module uses the Python unittest library. Run poetry run tests for running the tests.

Coverage

Run poetry run coverage run -m unittest discover to execute all tests with coverage. The resulting coverage can be reported using poetry run coverage report for a textual view the terminal and with poetry run coverage html for a webpage.

Notebook

There is a sample notebook included in this repository, which can be used to quickly get a hands-on experience with the repository. The notebook might not be completely up-to-date and requires the jupyter package to run, which can be installed using pip install jupyter.

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

epcpy-0.1.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

epcpy-0.1.0-py3-none-any.whl (50.2 kB view details)

Uploaded Python 3

File details

Details for the file epcpy-0.1.0.tar.gz.

File metadata

  • Download URL: epcpy-0.1.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.5 Windows/10

File hashes

Hashes for epcpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 81e2eec4822f910f6dfdea5970f6a231acd773a734337d38a5d848ce633400e8
MD5 bb5b22e515ae0aafc079f376ac9488d0
BLAKE2b-256 6019fe83c64a4db93ee04da124fe90c518188a44d4661b32acaa61fd8196917c

See more details on using hashes here.

File details

Details for the file epcpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: epcpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.5 Windows/10

File hashes

Hashes for epcpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5332b5a4ad77cb130b1969623d737184c36183d8fd86b7789d06780a4f7043b1
MD5 b6f58e61ba48ec57750fe8eff5478442
BLAKE2b-256 cf00404099d93f7f3f40a9110efdaa6e1eea962f19d537533721af0b17fdaeab

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