{"id":22862738,"url":"https://github.com/nedap/retail-epcpy","last_synced_at":"2025-06-18T06:35:19.386Z","repository":{"id":42686372,"uuid":"450452510","full_name":"nedap/retail-epcpy","owner":"nedap","description":"A Python module for creation, validation, and transformation of EPC representations as defined in GS1's EPC Tag Data Standard.","archived":false,"fork":false,"pushed_at":"2025-02-04T09:41:59.000Z","size":315,"stargazers_count":11,"open_issues_count":4,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-30T21:52:46.866Z","etag":null,"topics":["epc","gs1","gtin","nedap","python","sgtin"],"latest_commit_sha":null,"homepage":"https://github.com/nedap/retail-epcpy","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nedap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-21T10:43:49.000Z","updated_at":"2025-02-04T09:38:44.000Z","dependencies_parsed_at":"2023-01-22T15:00:15.068Z","dependency_job_id":null,"html_url":"https://github.com/nedap/retail-epcpy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nedap%2Fretail-epcpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nedap%2Fretail-epcpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nedap%2Fretail-epcpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nedap%2Fretail-epcpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nedap","download_url":"https://codeload.github.com/nedap/retail-epcpy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251789310,"owners_count":21644081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["epc","gs1","gtin","nedap","python","sgtin"],"created_at":"2024-12-13T10:14:40.875Z","updated_at":"2025-04-30T21:52:54.989Z","avatar_url":"https://github.com/nedap.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EPCPY\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPI version](https://badge.fury.io/py/epcpy.svg)](https://badge.fury.io/py/epcpy)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/epcpy.svg)](https://pypi.org/project/epcpy/)\n\n\nA 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).\n\n**Table of contents**\n- [EPCPY](#epcpy)\n  - [Requirements](#requirements)\n  - [Installation](#installation)\n  - [Scheme types](#scheme-types)\n  - [Available schemes](#available-schemes)\n  - [Generic parsers](#generic-parsers)\n  - [Example usage](#example-usage)\n    - [SGTIN](#sgtin)\n      - [Pure identity](#pure-identity)\n      - [GS1Keyed](#gs1keyed)\n      - [Tag encoded](#tag-encoded)\n    - [Generic parsing](#generic-parsing)\n  - [Exceptions](#exceptions)\n  - [Development](#development)\n    - [Testing](#testing)\n    - [Coverage](#coverage)\n    - [Notebook](#notebook)\n\n## Requirements\n- Python \u003e= 3.8\n\n## Installation\n```\npip install epcpy\n```\n## Scheme types\nEvery 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:\n\n**EPCScheme**\n- *constructor*\n- `from_epc_uri`\n\n**GS1Element / GS1Keyed**\n- `from_gs1_element_string`\n- `gs1_element_string`\n- `gs1_key` (if `GS1Keyed`)\n\n**TagEncodable**\n- `from_binary`\n- `from_hex`\n- `from_base64`\n- `from_tag_uri`\n- `binary`\n- `hex`\n- `base64`\n- `tag_uri`\n\nAn example highlighting the different options for the `SGTIN` scheme can be found [later in this document](#example-usage) .\n\n## Available schemes\n| **Scheme** |  **GS1 element**   |   **GS1 keyed**    | **Tag encodable**  |\n| ---------- | :----------------: | :----------------: | :----------------: |\n| ADI        |                    |                    | :heavy_check_mark: |\n| BIC        |                    |                    |                    |\n| CPI        | :heavy_check_mark: |                    | :heavy_check_mark: |\n| GDTI       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| GIAI       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| GID        |                    |                    | :heavy_check_mark: |\n| GINC       | :heavy_check_mark: | :heavy_check_mark: |                    |\n| GRAI       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| GSIN       | :heavy_check_mark: | :heavy_check_mark: |                    |\n| GSRN       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| GSRNP      | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| IMOVN      |                    |                    |                    |\n| ITIP       | :heavy_check_mark: |                    | :heavy_check_mark: |\n| LGTIN      | :heavy_check_mark: | :heavy_check_mark: |                    |\n| PGLN       | :heavy_check_mark: | :heavy_check_mark: |                    |\n| SGCN       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| SGLN       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| SGTIN      | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| SSCC       | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |\n| UPUI       | :heavy_check_mark: |                    |                    |\n| USDOD      |                    |                    | :heavy_check_mark: |\n\n## Generic parsers\nThe following generic parser functions are available\n- `base64_to_tag_encodable`\n- `binary_to_tag_encodable`\n- `hex_to_tag_encodable`\n- `tag_uri_to_tag_encodable`\n- `epc_pure_identity_to_gs1_element`\n- `epc_pure_identity_to_gs1_element_string`\n- `epc_pure_identity_to_gs1_key`\n- `epc_pure_identity_to_gs1_keyed`\n- `epc_pure_identity_to_scheme`\n- `epc_pure_identity_to_tag_encodable`\n- `get_gs1_key`\n\n## Example usage\n### SGTIN\n#### Pure identity\nGiven an `SGTIN` in EPC URI representation, `urn:epc:id:sgtin:00000950.01093.Serial`, an epcpy `SGTIN` object can be created as follows\n```python\nfrom epcpy.epc_schemes import SGTIN\n\nsgtin = SGTIN.from_epc_uri(\"urn:epc:id:sgtin:00000950.01093.Serial\")\n\n# Alternatively\nsgtin = SGTIN(\"urn:epc:id:sgtin:00000950.01093.Serial\")\n\nsgtin.epc_uri\n# urn:epc:id:sgtin:00000950.01093.Serial\n```\n\n\n#### GS1Keyed\nSince `SGTIN` is `GS1Keyed`, several elements can be derived using\n```python\nsgtin.gs1_element_string()\n# (01)00000095010939(21)Serial\n\nsgtin.gs1_key()\n# 00000095010939\n\nfrom epcpy.epc_schemes.sgtin import GTIN_TYPE\nsgtin.gs1_key(gtin_type=GTIN_TYPE.GTIN8) # GTIN14 is the default\n# 95010939\n```\nAdditionaly, an `SGTIN` can also be constructed from a GS1 element string if a company prefix length is provided\n```python\nSGTIN.from_gs1_element_string(\"(01)00000095010939(21)Serial\", company_prefix_length=8)\n```\n\n#### Tag encoded\nWith 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\n```python\nsgtin.tag_uri(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)\n# urn:epc:tag:sgtin-198:1.00000950.01093.Serial\n\nsgtin.hex(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)\n# 36300001DB011169E5E5A70EC000000000000000000000000000\n\n\nsgtin.base64(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)\n# NjAAAdsBEWnl5acOwAAAAAAAAAAAAAAAAAA\n\nsgtin.binary(binary_coding_scheme=SGTIN.BinaryCodingScheme.SGTIN_198, filter_value=SGTINFilterValue.POS_ITEM)\n# 001101100011000000000000000000...\n```\n\nSimilary, given a `SGTIN` tag in hex `36300001DB011169E5E5A70EC000000000000000000000000000`, an `SGTIN` can be constructed\n```python\nSGTIN.from_hex(\"36300001DB011169E5E5A70EC000000000000000000000000000\")\n\n# from_binary, from_base64 and from_tag_uri are available as well\n```\n\n### Generic parsing\nWhen dealing with arbitrary tags epcpy also provides generic parsing options.\n```python\nfrom epcpy import hex_to_epc\n\nhex_to_epc(\"36300001DB011169E5E5A70EC000000000000000000000000000\")\n```\nThe following parsers are available:\n- `base64_to_tag_encodable`\n- `binary_to_tag_encodable`\n- `epc_pure_identity_to_gs1_element`\n- `epc_pure_identity_to_gs1_element_string`\n- `epc_pure_identity_to_gs1_key`\n- `epc_pure_identity_to_gs1_keyed`\n- `epc_pure_identity_to_scheme`\n- `epc_pure_identity_to_tag_encodable`\n- `hex_to_tag_encodable`\n- `tag_uri_to_tag_encodable`\n\nAlternatively, the `get_gs1_key` method can be used to distill the GS1 key from a given string.\n```python\nfrom epcpy import get_gs1_key\n\nget_gs1_key(\"36300001DB011169E5E5A70EC000000000000000000000000000\")\n# 00000095010939\n\nget_gs1_key(\"urn:epc:tag:sgtin-198:1.00000950.01093.Serial\")\n# 00000095010939\n\nget_gs1_key(\"urn:epc:idpat:sgtin:00000950.01093.*\")\n# 00000095010939\n```\n`get_gs1_key` is able to parse the following sources:\n- EPC pure identity URIs\n- EPC tag URIs\n- GS1 element strings (company_prefix_length should be provided)\n- EPC id pattern URIs\n- Binary strings\n- Hexadecimal strings\n\n## Exceptions\nEspecially when applying generic parsing, exceptions may be thrown when passing invalid data. One can import the `ConvertException` class to specially deal with exceptions thrown by this library:\n```python\nfrom epcpy import ConvertException, get_gs1_key\n\ntry:\n  get_gs1_key(\"urn:epc:idpat:sgtin:00000950.*.*\")\nexcept ConvertException as e:\n  print(e)\n  # Could not create valid scheme from given id pat\n```\n\n## Development\n\nThis project uses [Poetry](https://python-poetry.org/) for project management.\nPoetry must be installed and available in `$PATH`.\nAfter cloning run `poetry install` to install (development) dependencies.\n\n### Testing\nThis module uses the Python unittest library. Run `poetry run test` for running the tests.\n\n### Coverage\nRun `poetry run coverage run -m unittest discover` to execute all tests with coverage. The resulting coverage can be reported using `poetry run coverage report --omit=\"*/test*\"` for a textual view the terminal and with `poetry run coverage html --omit=\"*/test*\"` for a webpage.\n\n### Notebook\nThere 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_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnedap%2Fretail-epcpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnedap%2Fretail-epcpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnedap%2Fretail-epcpy/lists"}