pybarcodes package
Submodules
pybarcodes.barcode module
- class pybarcodes.barcode.Barcode(barcode: str | int)[source]
Bases:
objectA base class for all barcode types
- BARCODE_COLUMN_NUMBER: int
- BARCODE_FONT_SIZE: int
- BARCODE_PADDING: Any
- BARCODE_SIZE: tuple[int, int]
- property image: Image
Retrieves and returns the PIL.Image object with the barcode
- Returns:
- PIl.Image.Image:
The barcode image
- classmethod normalize(barcode: str | int) str[source]
Return the normalized barcode value used by the instance.
- render(size: tuple[int, int] | None = None, module_width: int | None = None, bar_height: int | None = None, quiet_zone: int | None = None, font_size: int | None = None, draw_text: bool = True) Image[source]
Create a PIL Image object for the barcode.
- save(path: str | PathLike[str], size: tuple[int, int] | None = None, module_width: int | None = None, bar_height: int | None = None, quiet_zone: int | None = None, font_size: int | None = None, draw_text: bool = True, **save_kwargs: Any) Image[source]
Create a PIL Image object and save it to the path given.
It also returns that image object to the caller.
- Parameters:
- path: str
The path to save the image to
- Returns:
- Returns a PIL Image object to the caller
- to_bytesio(encoding: str = 'ascii') BytesIO[source]
Return the normalized barcode text in a BytesIO object.
- to_image_bytes(format: str = 'PNG', size: tuple[int, int] | None = None, module_width: int | None = None, bar_height: int | None = None, quiet_zone: int | None = None, font_size: int | None = None, draw_text: bool = True, **save_kwargs: Any) bytes[source]
Return the rendered barcode image as bytes.
- to_image_bytesio(format: str = 'PNG', size: tuple[int, int] | None = None, module_width: int | None = None, bar_height: int | None = None, quiet_zone: int | None = None, font_size: int | None = None, draw_text: bool = True, **save_kwargs: Any) BytesIO[source]
Return the rendered barcode image in a BytesIO object.
pybarcodes.ean module
- class pybarcodes.ean.EAN(barcode: str | int)[source]
Bases:
BarcodeBase class for EAN type barcodes
Shouldn’t be used directly and it’s subclasses are preferred
- classmethod calculate_checksum(barcode: str | EAN13 | EAN8 | EAN14) int[source]
Calculate the checksum from the barcode given
This is a class method because it can only be used just to calculate any barcode of the same type, not only the instance’s checksum
- Parameters:
- barcode: Union[str, “EAN13”]
The barcode to calculate the check digit of.
- Returns:
- A single digit integer that helps determine if the barcode is correct
- Raises:
- TypeError
Raised when the barcode is not an acceptable type
- IncorrectFormat
Raised when the barcode is not in the format expected
- property get_binary_string: str
Converts the code to the binary string that it produces The binary string contains the left, center and right guards, and also the binary values of each digit.
- Returns:
- The return string contains 1’s and 0’s that represent the barcode.
- This string is used to iterate over, to create the barcode.
- class pybarcodes.ean.EAN13(barcode: str | int)[source]
Bases:
EANThe class to represent an EAN13 barcode
- Attributes:
- BARCODE_LENGTH: int
The number of digits in an EAN13 barcode
- BARCODE_SIZE: Tuple[int, int]
The barcode’s size and not the output image’s size
- BARCODE_FONT_SIZE: int
The size of the font under the barcode
- BARCODE_COLUMN_NUMBER: int
How many binary columns the barcode consists of
- BARCODE_PADDING: Tuple[int, int]
The padding around the actual barcode
- BARCODE_COLUMN_NUMBER: int = 110
- BARCODE_FONT_SIZE: int = 46
- BARCODE_LENGTH = 12
- BARCODE_PADDING: Any = (100, 200)
- BARCODE_SIZE: RenderSize = (720, 360)
- FIRST_SECTION = (0, 6)
- HAS_STRUCTURE = True
- SECOND_SECTION = (6, 12)
- WEIGHTS = (3, 1)
- class pybarcodes.ean.EAN14(barcode: str | int)[source]
Bases:
EANThe class to represent an EAN14 barcode
- Attributes:
- BARCODE_LENGTH: int
The number of digits in an EAN14 barcode
- BARCODE_SIZE: Tuple[int, int]
The barcode’s size and not the output image’s size
- BARCODE_FONT_SIZE: int
The size of the font under the barcode
- BARCODE_COLUMN_NUMBER: int
How many binary columns the barcode consists of
- BARCODE_PADDING: Tuple[int, int]
The padding around the actual barcode
- BARCODE_COLUMN_NUMBER: int = 108
- BARCODE_FONT_SIZE: int = 46
- BARCODE_LENGTH = 13
- BARCODE_PADDING: Any = (100, 200)
- BARCODE_SIZE: RenderSize = (720, 360)
- FIRST_SECTION = (0, 6)
- HAS_STRUCTURE = True
- SECOND_SECTION = (6, 13)
- WEIGHTS = (1, 3)
- class pybarcodes.ean.EAN8(barcode: str | int)[source]
Bases:
EANThe class to represent an EAN8 barcode
- Attributes:
- BARCODE_LENGTH: int
The number of digits of the barcode
- BARCODE_SIZE: Tuple[int, int]
The barcode’s size and not the output image’s size
- BARCODE_FONT_SIZE: int
The size of the font under the barcode
- BARCODE_COLUMN_NUMBER: int
How many binary columns the barcode consists of
- BARCODE_PADDING: Tuple[int, int]
The padding around the actual barcode
- BARCODE_COLUMN_NUMBER: int = 75
- BARCODE_FONT_SIZE: int = 40
- BARCODE_LENGTH = 7
- BARCODE_PADDING: Any = (0, 200)
- BARCODE_SIZE: RenderSize = (480, 240)
- FIRST_SECTION = (0, 4)
- HAS_STRUCTURE = False
- SECOND_SECTION = (4, 8)
- WEIGHTS = (1, 3)
- class pybarcodes.ean.JAN(barcode: str | int)[source]
-
The class to represent an EAN13 barcode
- Attributes:
- BARCODE_LENGTH: int
The number of digits in an EAN13 barcode
- BARCODE_SIZE: Tuple[int, int]
The barcode’s size and not the output image’s size
- BARCODE_FONT_SIZE: int
The size of the font under the barcode
- BARCODE_COLUMN_NUMBER: int
How many binary columns the barcode consists of
- BARCODE_PADDING: Tuple[int, int]
The padding around the actual barcode