pyepc


Namepyepc JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/fulfilio/pyepc
SummaryPython utility to encode/decode GS1 EPCs
upload_time2023-09-06 13:26:24
maintainer
docs_urlNone
authorFulfil.IO Inc.
requires_python>=3.9
licenseMIT license
keywords pyepc epc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python EPC toolkit

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

## Installation

```
pip install pyepc
```

## Usage

### SGTIN

```python
# Encoding
# --------

# Always import from the root of the package
>>> from pyepc import SGTIN

# You can build an epc object in many ways. If you are starting
# from an application that manages items and GS1 company prefixes
# then building an SGTIN from the components is the likely path
>>> company_prefix = '0614141'
>>> indicator = '8'
>>> item_ref = '12345'
>>> serial = '12345'
>>> sgtin = SGTIN(company_prefix, indicator, item_ref, serial)

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

# Get GS1 element string
>>> sgtin.gs1_element_string
'(01)80614141123458(21)12345'

# Get a GTIN from the EPC
>>> sgtin.gtin
'80614141123458'

# You can also build a SGTIN object from the GTIN
# if a GTIN is what you have as a starting point
>>> sgtin = SGTIN.from_sgtin('80614141123458', serial_number='123456')
'<urn:epc:id:sgtin:0614141.812345.123456>'

# Get the tag URI
>>> sgtin.get_tag_uri()
'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)
'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,
... )
'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()
'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,
... )
'36D4257BF7194E58B266D1A800000000000000000000000000'

# Decoding
# --------
>>> SGTIN.decode('36D4257BF7194E58B266D1A800000000000000000000000000')
'<urn:epc:id:sgtin:0614141.812345.12345>'

# EPC from GTIN
# -------------
# If all what you have is a GTIN, then you can build an EPC from it

>>> SGTIN.from_sgtin('80614141123458', '6789AB')
'<urn:epc:id:sgtin:0614141.812345.6789AB>'

# However, this has to lookup the company prefix length from the GS1
# prefix list and could be expensive the first time. So if you already
# know your company prefix length, then pass that along

>>> company_prefix_len = len('0614141')
>>> SGTIN.from_sgtin('80614141123458', '6789AB', company_prefix_len)
'<urn:epc:id:sgtin:0614141.812345.6789AB>'
```

### SSCC

```python
# Encoding
# --------

# Always import from the root of the package
>>> from pyepc import SSCC

# Build an SSCC object from the company prefix, extension digit
# and a serial reference for the logistics unit
>>> company_prefix = '0614141'
>>> extension_digit = '1'
>>> serial_ref = '234567890'
>>> sscc = SSCC(company_prefix, extension_digit, serial_ref)

# Get pure identity URI
>>> sscc.pure_identity_uri
'urn:epc:id:sscc:0614141.1234567890'

# Get GS1 element string
>>> sscc.gs1_element_string
'(00)106141412345678908'

# Get the tag URI
>>> sscc.get_tag_uri()
'urn:epc:tag:sscc-96:0.0614141.1234567890'

# 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.
>>> sscc.encode()
'3114257BF4499602D2000000'

# Decoding
# --------

>>> sscc.decode('3114257BF4499602D2000000')
'<urn:epc:id:sscc:0614141.1234567890>'

# EPC from SSCC Code
# ------------------

>>> SSCC.from_sscc('106141412345678908')
'<urn:epc:id:sscc:0614141.1234567890>'

However, this has to lookup the company prefix length from the GS1
prefix list and could be expensive the first time. So if you already
know your company prefix length, then pass that along

>>> company_prefix_len = len('0614141')
>>> SSCC.from_sscc('106141412345678908', company_prefix_len)
'<urn:epc:id:sscc:0614141.1234567890>'
```

### 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

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

sgtin.company_prefix
# '0614141'

sgtin.item_ref
# '12345'

