Skip to main content

Python utility to encode/decode GS1 EPCs

Project description

Python EPC toolkit

This package provides utilities for building, encoding, decoding and translating EPCs.

Installation

pip install pyepc

Usage

Encoding EPC from company prefix and item reference

from pyepc import SGTIN

# Build an sgtin object from company prefix, item ref and serial number
company_prefix = '0614141'
item_ref = '812345'
serial = '12345'
sgtin = SGTIN(company_prefix, item_ref, serial)

# Get pure identity URI
# urn:epc:id:sgtin:0614141.812345.12345
sgtin.pure_identity_uri

# Get the tag URI
sgtin.get_tag_uri()

# Output will be
# 'urn:epc:tag:sgtin-96:1.0614141.812345.12345'
# The sgtin-96 scheme was automatically selected as the most
# efficient binary encoding scheme for a numeric serial
# number.


# To explicitly use another encoding scheme like 'sgtin-198',
# specify the encoding scheme
sgtin.get_tag_uri(SGTIN.BinarySchemes.SGTIN_198)

# output will be
# 'urn:epc:tag:sgtin-198:1.0614141.812345.12345'

# You can also change the filter value. In this case
# 1 (for POS item) was used as the default
sgtin.get_tag_uri(
    SGTIN.BinarySchemes.SGTIN_198,
    SGTIN.FilterValues.UNIT_LOAD,
)

# output will be
# 'urn:epc:tag:sgtin-198:6.0614141.812345.12345'
# The filter value is now 6

# If you want to encode the EPC into the EPC bank of an RFID
# tag, you will need the hex encoded value of the tag uri.
sgtin.encode()

# output will be
# '3034257BF7194E4000003039'

# Similar to the `get_tag_uri` methods, you can enforce which
# scheme should be used and the filter value
sgtin.encode(
    SGTIN.BinarySchemes.SGTIN_198,
    SGTIN.FilterValues.UNIT_LOAD,
)

# output will be
# '36D4257BF7194E58B266D1A800000000000000000000000000

Decoding EPC from Hex value in an EPC

If you want to convert the EPC Hex back into an EPC object, you can use the decode method.

If you don't know the type of the code, then use the decode method

from pyepc import decode
sgtin = decode('3034257BF7194E4000003039')

sgtin.company_prefix
# '0614141'

sgtin.item_ref
# '812345'

sgtin.serial_number
# '12345'

Additional Resources

Tag translation between UPC and EPC

History

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

pyepc-0.0.1.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file pyepc-0.0.1.tar.gz.

File metadata

  • Download URL: pyepc-0.0.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

File hashes

Hashes for pyepc-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fa9bc84cec1111e6c3d83828211460d18792b1dac7f6e8c949862065c2241441
MD5 684431515e48d3bf0de629e4d136ece1
BLAKE2b-256 ba8865e11ef2a990a3d6cf47b742721d778e28e9e8e2eb2c7fa98f9226b72c45

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page