### Install Biip with Money Support Source: https://github.com/jodal/biip/blob/main/docs/index.md Install Biip with optional support for parsing money amounts by including the 'money' extra. ```sh python3 -m pip install "biip[money]" ``` -------------------------------- ### Install Biip Library Source: https://github.com/jodal/biip/blob/main/docs/index.md Install the Biip library using pip. Ensure you have Python 3.10 or newer. ```sh python3 -m pip install biip ``` -------------------------------- ### Try Biip without Installation Source: https://github.com/jodal/biip/blob/main/docs/index.md Use uvx to try Biip in a Python shell without a local installation. This is useful for quick testing. ```sh uvx --with biip python ``` -------------------------------- ### GS1 Digital Link URI Example (Supported) Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v5.md This example demonstrates the correct format for a GS1 Digital Link URI after aliases have been removed, using explicit Application Identifiers. ```text https://id.gs1.org/01/07032069804988100329/10/ABC ``` -------------------------------- ### GS1 Digital Link URI Example (Unsupported) Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v5.md This example shows an outdated format for a GS1 Digital Link URI that uses aliases, which is no longer supported in Biip v5.x. ```text https://id.gs1.org/gtin/07032069804988100329/lot/ABC ``` -------------------------------- ### Basic Biip Usage in Python Shell Source: https://github.com/jodal/biip/blob/main/docs/index.md Import and use Biip within a Python shell after setting it up with uvx or installing it. ```python >>> import biip >>> biip.parse("your-barcode-data") ``` -------------------------------- ### Parse Barcode Data with Biip Source: https://github.com/jodal/biip/blob/main/README.md Use the `biip.parse()` function to interpret data from a barcode string. This example demonstrates parsing an EAN-13 barcode. ```python >>> from rich import print >>> import biip >>> print(biip.parse("]E09781492053743")) ParseResult( value="]E09781492053743", symbology_identifier=SymbologyIdentifier( value="]E0", iso_symbology=ISOSymbology.EAN_UPC, modifiers='0', gs1_symbology=GS1Symbology.EAN_13 ), gtin=Gtin( value='9781492053743', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='978', usage='Bookland (ISBN)'), company_prefix=None, payload='978149205374', check_digit=3 ) ) ``` -------------------------------- ### Get Batch/Lot Number by Application Identifier Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Retrieves the element string for the batch or lot number using its application identifier ('10') and accesses its value. ```python >>> element_string = result.gs1_message.element_strings.get(ai="10") >>> element_string.value '0329' ``` -------------------------------- ### Update GS1 Message Get Method Call Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v4.md Change calls from `gs1_message.get()` to `gs1_message.element_strings.get()` to retrieve element strings. ```python gs1_message.element_strings.get() ``` -------------------------------- ### Get Expiration Date by Data Title Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Fetches the element string for the expiration date using its data title ('BEST BY') and accesses the parsed datetime.date object. ```python >>> element_string = result.gs1_message.element_strings.get(data_title="BEST BY") >>> element_string.date datetime.date(2021, 5, 26) ``` -------------------------------- ### Get Human-Readable Interpretation (HRI) of GS1 Message Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Converts the parsed GS1 message into a human-readable string format, showing the application identifiers and their corresponding values. ```python >>> result.gs1_message.as_hri() '(01)07032069804988(15)210526(10)0329' ``` -------------------------------- ### Import Biip and Rich for Pretty Printing Source: https://github.com/jodal/biip/blob/main/docs/getting-started/index.md Import the necessary libraries for parsing barcode data and for pretty-printing the output. Rich is optional but recommended for readability. ```python >>> from rich import print >>> import biip ``` -------------------------------- ### Convert GTIN to GTIN-14 Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gtin.md Demonstrates how to convert a GTIN value to its GTIN-14 representation, which is the canonical format for database storage. ```python >>> result.gtin.value '123601057072' ``` ```python >>> result.gtin.as_gtin_14() '00123601057072' ``` -------------------------------- ### Parse an RCN with specified region for price/weight extraction Source: https://github.com/jodal/biip/blob/main/docs/getting-started/rcn.md Shows how to parse an RCN after specifying the geographical region using `ParseConfig`. This enables Biip to extract price and weight information if the RCN follows the rules for that region. ```python >>> from biip.rcn import RcnRegion >>> config = biip.ParseConfig(rcn_region=RcnRegion.GREAT_BRITAIN) >>> print(biip.parse("2011122912346", config=config)) ParseResult( value='2011122912346', gtin=Rcn( value='2011122912346', format=GtinFormat.GTIN_13, prefix=GS1Prefix( value='201', usage='Used to issue GS1 Restricted Circulation Numbers within a geographic region (MO defined)' ), company_prefix=None, item_reference='11122', payload='201112291234', check_digit=6, usage=RcnUsage.GEOGRAPHICAL, region=RcnRegion.GREAT_BRITAIN, price=Decimal('12.34'), money=Money('12.34', 'GBP') ), upc_error="Failed to parse '2011122912346' as UPC: Expected 6, 7, 8, or 12 digits, got 13.", sscc_error="Failed to parse '2011122912346' as SSCC: Expected 18 digits, got 13.", gs1_message_error="Failed to match '122912346' with GS1 AI (12) pattern '^12(\d{2}(?:0\d|1[0-2])(?:[0-2]\d|3[01])) Perkenalkan'." ) ``` -------------------------------- ### Parse Barcode Data with Biip Source: https://github.com/jodal/biip/blob/main/docs/index.md Use this snippet to parse barcode data and extract structured information. It requires importing the 'biip' library. ```python >>> from rich import print >>> import biip >>> print(biip.parse("]E05710858000781")) ParseResult( value="]E05710858000781", symbology_identifier=SymbologyIdentifier( value="]E0", iso_symbology=ISOSymbology.EAN_UPC, modifiers='0', gs1_symbology=GS1Symbology.EAN_13 ), gtin=Gtin( value='5710858000781', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='571', usage='GS1 Denmark'), company_prefix=GS1CompanyPrefix(value='5710858'), item_reference='00078', payload='571085800078', check_digit=1 ) ) ``` -------------------------------- ### Update ParseConfig for Separator Characters Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v4.md Replace the old `separator_chars` argument in `biip.parse()` with a `ParseConfig` instance for specifying custom separators. ```python config = biip.ParseConfig(separator_chars=["|"]) result = biip.parse("0107032069804988100329|15210525", config=config) ``` -------------------------------- ### Parse GS1 Digital Link URI with Biip Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-digital-links.md Use Biip to parse a GS1 Digital Link URI and extract structured data including GTIN, batch number, and expiration date. ```python >>> result = biip.parse("https://www.example.com/products/01/07032069804988?10=0329&15=210526") >>> print(result) ParseResult( value='https://www.example.com/products/01/07032069804988?10=0329&15=210526', gtin=Gtin( value='07032069804988', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='703', usage='GS1 Norway'), company_prefix=GS1CompanyPrefix(value='703206'), item_reference='980498', payload='703206980498', check_digit=8 ), gs1_digital_link_uri=GS1DigitalLinkURI( value='https://www.example.com/products/01/07032069804988?10=0329&15=210526', element_strings=[ GS1ElementString( ai=GS1ApplicationIdentifier( ai='01', description='Global Trade Item Number (GTIN)', data_title='GTIN', separator_required=False, format='N2+N14' ), value='07032069804988', pattern_groups=['07032069804988'], gtin=Gtin( value='07032069804988', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='703', usage='GS1 Norway'), company_prefix=GS1CompanyPrefix(value='703206'), item_reference='980498', payload='703206980498', check_digit=8 ) ), GS1ElementString( ai=GS1ApplicationIdentifier( ai='10', description='Batch or lot number', data_title='BATCH/LOT', separator_required=True, format='N2+X..20' ), value='0329', pattern_groups=['0329'] ), GS1ElementString( ai=GS1ApplicationIdentifier( ai='15', description='Best before date (YYMMDD)', data_title='BEST BEFORE or BEST BY', separator_required=False, format='N2+N6' ), value='210526', pattern_groups=['210526'], date=datetime.date(2021, 5, 26) ) ] ) ) ``` -------------------------------- ### Parse an RCN without specifying region Source: https://github.com/jodal/biip/blob/main/docs/getting-started/rcn.md Demonstrates parsing a GTIN that is identified as an RCN. The result includes details about the RCN structure but not extracted price or weight. ```python >>> print(biip.parse("2011122912346")) ParseResult( value='2011122912346', gtin=Rcn( value='2011122912346', format=GtinFormat.GTIN_13, prefix=GS1Prefix( value='201', usage='Used to issue GS1 Restricted Circulation Numbers within a geographic region (MO defined)' ), company_prefix=None, item_reference=None, payload='201112291234', check_digit=6 ), upc_error="Failed to parse '2011122912346' as UPC: Expected 6, 7, 8, or 12 digits, got 13.", sscc_error="Failed to parse '2011122912346' as SSCC: Expected 18 digits, got 13.", gs1_message_error="Failed to match '122912346' with GS1 AI (12) pattern '^12(\d{2}(?:0\d|1[0-2])(?:[0-2]\d|3[01])) Perkenalkan'." ) ``` -------------------------------- ### Update ParseConfig for Variable Measure Verification Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v4.md Replace the old `rcn_verify_variable_measure` configuration option with a `ParseConfig` instance. ```python config = biip.ParseConfig(rcn_verify_variable_measure=True) result = biip.parse("0107032069804988100329", config=config) ``` -------------------------------- ### Configure Biip with Custom Separator Character Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Configures Biip to use a pipe character ('|') as a separator for variable-length fields. This is useful when the barcode scanner does not output the standard GS character or when the data pipeline cannot preserve it. ```python >>> config = biip.ParseConfig(separator_chars=["|"]) >>> result = biip.parse("0107032069804988100329|15210525", config=config) >>> result.gs1_message.as_hri() '(01)07032069804988(10)0329(15)210525' ``` -------------------------------- ### Access All Parsed GS1 Element Strings Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Retrieves a list of all parsed GS1 element strings from the message. Each element string contains an application identifier (AI), its description, and the extracted value. ```python >>> print(result.gs1_message.element_strings) [ GS1ElementString( ai=GS1ApplicationIdentifier( ai='01', description='Global Trade Item Number (GTIN)', data_title='GTIN', separator_required=False, format='N2+N14' ), value='07032069804988', pattern_groups=['07032069804988'], gtin=Gtin( value='07032069804988', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='703', usage='GS1 Norway'), company_prefix=GS1CompanyPrefix(value='703206'), item_reference='980498', payload='703206980498', check_digit=8 ) ), GS1ElementString( ai=GS1ApplicationIdentifier( ai='15', description='Best before date (YYMMDD)', data_title='BEST BEFORE or BEST BY', separator_required=False, format='N2+N6' ), value='210526', pattern_groups=['210526'], date=datetime.date(2021, 5, 26) ), GS1ElementString( ai=GS1ApplicationIdentifier( ai='10', description='Batch or lot number', data_title='BATCH/LOT', separator_required=True, format='N2+X..20' ), value='0329', pattern_groups=['0329'] ) ] ``` -------------------------------- ### Access SSCC Directly from ParseResult Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Demonstrates accessing the parsed SSCC object directly from the main ParseResult object, confirming it matches the element string's SSCC. ```python >>> result.sscc == element_string.sscc True >>> print(result.sscc) Sscc( value='157035381410375177', prefix=GS1Prefix(value='570', usage='GS1 Denmark'), company_prefix=GS1CompanyPrefix(value='5703538'), extension_digit=1, payload='15703538141037517', check_digit=7 ) ``` -------------------------------- ### Convert GS1 Message to GS1 Digital Link URI with Custom Domain Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-digital-links.md Convert a GS1 message object to a GS1 Digital Link URI, specifying a custom domain and path prefix. ```python >>> dl_uri = message.as_gs1_digital_link_uri() >>> dl_uri.as_uri( ... domain="another.example.net", ... prefix="database", ... ) 'https://another.example.net/database/01/07032069804988/10/0329?15=210526' ``` -------------------------------- ### Update ParseConfig for RCN Region Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v4.md Replace the old `rcn_region` configuration option with a `ParseConfig` instance. ```python config = biip.ParseConfig(rcn_region=True) result = biip.parse("0107032069804988100329", config=config) ``` -------------------------------- ### Convert GS1 Digital Link URI to Canonical URI Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-digital-links.md Convert a parsed GS1 Digital Link URI result to its canonical URI representation. ```python >>> result.gs1_digital_link_uri.as_canonical_uri() 'https://id.gs1.org/01/07032069804988/10/0329?15=210526' ``` -------------------------------- ### Parse GS1 Message with Variable-Length Field at End Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Parses a GS1 message where the variable-length batch/lot number (AI '10') is the last element. Biip correctly identifies the end of the message. ```python >>> result = biip.parse("010703206980498815210526100329") >>> result.gs1_message.as_hri() '(01)07032069804988(15)210526(10)0329' ``` -------------------------------- ### Parse Barcode with Symbology Identifier - Python Source: https://github.com/jodal/biip/blob/main/docs/getting-started/symbology-identifiers.md Use this snippet to parse barcode data that may include a Symbology Identifier. Biip will automatically detect the identifier and use it to select the appropriate parser, improving efficiency. ```python >>> print(biip.parse("]E09781492053743")) ParseResult( value="]E09781492053743", symbology_identifier=SymbologyIdentifier( value="]E0", iso_symbology=ISOSymbology.EAN_UPC, modifiers='0', gs1_symbology=GS1Symbology.EAN_13 ), gtin=Gtin( value='9781492053743', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='978', usage='Bookland (ISBN)'), company_prefix=None, item_reference=None, payload='978149205374', check_digit=3 ) ) ``` -------------------------------- ### Update GS1 Symbology Method Call Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v4.md Change calls from `GS1Symbology.with_ai_element_strings()` to `GS1Symbology.with_gs1_messages()` when working with GS1 messages. ```python GS1Symbology.with_gs1_messages() ``` -------------------------------- ### Parsing with Multiple Errors Source: https://github.com/jodal/biip/blob/main/docs/getting-started/error-handling.md When all parsers fail, Biip returns a ParseResult object. The error fields within this object provide specific reasons why each parser could not interpret the input data. ```python >>> print(biip.parse("12345678")) ParseResult( value='12345678', gtin_error="Invalid GTIN check digit for '12345678': Expected 0, got 8.", upc_error="Invalid UPC-E check digit for '12345678': Expected 0, got 8.", sscc_error="Failed to parse '12345678' as SSCC: Expected 18 digits, got 8.", gs1_message_error="Failed to match '12345678' with GS1 AI (12) pattern '^12(\d{2}(?:0\d|1[0-2])(?:[0-2]\d|3[01]))$'." ) ``` -------------------------------- ### Parse GS1 Message with Variable-Length Field in Middle (Incorrect) Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Demonstrates parsing a GS1 message where the variable-length batch/lot number (AI '10') is placed in the middle without a proper terminator. This leads to incorrect parsing as the field consumes subsequent data. ```python >>> result = biip.parse("010703206980498810032915210525") >>> result.gs1_message.as_hri() '(01)07032069804988(10)032915210525' ``` -------------------------------- ### Parse GS1 Message with FNC1 (GS Character) Terminator Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Shows how to correctly parse a GS1 message with a variable-length field by using the Group Separator (GS) character (\x1d) to mark the end of the field. This simulates the FNC1 symbol from a barcode. ```python >>> result = biip.parse("0107032069804988100329\x1d15210525") >>> result.gs1_message.as_hri() '(01)07032069804988(10)0329(15)210525' ``` -------------------------------- ### Update GS1 Message Filter Method Call Source: https://github.com/jodal/biip/blob/main/docs/upgrading/v4.md Change calls from `gs1_message.filter()` to `gs1_message.element_strings.filter()` to access the filtering functionality. ```python gs1_message.element_strings.filter() ``` -------------------------------- ### Parse GTIN from EAN-13 Barcode Source: https://github.com/jodal/biip/blob/main/docs/getting-started/parsing.md Use `biip.parse()` to extract GTIN information from an EAN-13 barcode. The function returns a detailed `ParseResult` object, including the GTIN value, format, prefix, company prefix, item reference, and check digit. It also provides error messages for other formats like UPC and SSCC if parsing fails. ```python >>> print(biip.parse("7032069804988")) ParseResult( value='7032069804988', gtin=Gtin( value='7032069804988', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='703', usage='GS1 Norway'), company_prefix=GS1CompanyPrefix(value='703206'), item_reference='980498', payload='703206980498', check_digit=8 ), upc_error="Failed to parse '7032069804988' as UPC: Expected 6, 7, 8, or 12 digits, got 13.", sscc_error="Failed to parse '7032069804988' as SSCC: Expected 18 digits, got 13.", gs1_message=GS1Message( value='7032069804988', element_strings=[ GS1ElementString( ai=GS1ApplicationIdentifier( ai='7032', description='Number of processor with three-digit ISO country code', data_title='PROCESSOR # 2', separator_required=True, format='N3+X..27' ), value='069804988', pattern_groups=['069', '804988'] ) ] ) ) ``` -------------------------------- ### Define GS1 Application Identifier for Variable-Length Field Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md This Python code defines a GS1 Application Identifier for a batch or lot number, specifying it as a variable-length field with a format that allows up to 20 alphanumeric characters. ```python GS1ApplicationIdentifier( ai='10', description='Batch or lot number', data_title='BATCH/LOT', separator_required=True, format='N2+X..20' ) ``` -------------------------------- ### Format GS1 Message as Human Readable Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Converts a parsed GS1 message into a human-readable string format, suitable for display below a barcode. ```python >>> result.gs1_message.as_hri() '(00)157035381410375177' ``` -------------------------------- ### Parse GS1 Message String Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Parses a GS1-128 barcode data string into a structured result object. This is the initial step to access all GS1 data. ```python >>> result = biip.parse("010703206980498815210526100329") ``` -------------------------------- ### Parse a GTIN-12 Number Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gtin.md Parses a GTIN-12 value and displays the detailed ParseResult, including GTIN, UPC, and potential error messages. ```python >>> result = biip.parse("123601057072") >>> print(result) ParseResult( value='123601057072', gtin=Gtin( value='123601057072', format=GtinFormat.GTIN_12, prefix=GS1Prefix(value='012', usage='GS1 US'), company_prefix=None, item_reference=None, payload='12360105707', check_digit=2 ), upc=Upc( value='123601057072', format=UpcFormat.UPC_A, number_system_digit=1, payload='12360105707', check_digit=2 ), sscc_error="Failed to parse '123601057072' as SSCC: Expected 18 digits, got 12.", gs1_message_error="Failed to get GS1 Application Identifier from '7072'." ) ``` -------------------------------- ### Extract and Use SSCC Element String Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Extracts a specific element string (AI '00' for SSCC) from a parsed GS1 message and accesses its SSCC details. ```python >>> element_string = result.gs1_message.element_strings.(ai="00") >>> element_string.ai.data_title 'SSCC' >>> element_string.sscc.prefix.usage 'GS1 Denmark' >>> element_string.sscc.as_hri() '1 5703538 141037517 7' ``` -------------------------------- ### Convert GS1 Digital Link URI to GS1 Message HRI Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-digital-links.md Convert a parsed GS1 Digital Link URI result to a GS1 message and then to its Human Readable Interpretation (HRI) format. ```python >>> message = result.gs1_digital_link_uri.as_gs1_message() >>> message.as_hri() '(01)07032069804988(10)0329(15)210526' ``` -------------------------------- ### Parse SSCC GS1-128 Barcode Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Parses a GS1-128 barcode string representing an SSCC and displays the structured GS1 message. ```python >>> result = biip.parse("00157035381410375177") >>> print(result.gs1_message) GS1Message( value='00157035381410375177', element_strings=[ GS1ElementString( ai=GS1ApplicationIdentifier( ai='00', description='Serial Shipping Container Code (SSCC)', data_title='SSCC', separator_required=False, format='N2+N18' ), value='157035381410375177', pattern_groups=['157035381410375177'], sscc=Sscc( value='157035381410375177', prefix=GS1Prefix(value='570', usage='GS1 Denmark'), company_prefix=GS1CompanyPrefix(value='5703538'), extension_digit=1, payload='15703538141037517', check_digit=7 ) ) ] ) ``` -------------------------------- ### Access GTIN Directly from ParseResult Source: https://github.com/jodal/biip/blob/main/docs/getting-started/gs1-messages.md Retrieves the Global Trade Item Number (GTIN) directly from the ParseResult object. This is a convenience method for accessing the GTIN element string. ```python >>> result.gtin == result.gs1_message.element_strings[0].gtin True >>> print(result.gtin) Gtin( value='07032069804988', format=GtinFormat.GTIN_13, prefix=GS1Prefix(value='703', usage='GS1 Norway'), company_prefix=GS1CompanyPrefix(value='703206'), payload='703206980498', check_digit=8 ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.