sgtin.serial_number
# '12345'
```

## Additional Resources

* [EPC Tag Data Standard](https://www.gs1.org/sites/default/files/docs/epc/GS1_EPC_TDS_i1_13.pdf)
* [Encoder/Decoder on GS1 site](https://www.gs1.org/services/epc-encoderdecoder)

## Tag translation between UPC and EPC

* [GS1 EPCglobal Tag Data Translation (TDT) 1.6](https://www.gs1.org/sites/default/files/docs/epc/tdt_1_6_RatifiedStd-20111012-i2.pdf)
* [TDT Overview](https://www.gs1.org/sites/default/files/docs/epc/tdt_1_6_Intro.pdf)


History

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fulfilio/pyepc",
    "name": "pyepc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "pyepc epc",
    "author": "Fulfil.IO Inc.",
    "author_email": "help@fulfil.io",
    "download_url": "https://files.pythonhosted.org/packages/ed/35/5fc629d2ce4aecf365e29855ff68d4ce5ce9e10c36dafea0457ead5ed058/pyepc-0.5.0.tar.gz",
    "platform": null,
    "description": "# Python EPC toolkit\n\nThis package provides utilities for building, encoding, decoding\nand translating EPCs.\n\n## Installation\n\n```\npip install pyepc\n```\n\n## Usage\n\n### SGTIN\n\n```python\n# Encoding\n# --------\n\n# Always import from the root of the package\n>>> from pyepc import SGTIN\n\n# You can build an epc object in many ways. If you are starting\n# from an application that manages items and GS1 company prefixes\n# then building an SGTIN from the components is the likely path\n>>> company_prefix = '0614141'\n>>> indicator = '8'\n>>> item_ref = '12345'\n>>> serial = '12345'\n>>> sgtin = SGTIN(company_prefix, indicator, item_ref, serial)\n\n# Get pure identity URI\n>>> sgtin.pure_identity_uri\n'urn:epc:id:sgtin:0614141.812345.12345'\n\n# Get GS1 element string\n>>> sgtin.gs1_element_string\n'(01)80614141123458(21)12345'\n\n# Get a GTIN from the EPC\n>>> sgtin.gtin\n'80614141123458'\n\n# You can also build a SGTIN object from the GTIN\n# if a GTIN is what you have as a starting point\n>>> sgtin = SGTIN.from_sgtin('80614141123458', serial_number='123456')\n'<urn:epc:id:sgtin:0614141.812345.123456>'\n\n# Get the tag URI\n>>> sgtin.get_tag_uri()\n'urn:epc:tag:sgtin-96:1.0614141.812345.12345'\n\n# The sgtin-96 scheme was automatically selected as the most\n# efficient binary encoding scheme for a numeric serial\n# number.\n\n# To explicitly use another encoding scheme like 'sgtin-198',\n# specify the encoding scheme\n>>> sgtin.get_tag_uri(SGTIN.BinarySchemes.SGTIN_198)\n'urn:epc:tag:sgtin-198:1.0614141.812345.12345'\n\n# You can also change the filter value. In this case\n# 1 (for POS item) was used as the default\n>>> sgtin.get_tag_uri(\n...    SGTIN.BinarySchemes.SGTIN_198,\n...    SGTIN.FilterValues.UNIT_LOAD,\n... )\n'urn:epc:tag:sgtin-198:6.0614141.812345.12345'\n# The filter value is now 6\n\n# If you want to encode the EPC into the EPC bank of an RFID\n# tag, you will need the hex encoded value of the tag uri.\n>>> sgtin.encode()\n'3034257BF7194E4000003039'\n\n# Similar to the `get_tag_uri` methods, you can enforce which\n# scheme should be used and the filter value\n>>> sgtin.encode(\n...     SGTIN.BinarySchemes.SGTIN_198,\n...     SGTIN.FilterValues.UNIT_LOAD,\n... )\n'36D4257BF7194E58B266D1A800000000000000000000000000'\n\n# Decoding\n# --------\n>>> SGTIN.decode('36D4257BF7194E58B266D1A800000000000000000000000000')\n'<urn:epc:id:sgtin:0614141.812345.12345>'\n\n# EPC from GTIN\n# -------------\n# If all what you have is a GTIN, then you can build an EPC from it\n\n>>> SGTIN.from_sgtin('80614141123458', '6789AB')\n'<urn:epc:id:sgtin:0614141.812345.6789AB>'\n\n# However, this has to lookup the company prefix length from the GS1\n# prefix list and could be expensive the first time. So if you already\n# know your company prefix length, then pass that along\n\n>>> company_prefix_len = len('0614141')\n>>> SGTIN.from_sgtin('80614141123458', '6789AB', company_prefix_len)\n'<urn:epc:id:sgtin:0614141.812345.6789AB>'\n```\n\n### SSCC\n\n```python\n# Encoding\n# --------\n\n# Always import from the root of the package\n>>> from pyepc import SSCC\n\n# Build an SSCC object from the company prefix, extension digit\n# and a serial reference for the logistics unit\n>>> company_prefix = '0614141'\n>>> extension_digit = '1'\n>>> serial_ref = '234567890'\n>>> sscc = SSCC(company_prefix, extension_digit, serial_ref)\n\n# Get pure identity URI\n>>> sscc.pure_identity_uri\n'urn:epc:id:sscc:0614141.1234567890'\n\n# Get GS1 element string\n>>> sscc.gs1_element_string\n'(00)106141412345678908'\n\n# Get the tag URI\n>>> sscc.get_tag_uri()\n'urn:epc:tag:sscc-96:0.0614141.1234567890'\n\n# If you want to encode the EPC into the EPC bank of an RFID\n# tag, you will need the hex encoded value of the tag uri.\n>>> sscc.encode()\n'3114257BF4499602D2000000'\n\n# Decoding\n# --------\n\n>>> sscc.decode('3114257BF4499602D2000000')\n'<urn:epc:id:sscc:0614141.1234567890>'\n\n# EPC from SSCC Code\n# ------------------\n\n>>> SSCC.from_sscc('106141412345678908')\n'<urn:epc:id:sscc:0614141.1234567890>'\n\nHowever, this has to lookup the company prefix length from the GS1\nprefix list and could be expensive the first time. So if you already\nknow your company prefix length, then pass that along\n\n>>> company_prefix_len = len('0614141')\n>>> SSCC.from_sscc('106141412345678908', company_prefix_len)\n'<urn:epc:id:sscc:0614141.1234567890>'\n```\n\n### Decoding EPC from Hex value in an EPC\n\nIf you want to convert the EPC Hex back into an EPC object, you\ncan use the decode method.\n\nIf you don't know the type of the code, then use the decode method\n\n```python\nfrom pyepc import decode\nsgtin = decode('3034257BF7194E4000003039')\n\nsgtin.company_prefix\n# '0614141'\n\nsgtin.item_ref\n# '12345'\n\nsgtin.serial_number\n# '12345'\n```\n\n## Additional Resources\n\n* [EPC Tag Data Standard](https://www.gs1.org/sites/default/files/docs/epc/GS1_EPC_TDS_i1_13.pdf)\n* [Encoder/Decoder on GS1 site](https://www.gs1.org/services/epc-encoderdecoder)\n\n## Tag translation between UPC and EPC\n\n* [GS1 EPCglobal Tag Data Translation (TDT) 1.6](https://www.gs1.org/sites/default/files/docs/epc/tdt_1_6_RatifiedStd-20111012-i2.pdf)\n* [TDT Overview](https://www.gs1.org/sites/default/files/docs/epc/tdt_1_6_Intro.pdf)\n\n\nHistory\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "Python utility to encode/decode GS1 EPCs",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/fulfilio/pyepc"
    },
    "split_keywords": [
        "pyepc",
        "epc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efea973b24cc78ada972dbdb621a4b0551d86693f7573657273558ffbd5a322d",
                "md5": "e762cacff9b735f3b3a4e1d2a94655e6",
                "sha256": "b2fb9f463fcd06a3087412cb0b425e749c71b774fc613d9a35e2511c7ff2e323"
            },
            "downloads": -1,
            "filename": "pyepc-0.5.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e762cacff9b735f3b3a4e1d2a94655e6",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.9",
            "size": 15980,
            "upload_time": "2023-09-06T13:26:22",
            "upload_time_iso_8601": "2023-09-06T13:26:22.502517Z",
            "url": "https://files.pythonhosted.org/packages/ef/ea/973b24cc78ada972dbdb621a4b0551d86693f7573657273558ffbd5a322d/pyepc-0.5.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed355fc629d2ce4aecf365e29855ff68d4ce5ce9e10c36dafea0457ead5ed058",
                "md5": "12284e133ea84623672d667956c2af83",
                "sha256": "330b8341db2f96f7bcc9df1e1231d9cce4f02e1437fe19053a5fec524e2a1df2"
            },
            "downloads": -1,
            "filename": "pyepc-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "12284e133ea84623672d667956c2af83",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 13731,
            "upload_time": "2023-09-06T13:26:24",
            "upload_time_iso_8601": "2023-09-06T13:26:24.065861Z",
            "url": "https://files.pythonhosted.org/packages/ed/35/5fc629d2ce4aecf365e29855ff68d4ce5ce9e10c36dafea0457ead5ed058/pyepc-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-06 13:26:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fulfilio",
    "github_project": "pyepc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyepc"
}
        
Elapsed time: 0.12937s