### Install python-barcode Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Install the library using pip. For image export support, include the 'images' extra. ```shell pip install python-barcode ``` ```shell pip install "python-barcode[images]" ``` -------------------------------- ### Command Line Barcode Generation Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Examples of using the python-barcode CLI to create barcodes from the command line, including options for text and image format. ```console $ # Save a barcode to outfile.svg: $ python-barcode create "123456789000" outfile -b ean --text "text to appear under barcode" $ # Generate a PNG (Require Pillow): $ python-barcode create -t png "My Text" outfile $ python-barcode --help usage: python-barcode [-h] [-v] {create,list} ... Create standard barcodes via cli. optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit Actions: {create,list} create Create a barcode with the given options. list List available image and code types. Image output enabled, use --type option to give image format (png, jpeg, ...). $ ``` -------------------------------- ### Interactive PNG Generation Source: https://python-barcode.readthedocs.io/en/stable/getting-started.html Shows how to generate an EAN13 barcode to a PNG file using ImageWriter interactively. Also demonstrates using the `generate` function. ```python >>> import barcode >>> from barcode.writer import ImageWriter >>> EAN = barcode.get_barcode_class('ean13') >>> my_ean = EAN('5901234123457', writer=ImageWriter()) >>> fullname = my_ean.save('ean13_barcode') >>> fullname 'ean13_barcode.png' >>> from io import BytesIO >>> fp = BytesIO() >>> my_ean.write(fp) >>> my_ean >>> with open("path/to/file", "wb") as f: ... my_ean.write(f) # Pillow (ImageWriter) produces RAW format here ... >>> from barcode import generate >>> name = generate('EAN13', '5901234123457', output='barcode_svg') >>> name 'barcode_svg.svg' >>> fp = BytesIO() >>> generate('EAN13', '5901234123457', writer=ImageWriter(), output=fp) >>> ``` -------------------------------- ### Generate Compressed SVG (SVGZ) Source: https://python-barcode.readthedocs.io/en/stable/_sources/writers.rst.txt Demonstrates how to save a barcode as a compressed SVG file by setting the 'compress' option to True. The filename extension will change to .svgz. ```pycon >>> import barcode >>> ean = barcode.get('ean13', '123456789102') # Now we look if the checksum was added >>> ean.get_fullcode() '1234567891026' >>> filename = ean.save('ean13') >>> filename 'ean13.svg' >>> options = dict(compress=True) >>> filename = ean.save('ean13', options) >>> filename 'ean13.svgz' ``` -------------------------------- ### Saving a compressed SVG (SVGZ) Source: https://python-barcode.readthedocs.io/en/stable/writers.html Demonstrates how to save a barcode as a compressed SVG file by setting the 'compress' option to True. The filename extension changes to .svgz for compressed files. ```python import barcode ean = barcode.get('ean13', '123456789102') # Now we look if the checksum was added ean.get_fullcode() '1234567891026' filename = ean.save('ean13') filename 'ean13.svg' options = dict(compress=True) filename = ean.save('ean13', options) filename 'ean13.svgz' ``` -------------------------------- ### Command Line Barcode Generation Source: https://python-barcode.readthedocs.io/en/stable/getting-started.html Utilize the python-barcode CLI to create barcodes from the command line. Supports saving to SVG, generating PNGs, and displaying help information. ```bash $ # Save a barcode to outfile.svg: $ python-barcode create "123456789000" outfile -b ean --text "text to appear under barcode" $ # Generate a PNG (Require Pillow): $ python-barcode create -t png "My Text" outfile $ python-barcode --help ``` -------------------------------- ### Interactive PNG Barcode Generation Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Demonstrates interactive generation of an EAN13 barcode to a PNG file using the python interpreter and ImageWriter. ```pycon >>> import barcode >>> from barcode.writer import ImageWriter >>> EAN = barcode.get_barcode_class('ean13') >>> my_ean = EAN('5901234123457', writer=ImageWriter()) >>> fullname = my_ean.save('ean13_barcode') >>> fullname 'ean13_barcode.png' >>> from io import BytesIO >>> fp = BytesIO() >>> my_ean.write(fp) >>> my_ean >>> with open("path/to/file", "wb") as f: ... my_ean.write(f) # Pillow (ImageWriter) produces RAW format here ... >>> from barcode import generate >>> name = generate('EAN13', '5901234123457', output='barcode_svg') >>> name 'barcode_svg.svg' >>> fp = BytesIO() >>> generate('EAN13', '5901234123457', writer=ImageWriter(), output=fp) >>> ``` -------------------------------- ### UPC-A Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the UPC-A (Universal Product Code A) barcode format. ```APIDOC ## UPC-A ### Description Supports the UPC-A (Universal Product Code A) barcode symbology. ### Class `barcode.upc.UniversalProductCodeA` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Generate Image Barcode to File Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Generate an EAN13 barcode and write it to a file named 'somefile.jpeg' using ImageWriter. ```python with open("somefile.jpeg", "wb") as f: EAN13("100000011111", writer=ImageWriter()).write(f) ``` -------------------------------- ### Interactive SVG Barcode Generation Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Demonstrates interactive generation of an EAN13 barcode to an SVG file using the python interpreter. ```pycon >>> import barcode >>> barcode.PROVIDED_BARCODES ['code128', 'code39', 'ean', 'ean13', 'ean14', 'ean8', 'gs1', 'gs1_128', 'gtin', 'isbn', 'isbn10', 'isbn13', 'issn', 'itf', 'jan', 'pzn', 'upc', 'upca'] >>> EAN = barcode.get_barcode_class('ean13') >>> EAN >>> my_ean = EAN('5901234123457') >>> my_ean >>> fullname = my_ean.save('ean13_barcode') >>> fullname 'ean13_barcode.svg' >>> ``` -------------------------------- ### PZN7 (PZN) Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the PZN7 barcode format, also known as PZN. ```APIDOC ## PZN7 (aka: PZN) ### Description Supports the PZN7 barcode symbology. ### Class `barcode.codex.PZN7` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Generate Image Barcode to File-like Object Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Generate an EAN13 barcode and write it to a BytesIO object using ImageWriter. ```python from io import BytesIO from barcode import EAN13 from barcode.writer import ImageWriter # Write to a file-like object: rv = BytesIO() EAN13(str(100000902922), writer=ImageWriter()).write(rv) ``` -------------------------------- ### Code 39 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the Code 39 barcode format. ```APIDOC ## Code 39 ### Description Supports the Code 39 barcode symbology. ### Class `barcode.codex.Code39` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Generate SVG Barcode to File Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Generate an EAN13 barcode and write it to a file named 'somefile.svg' using SVGWriter. ```python with open("somefile.svg", "wb") as f: EAN13(str(100000011111), writer=SVGWriter()).write(f) ``` -------------------------------- ### EAN-8 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the EAN-8 barcode format. ```APIDOC ## EAN-8 ### Description Supports the EAN-8 barcode symbology. ### Class `barcode.ean.EuropeanArticleNumber8` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Code39 Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Implementation for Code 39 barcodes. Supports checksum addition and custom writers. ```APIDOC ## Code39 ### Description Implementation for Code 39 barcodes. Supports checksum addition and custom writers. ### Class Signature `barcode.codex.Code39(code: str, writer=None, add_checksum: bool = True)` ### Parameters * **code** (str) - Code 39 string without * and without checksum. * **writer** (barcode.writer) - A `barcode.writer` instance used to render the barcode (default: SVGWriter). * **add_checksum** (bool) - Add the checksum to code or not. ### Methods #### `get_fullcode()` Returns the full code as it will be encoded. #### `render(writer_options=None, text=None)` Renders the barcode using self.writer. * **writer_options** (dict) - Options for self.writer, see writer docs for details. * **text** (str) - Text to render under the barcode. ### Returns Output of the writers render method. ``` -------------------------------- ### UniversalProductCodeA Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Universal Product Code (UPC) barcode. UPC-A consists of 12 numeric digits. Initializes new UPC-A barcode. ```APIDOC ## UPC-A ### Description Universal Product Code (UPC) barcode. UPC-A consists of 12 numeric digits. Initializes new UPC-A barcode. ### Parameters * **upc** (str) - The upc number as string. * **writer** - barcode.writer instance. The writer to render the barcode (default: SVGWriter). * **make_ean** (bool) - Indicates if a leading zero should be added to the barcode. This converts the UPC into a valid European Article Number (EAN). ### Methods #### build() Builds the barcode pattern from ‘self.upc’ Returns: The pattern as string Return type: str #### calculate_checksum() Calculates the checksum for UPCA/UPC codes Returns: The checksum for ‘self.upc’ Return type: int #### get_fullcode() Returns the full code, encoded in the barcode. Returns: Full human readable code. Return type: String #### render(writer_options=None, text=None) Renders the barcode using self.writer. Parameters: * **writer_options** – Options for self.writer, see writer docs for details. * **text** – Text to render under the barcode. Returns: Output of the writers render method. #### to_ascii() Returns an ascii representation of the barcode. Return type: str ``` -------------------------------- ### EAN-13 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the EAN-13 barcode format. ```APIDOC ## EAN-13 ### Description Supports the EAN-13 barcode symbology. ### Class `barcode.ean.EuropeanArticleNumber13` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### ISBN-13 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the ISBN-13 (International Standard Book Number 13) barcode format. ```APIDOC ## ISBN-13 ### Description Supports the ISBN-13 (International Standard Book Number 13) barcode symbology. ### Class `barcode.isxn.InternationalStandardBookNumber13` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### ISBN-10 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the ISBN-10 (International Standard Book Number 10) barcode format. ```APIDOC ## ISBN-10 ### Description Supports the ISBN-10 (International Standard Book Number 10) barcode symbology. ### Class `barcode.isxn.InternationalStandardBookNumber10` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Code 128 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the Code 128 barcode format, available since version 0.8beta1. ```APIDOC ## Code 128 ### Description Supports the Code 128 barcode symbology. ### Version Added 0.8beta1 ### Class `barcode.codex.Code128` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### JAN Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the JAN (Japan Article Number) barcode format. ```APIDOC ## JAN ### Description Supports the JAN (Japan Article Number) barcode symbology. ### Class `barcode.ean.JapanArticleNumber` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### PZN7 Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Implementation for PZN7 (German pharmaceutical product number) barcodes. ```APIDOC ## PZN7 (aka: PZN) ### Description Implementation for PZN7 (German pharmaceutical product number) barcodes. ### Class Signature `barcode.codex.PZN7(pzn, writer=None)` ### Parameters * **pzn** (str) - Code to render. * **writer** (barcode.writer) - The writer to render the barcode (default: SVGWriter). ### Methods #### `get_fullcode()` Returns the full code as it will be encoded. ``` -------------------------------- ### GS1-128 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the GS1-128 barcode format, available since version v0.10.0. ```APIDOC ## GS1-128 ### Description Supports the GS1-128 barcode symbology. ### Version Added v0.10.0 ### Class `barcode.codex.Gs1_128` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Generate SVG Barcode to File-like Object Source: https://python-barcode.readthedocs.io/en/stable/_sources/getting-started.rst.txt Generate an EAN13 barcode and write it to a BytesIO object using SVGWriter. ```python from io import BytesIO from barcode import EAN13 from barcode.writer import SVGWriter # Write to a file-like object: rv = BytesIO() EAN13("100000902922", writer=SVGWriter()).write(rv) ``` -------------------------------- ### Generate Image Barcodes Source: https://python-barcode.readthedocs.io/en/stable/getting-started.html Generate EAN13 barcodes and write them to image files (e.g., JPEG) or file-like objects using ImageWriter. Recommended for non-SVG compatible targets. ```python from io import BytesIO from barcode import EAN13 from barcode.writer import ImageWriter # Write to a file-like object: rv = BytesIO() EAN13(str(100000902922), writer=ImageWriter()).write(rv) # Or to an actual file: with open("somefile.jpeg", "wb") as f: EAN13("100000011111", writer=ImageWriter()).write(f) ``` -------------------------------- ### InternationalStandardBookNumber10 Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Initializes a new ISBN-10 barcode. This code is rendered as EAN-13 by prefixing it with 978. ```APIDOC ## ISBN-10 ### Description Initializes new ISBN-10 barcode. This code is rendered as EAN-13 by prefixing it with 978. ### Parameters * **isbn** (String) - The isbn number as string. * **writer** (barcode.writer Instance) - The writer to render the barcode (default: SVGWriter). ``` -------------------------------- ### Code128 Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Implementation for Code 128 barcodes. Checksum is added automatically. ```APIDOC ## Code128 ### Description Implementation for Code 128 barcodes. Checksum is added automatically. ### Class Signature `barcode.codex.Code128(code, writer=None)` ### Parameters * **code** (str) - Code 128 string without checksum (added automatically). * **writer** (barcode.writer) - The writer to render the barcode (default: SVGWriter). ### Methods #### `get_fullcode()` Returns the full code, encoded in the barcode. #### `render(writer_options=None, text=None)` Renders the barcode using self.writer. * **writer_options** (dict) - Options for self.writer, see writer docs for details. * **text** (str) - Text to render under the barcode. ### Returns Output of the writers render method. ``` -------------------------------- ### EAN14 Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the EAN14 (European Article Number 14) barcode format. ```APIDOC ## EAN14 ### Description Supports the EAN14 (European Article Number 14) barcode symbology. ### Class `barcode.ean.EuropeanArticleNumber14` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### Generate SVG Barcodes Source: https://python-barcode.readthedocs.io/en/stable/getting-started.html Generate EAN13 barcodes and write them to SVG files or file-like objects. Checksums are calculated automatically. ```python from io import BytesIO from barcode import EAN13 from barcode.writer import SVGWriter # Write to a file-like object: rv = BytesIO() EAN13("100000902922", writer=SVGWriter()).write(rv) # Or to an actual file: with open("somefile.svg", "wb") as f: EAN13(str(100000011111), writer=SVGWriter()).write(f) ``` -------------------------------- ### ISSN Source: https://python-barcode.readthedocs.io/en/stable/_sources/supported-formats.rst.txt Documentation for the ISSN (International Standard Serial Number) barcode format. ```APIDOC ## ISSN ### Description Supports the ISSN (International Standard Serial Number) barcode symbology. ### Class `barcode.isxn.InternationalStandardSerialNumber` ### Members (See `autoclass` documentation for details on available members.) ``` -------------------------------- ### InternationalStandardSerialNumber Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Initializes a new ISSN barcode. This code is rendered as EAN-13 by prefixing it with 977 and adding 00 between code and checksum. ```APIDOC ## ISSN ### Description Initializes new ISSN barcode. This code is rendered as EAN-13 by prefixing it with 977 and adding 00 between code and checksum. ### Parameters * **issn** (String) - The issn number as string. * **writer** (barcode.writer Instance) - The writer to render the barcode (default: SVGWriter). ``` -------------------------------- ### Gs1_128 Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html GS1-128 barcode. Following the norm, a gs1-128 barcode is a subset of code 128 barcode, it can be generated by prepending the code with the FNC1 character. ```APIDOC ## GS1-128 ### Description Following the norm, a gs1-128 barcode is a subset of code 128 barcode, it can be generated by prepending the code with the FNC1 character. ### Parameters * **code** (String) - The gs1-128 code. * **writer** (barcode.writer Instance) - The writer to render the barcode (default: SVGWriter). ### Methods #### get_fullcode() Returns the full code, encoded in the barcode. Returns: Full human readable code. Return type: String ``` -------------------------------- ### EuropeanArticleNumber14 Source: https://python-barcode.readthedocs.io/en/stable/supported-formats.html Represents an EAN-14 barcode. See EAN13’s __init__ for details. ```APIDOC ## EAN14 ### Description Represents an EAN-14 barcode. See EAN13’s __init__ for details. ### Parameters * **ean** (String) - The ean number as string. * **writer** (barcode.writer Instance) - The writer to render the barcode (default: SVGWriter). * **no_checksum** (bool) - If true, the checksum is not calculated. * **guardbar** (bool) - If true, a guard bar is added to the barcode. ### Methods #### calculate_checksum() Calculates the checksum for EAN13-Code. Returns: The checksum for self.ean. Return type: Integer ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.