- Notifications
You must be signed in to change notification settings - Fork1
A Python module for creation, validation, and transformation of EPC representations as defined in GS1's EPC Tag Data Standard.
License
nedap/retail-epcpy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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
- Python >= 3.8
pip install epcpy
Every scheme is an instance of theEPCScheme
class, which allows scheme initialization using a constructor which accepts a EPC pure identity such asurn:epc:id:sgtin:00000950.01093.Serial
or using the class methodfrom_epc_uri
. Aside from this base class, schemes can also be instances of theGS1Keyed
,GS1Element
and/orTagEncodable
classes. These provide the following methods:
EPCScheme
- constructor
from_epc_uri
GS1Element / GS1Keyed
from_gs1_element_string
gs1_element_string
gs1_key
(ifGS1Keyed
)
TagEncodable
from_binary
from_hex
from_base64
from_tag_uri
binary
hex
base64
tag_uri
An example highlighting the different options for theSGTIN
scheme can be foundlater in this document .
Scheme | GS1 element | GS1 keyed | Tag encodable |
---|---|---|---|
ADI | ✔️ | ||
BIC | |||
CPI | ✔️ | ✔️ | |
GDTI | ✔️ | ✔️ | ✔️ |
GIAI | ✔️ | ✔️ | ✔️ |
GID | ✔️ | ||
GINC | ✔️ | ✔️ | |
GRAI | ✔️ | ✔️ | ✔️ |
GSIN | ✔️ | ✔️ | |
GSRN | ✔️ | ✔️ | ✔️ |
GSRNP | ✔️ | ✔️ | ✔️ |
IMOVN | |||
ITIP | ✔️ | ✔️ | |
LGTIN | ✔️ | ✔️ | |
PGLN | ✔️ | ✔️ | |
SGCN | ✔️ | ✔️ | ✔️ |
SGLN | ✔️ | ✔️ | ✔️ |
SGTIN | ✔️ | ✔️ | ✔️ |
SSCC | ✔️ | ✔️ | ✔️ |
UPUI | ✔️ | ||
USDOD | ✔️ |
The following generic parser functions are available
base64_to_tag_encodable
binary_to_tag_encodable
hex_to_tag_encodable
tag_uri_to_tag_encodable
epc_pure_identity_to_gs1_element
epc_pure_identity_to_gs1_element_string
epc_pure_identity_to_gs1_key
epc_pure_identity_to_gs1_keyed
epc_pure_identity_to_scheme
epc_pure_identity_to_tag_encodable
get_gs1_key
Given anSGTIN
in EPC URI representation,urn:epc:id:sgtin:00000950.01093.Serial
, an epcpySGTIN
object can be created as follows
fromepcpy.epc_schemesimportSGTINsgtin=SGTIN.from_epc_uri("urn:epc:id:sgtin:00000950.01093.Serial")# Alternativelysgtin=SGTIN("urn:epc:id:sgtin:00000950.01093.Serial")sgtin.epc_uri# urn:epc:id:sgtin:00000950.01093.Serial
SinceSGTIN
isGS1Keyed
, several elements can be derived using
sgtin.gs1_element_string()# (01)00000095010939(21)Serialsgtin.gs1_key()# 00000095010939fromepcpy.epc_schemes.sgtinimportGTIN_TYPEsgtin.gs1_key(gtin_type=GTIN_TYPE.GTIN8)# GTIN14 is the default# 95010939
Additionaly, anSGTIN
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)
With some additional information anSGTIN
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.Serialsgtin.hex(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198,filter_value=SGTINFilterValue.POS_ITEM)# 36300001DB011169E5E5A70EC000000000000000000000000000sgtin.base64(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198,filter_value=SGTINFilterValue.POS_ITEM)# NjAAAdsBEWnl5acOwAAAAAAAAAAAAAAAAAAsgtin.binary(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198,filter_value=SGTINFilterValue.POS_ITEM)# 001101100011000000000000000000...
Similary, given aSGTIN
tag in hex36300001DB011169E5E5A70EC000000000000000000000000000
, anSGTIN
can be constructed
SGTIN.from_hex("36300001DB011169E5E5A70EC000000000000000000000000000")# from_binary, from_base64 and from_tag_uri are available as well
When dealing with arbitrary tags epcpy also provides generic parsing options.
fromepcpyimporthex_to_epchex_to_epc("36300001DB011169E5E5A70EC000000000000000000000000000")
The following parsers are available:
base64_to_tag_encodable
binary_to_tag_encodable
epc_pure_identity_to_gs1_element
epc_pure_identity_to_gs1_element_string
epc_pure_identity_to_gs1_key
epc_pure_identity_to_gs1_keyed
epc_pure_identity_to_scheme
epc_pure_identity_to_tag_encodable
hex_to_tag_encodable
tag_uri_to_tag_encodable
Alternatively, theget_gs1_key
method can be used to distill the GS1 key from a given string.
fromepcpyimportget_gs1_keyget_gs1_key("36300001DB011169E5E5A70EC000000000000000000000000000")# 00000095010939get_gs1_key("urn:epc:tag:sgtin-198:1.00000950.01093.Serial")# 00000095010939get_gs1_key("urn:epc:idpat:sgtin:00000950.01093.*")# 00000095010939
get_gs1_key
is able to parse the following sources:
- EPC pure identity URIs
- EPC tag URIs
- GS1 element strings (company_prefix_length should be provided)
- EPC id pattern URIs
- Binary strings
- Hexadecimal strings
Especially when applying generic parsing, exceptions may be thrown when passing invalid data. One can import theConvertException
class to specially deal with exceptions thrown by this library:
fromepcpyimportConvertException,get_gs1_keytry:get_gs1_key("urn:epc:idpat:sgtin:00000950.*.*")exceptConvertExceptionase:print(e)# Could not create valid scheme from given id pat
This project usesPoetry for project management.Poetry must be installed and available in$PATH
.After cloning runpoetry install
to install (development) dependencies.
This module uses the Python unittest library. Runpoetry run test
for running the tests.
Runpoetry run coverage run -m unittest discover
to execute all tests with coverage. The resulting coverage can be reported usingpoetry run coverage report --omit="*/test*"
for a textual view the terminal and withpoetry run coverage html --omit="*/test*"
for a webpage.
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 thejupyter
package to run, which can be installed usingpip install jupyter
.
About
A Python module for creation, validation, and transformation of EPC representations as defined in GS1's EPC Tag Data Standard.