SGTIN¶
- class epc.schemes.SGTIN(*args, **kwargs)¶
The Serialised Global Trade Item Number EPC scheme is used to assign a unique identity to an instance of a trade item, such as a specific instance of a product or SKU.
General syntax: urn:epc:id:sgtin:CompanyPrefix.ItemRefAndIndicator.SerialNumber
Example: urn:epc:id:sgtin:0614141.112345.400
- filter(tag_filter)¶
The filter value is additional control information that may be included in the EPC memory bank of a Gen 2 tag. The intended use of the filter value is to allow an RFID reader to select or deselect the tags corresponding to certain physical objects, to make it easier to read the desired tags in an environment where there may be other tags present in the environment. For example, if the goal is to read the single tag on a pallet, and it is expected that there may be hundreds or thousands of item-level tags present, the performance of the capturing application may be improved by using the Gen 2 air interface to select the pallet tag and deselect the item-level tags.
Allowed values for SGTIN tags:
Value
Constant
Description
0
FILTER_ALL
All Others
1
FILTER_POS
Point of Sale Trade Item
2
FILTER_FULL_CASE
Full Case for Transport
3
FILTER_RESERVED_3
Reserved
4
FILTER_INNER_PACK
Inner Pack Trade Item
5
FILTER_RESERVED_5
Reserved
6
FILTER_UNIT_LOAD
Unit Load
7
FILTER_INNER_ITEM
Unit Inside Trade Item
- Parameters
tag_filter (int) – The filter value, defaults to
FILTER_ALL
.- Raises
AttributeError – Filter must be between 0 and 7.
- Returns
The SGTIN tag object.
- Return type
- company_prefix(company_prefix, company_prefix_length=None)¶
The GS1 Company Prefix, assigned by GS1 to a managing entity.
Length corresponds to the number of digits in the company prefix.
- Parameters
company_prefix (str, int) – GS1 company prefix.
company_prefix_length (int, optional) – Number of digits in the company prefix. Required when
company_prefix
is an int.
- Returns
The SGTIN tag object.
- Return type
- item_reference(item_reference)¶
The Item Reference is assigned by the managing entity to a particular object class.
The Item Reference as it appears in the EPC URI is derived from the GTIN by concatenating the Indicator Digit of the GTIN (or a zero pad character, if the EPC URI is derived from a GTIN-8, GTIN-12, or GTIN-13) and the Item Reference digits, and treating the result as a single numeric string.
- Parameters
item_reference (int, str) – The item reference.
- Raises
ValueError – item_reference must be an integer
- Returns
The SGTIN tag object.
- Return type
- serial_number(serial_number)¶
The Serial Number, assigned by the managing entity to an individual object. The serial number is not part of the GTIN, but is formally a part of the SGTIN.
- Parameters
serial_number (str, int) – The serial number.
- Raises
AttributeError – Serial number bit length incorrect.
AttributeError – Serial number length incorrect.
- Returns
The SGTIN tag object.
- Return type
- tag_size()¶
Set the size for the tag. Options are
SIZE_96
orSIZE_198
.- Parameters
tag_size (int) – Tag size in bits. Defaults to
SIZE_96
.- Raises
AttributeError – Invalid tag size specified.
- Returns
The SGTIN tag object.
- Return type
- property tag_uri¶
- Returns
The tag’s URI.
- Return type
str
- property pure_identity_uri¶
- Returns
The tag’s pure identity URI.
- Return type
str
- property barcode¶
- Returns
The barcode representation of the tag.
- Return type
str
- property barcode_humanized¶
- Returns
A human readable barcode representation of the tag.
- Return type
str
- property gtin¶
A Global Trade Item Number (GTIN) is the 14 digit GS1 Identification Key used to identify products. The key comprises a GS1 Company Prefix followed by an Item Reference Number and a Check Digit.
- Returns
The GTIN-14 representation of the tag.
- Return type
str
- property values¶
- Returns
Dictionary containing:
size
(int): the tag’s size in bitsfilter
(int)company_prefix
(str)item_reference
(int)serial_number
(int or str)
- decode_epc(hex_string)¶
Decode an encoded tag and populate this object’s values from it.
- Parameters
hex_string (str) – Tag data encoded as a hexadecimal string.
- Raises
ValueError – EPC scheme header does not match input.
ValueError – Filter does not match allowed values.
ValueError – Supplied
hex_string
bit length invalid.
- decode_barcode(barcode, company_prefix_length)¶
Decode a barcode and populate this object’s values from it.
- Parameters
hex_string (str) – Barcode
company_prefix_length (int) – Number of digits of the company prefix length
- Raises
ValueError – Expected barcode header does not match input
AttributeError – Invalid check digit
AttributeError – Invalid barcode length, or wrong company prefix
AttributeError – Invalid item_reference in barcode
- decode_gtin(gtin, company_prefix_length, serial_number=0)¶
Decode a GTIN (Supports GTIN-14, GTIN-13, GTIN-12 formats) to populate this object’s values from it. Check digit must be included.
- Parameters
gtin (str) – Global trade item number
company_prefix_length (int) – Number of digits of the company prefix length
serial_number (int, str, optional) – Serial number to set on the tag. Defaults to 0.
- Raises
ValueError – Invalid GTIN length
AttributeError – Invalid check digit
AttributeError – Invalid company_prefix_length specified
AttributeError – Invalid item_reference in gtin
- check_fields()¶
Checks to make sure all components of the tag are present, including
size
,filter
,company_prefix
,item_reference
andserial_number
.- Raises
AttributeError – If any components of the tag are missing.
Hint
To get the encoded tag data, use python’s built in conversion methods:
>>> tag = SGTIN().tag_size(SGTIN.SIZE_198)
>>> tag.company_prefix('000123').item_reference(18).serial_number('ABC')
# Hexadecimal
>>> hex(tag)
'0x3618001ec00004a0c28600000000000000000000000000000000'
# Binary
>>> bin(tag)
'0b11011000011000000000000001111011000000000000000000010010100000110000101000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
Constants¶
Filters
- SGTIN.FILTER_ALL¶
- SGTIN.FILTER_POS¶
- SGTIN.FILTER_FULL_CASE¶
- SGTIN.FILTER_RESERVED_3¶
- SGTIN.FILTER_INNER_PACK¶
- SGTIN.FILTER_RESERVED_5¶
- SGTIN.FILTER_UNIT_LOAD¶
- SGTIN.FILTER_INNER_ITEM¶
Sizes
- SGTIN.SIZE_96¶
96 bit tag size.
- SGTIN.SIZE_198¶
198 bit tag size.
Headers
- SGTIN.HEADER_BARCODE¶
GS1 specified GTIN barcode header:
01
.
- SGTIN.HEADER_BARCODE_SERIAL_NUMBER¶
GS1 specified GTIN serial barcode header:
21
.
- SGTIN.HEADER_96¶
GS1 specified hexadecimal header for 96 bit SGTIN tags:
0x30
.
- SGTIN.HEADER_198¶
GS1 specified hexadecimal header for 202 bit SGTIN tags:
0x36
.
- SGTIN.SGTIN_96¶
Human readable GS1 specified header for 96 bit SGTIN tags:
sgtin-96
.
- SGTIN.SGTIN_198¶
Human readable GS1 specified header for 198 bit SGTIN tags:
sgtin-198
.