brother_ql package

Submodules

brother_ql.brother_ql_analyse module

main()[source]

brother_ql.brother_ql_create module

main()[source]
create_label(qlr, image, label_size, threshold=70, cut=True, dither=False, compress=False, red=False, **kwargs)[source]

brother_ql.brother_ql_debug module

class BrotherQL_USBdebug(dev, instructions_data, backend='linux_kernel')[source]

Bases: object

continue_reading(seconds=3.0)[source]
log_interp_response(data)[source]
print_and_debug()[source]
main()[source]

brother_ql.brother_ql_info module

main()[source]

brother_ql.brother_ql_print module

Testing the packaged version of the Linux Kernel backend

main()[source]

brother_ql.cli module

discover_and_list_available_devices(backend)[source]

brother_ql.conversion module

convert(qlr, images, label, **kwargs)[source]

Converts one or more images to a raster instruction file.

Parameters:
Keyword Arguments:
 
  • cut (bool) – Enable cutting after printing the labels.
  • dither (bool) – Instead of applying a threshold to the pixel values, approximate grey tones with dithering.
  • compress
  • red
  • rotate
  • dpi_600
  • hq
  • threshold

future kwargs (to be implemented): cut_after_every, extend_printable_area, resize (in (none’, ‘inner’, ‘outer’))

brother_ql.devicedependent module

Deprecated Module brother_ql.devicedependent

This module held constants and settings that were specific to different QL-series printer models and to different label types.

The content is now split into two modules:

  • brother_ql.models
  • brother_ql.labels

Please import directly from them as this module will be removed in a future version.

brother_ql.exceptions module

exception BrotherQLError[source]

Bases: Exception

exception BrotherQLUnsupportedCmd[source]

Bases: brother_ql.exceptions.BrotherQLError

exception BrotherQLUnknownModel[source]

Bases: brother_ql.exceptions.BrotherQLError

exception BrotherQLRasterError[source]

Bases: brother_ql.exceptions.BrotherQLError

exception BrotherQLBackendError[source]

Bases: brother_ql.exceptions.BrotherQLError

exception BrotherQLSendError(result)[source]

Bases: brother_ql.exceptions.BrotherQLBackendError

brother_ql.helpers module

class ElementsManager(elements=None)[source]

Bases: object

A class managing a collection of ‘elements’. Those elements are expected to be objects that * can be compared for equality against each other * have the attribute .identifier

DEFAULT_ELEMENTS = []
ELEMENT_NAME = 'element'
register(element, pos=-1)[source]
deregister(element)[source]
iter_identifiers()[source]
iter_elements()[source]

brother_ql.image_trafos module

filtered_hsv(im, filter_h, filter_s, filter_v, default_col=(255, 255, 255))[source]

https://stackoverflow.com/a/22237709/183995

brother_ql.labels module

class FormFactor[source]

Bases: enum.IntEnum

Enumeration representing the form factor of a label. The labels for the Brother QL series are supplied either as die-cut (pre-sized), or for more flexibility the continuous label tapes offer the ability to vary the label length.

DIE_CUT = 1

rectangular die-cut labels

ENDLESS = 2

endless (continouse) labels

ROUND_DIE_CUT = 3

round die-cut labels

class Color[source]

Bases: enum.IntEnum

Enumeration representing the colors to be printed on a label. Most labels only support printing black on white. Some newer ones can also print in black and red on white.

BLACK_WHITE = 0

The label can be printed in black & white.

BLACK_RED_WHITE = 1

The label can be printed in black, white & red.

class Label(identifier: str, tape_size: Tuple[int, int], form_factor: brother_ql.labels.FormFactor, dots_total: Tuple[int, int], dots_printable: Tuple[int, int], offset_r: int, feed_margin: int = 0, restricted_to_models: List[str] = NOTHING, color: brother_ql.labels.Color = <Color.BLACK_WHITE: 0>)[source]

Bases: object

This class represents a label. All specifics of a certain label and what the rasterizer needs to take care of depending on the label choosen, should be contained in this class.

identifier = None

A string identifier given to each label that can be selected. Eg. ‘29’.

tape_size = None

The tape size of a single label (width, lenght) in mm. For endless labels, the length is 0 by definition.

form_factor = None

The type of label. It’s an instance of the FormFactor class.

dots_total = None

The total area (width, length) of the label in dots (@300dpi).

dots_printable = None

The printable area (width, length) of the label in dots (@300dpi).

offset_r = None

The required offset from the right side of the label in dots to obtain a centered printout.

feed_margin = None

An additional amount of feeding when printing the label. This is non-zero for some smaller label sizes and for endless labels.

restricted_to_models = None

If a label can only be printed with certain label printers, this member variable lists the allowed ones. Otherwise it’s an empty list.

color = None

Some labels allow printing in red, most don’t. The member is an instance of the Color class.

works_with_model(model)[source]

Method to determine if certain label can be printed by the specified printer model.

name
class LabelsManager(elements=None)[source]

Bases: brother_ql.helpers.ElementsManager

DEFAULT_ELEMENTS = (Label(identifier='12', tape_size=(12, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(142, 0), dots_printable=(106, 0), offset_r=29, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='29', tape_size=(29, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(342, 0), dots_printable=(306, 0), offset_r=6, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='38', tape_size=(38, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(449, 0), dots_printable=(413, 0), offset_r=12, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='50', tape_size=(50, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(590, 0), dots_printable=(554, 0), offset_r=12, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='54', tape_size=(54, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(636, 0), dots_printable=(590, 0), offset_r=0, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='62', tape_size=(62, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(732, 0), dots_printable=(696, 0), offset_r=12, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='62red', tape_size=(62, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(732, 0), dots_printable=(696, 0), offset_r=12, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_RED_WHITE: 1>), Label(identifier='102', tape_size=(102, 0), form_factor=<FormFactor.ENDLESS: 2>, dots_total=(1200, 0), dots_printable=(1164, 0), offset_r=12, feed_margin=35, restricted_to_models=['QL-1050', 'QL-1060N'], color=<Color.BLACK_WHITE: 0>), Label(identifier='17x54', tape_size=(17, 54), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(201, 636), dots_printable=(165, 566), offset_r=0, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='17x87', tape_size=(17, 87), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(201, 1026), dots_printable=(165, 956), offset_r=0, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='23x23', tape_size=(23, 23), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(272, 272), dots_printable=(202, 202), offset_r=42, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='29x42', tape_size=(29, 42), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(342, 495), dots_printable=(306, 425), offset_r=6, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='29x90', tape_size=(29, 90), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(342, 1061), dots_printable=(306, 991), offset_r=6, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='39x90', tape_size=(38, 90), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(449, 1061), dots_printable=(413, 991), offset_r=12, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='39x48', tape_size=(39, 48), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(461, 565), dots_printable=(425, 495), offset_r=6, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='52x29', tape_size=(52, 29), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(614, 341), dots_printable=(578, 271), offset_r=0, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='62x29', tape_size=(62, 29), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(732, 341), dots_printable=(696, 271), offset_r=12, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='62x100', tape_size=(62, 100), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(732, 1179), dots_printable=(696, 1109), offset_r=12, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='102x51', tape_size=(102, 51), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(1200, 596), dots_printable=(1164, 526), offset_r=12, feed_margin=0, restricted_to_models=['QL-1050', 'QL-1060N'], color=<Color.BLACK_WHITE: 0>), Label(identifier='102x152', tape_size=(102, 153), form_factor=<FormFactor.DIE_CUT: 1>, dots_total=(1200, 1804), dots_printable=(1164, 1660), offset_r=12, feed_margin=0, restricted_to_models=['QL-1050', 'QL-1060N'], color=<Color.BLACK_WHITE: 0>), Label(identifier='d12', tape_size=(12, 12), form_factor=<FormFactor.ROUND_DIE_CUT: 3>, dots_total=(142, 142), dots_printable=(94, 94), offset_r=113, feed_margin=35, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='d24', tape_size=(24, 24), form_factor=<FormFactor.ROUND_DIE_CUT: 3>, dots_total=(284, 284), dots_printable=(236, 236), offset_r=42, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>), Label(identifier='d58', tape_size=(58, 58), form_factor=<FormFactor.ROUND_DIE_CUT: 3>, dots_total=(688, 688), dots_printable=(618, 618), offset_r=51, feed_margin=0, restricted_to_models=[], color=<Color.BLACK_WHITE: 0>))
ELEMENT_NAME = 'label'

brother_ql.models module

class Model(identifier: str, min_max_length_dots: Tuple[int, int], min_max_feed: Tuple[int, int] = (35, 1500), number_bytes_per_row: int = 90, additional_offset_r: int = 0, mode_setting: bool = True, cutting: bool = True, expanded_mode: bool = True, compression: bool = True, two_color: bool = False)[source]

Bases: object

This class represents a printer model. All specifics of a certain model and the opcodes it supports should be contained in this class.

identifier = None

A string identifier given to each model implemented. Eg. ‘QL-500’.

min_max_length_dots = None

Minimum and maximum number of rows or ‘dots’ that can be printed. Together with the dpi this gives the minimum and maximum length for continuous tape printing.

min_max_feed = None

The minimum and maximum amount of feeding a label

additional_offset_r = None

The required additional offset from the right side

mode_setting = None

Support for the ‘mode setting’ opcode

cutting = None

Model has a cutting blade to automatically cut labels

expanded_mode = None

Model has support for the ‘expanded mode’ opcode. (So far, all models that have cutting support do).

compression = None

Model has support for compressing the transmitted raster data. Some models with only USB connectivity don’t support compression.

two_color = None

Support for two color printing (black/red/white) available only on some newer models.

name
class ModelsManager(elements=None)[source]

Bases: brother_ql.helpers.ElementsManager

DEFAULT_ELEMENTS = [Model(identifier='QL-500', min_max_length_dots=(295, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=False, cutting=False, expanded_mode=False, compression=False, two_color=False), Model(identifier='QL-550', min_max_length_dots=(295, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=False, cutting=True, expanded_mode=True, compression=False, two_color=False), Model(identifier='QL-560', min_max_length_dots=(295, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=False, cutting=True, expanded_mode=True, compression=False, two_color=False), Model(identifier='QL-570', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=False, cutting=True, expanded_mode=True, compression=False, two_color=False), Model(identifier='QL-580N', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=False), Model(identifier='QL-650TD', min_max_length_dots=(295, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=False), Model(identifier='QL-700', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=False, cutting=True, expanded_mode=True, compression=False, two_color=False), Model(identifier='QL-710W', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=False), Model(identifier='QL-720NW', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=False), Model(identifier='QL-800', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=False, two_color=True), Model(identifier='QL-810W', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=True), Model(identifier='QL-820NWB', min_max_length_dots=(150, 11811), min_max_feed=(35, 1500), number_bytes_per_row=90, additional_offset_r=0, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=True), Model(identifier='QL-1050', min_max_length_dots=(295, 35433), min_max_feed=(35, 1500), number_bytes_per_row=162, additional_offset_r=44, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=False), Model(identifier='QL-1060N', min_max_length_dots=(295, 35433), min_max_feed=(35, 1500), number_bytes_per_row=162, additional_offset_r=44, mode_setting=True, cutting=True, expanded_mode=True, compression=True, two_color=False)]
ELEMENTS_NAME = 'model'

brother_ql.output_helpers module

textual_label_description(labels_to_include)[source]
log_discovered_devices(available_devices, level=20)[source]
textual_description_discovered_devices(available_devices)[source]

brother_ql.raster module

This module contains the implementation of the raster language of the Brother QL-series label printers according to their documentation and to reverse engineering efforts.

The central piece of code in this module is the class BrotherQLRaster.

class BrotherQLRaster(model='QL-500')[source]

Bases: object

This class facilitates the creation of a complete set of raster instructions by adding them one after the other using the methods of the class. Each method call is adding instructions to the member variable data.

Instatiate the class by providing the printer model as argument.

Parameters:

model (str) – Choose from the list of available models.

Variables:
  • data (bytes) – The resulting bytecode with all instructions.
  • exception_on_warning (bool) – If set to True, an exception is raised if trying to add instruction which are not supported on the selected model. If set to False, the instruction is simply ignored and a warning sent to logging/stderr.
two_color_support
add_initialize()[source]
add_status_information()[source]

Status Information Request

add_switch_mode()[source]

Switch dynamic command mode Switch to the raster mode on the printers that support the mode change (others are in raster mode already).

add_invalidate()[source]

clear command buffer

mtype
mwidth
mlength
pquality
add_media_and_quality(rnumber)[source]
add_autocut(autocut=False)[source]
add_cut_every(n=1)[source]
add_expanded_mode()[source]
add_margins(dots=35)[source]
add_compression(compression=True)[source]

Add an instruction enabling or disabling compression for the transmitted raster image lines. Not all models support compression. If the specific model doesn’t support it but this method is called trying to enable it, either a warning is set or an exception is raised depending on the value of exception_on_warning

Parameters:compression (bool) – Whether compression should be on or off
get_pixel_width()[source]
add_raster_data(image, second_image=None)[source]

Add the image data to the instructions. The provided image has to be binary (every pixel is either black or white).

Parameters:
  • image (PIL.Image.Image) – The image to be converted and added to the raster instructions
  • second_image (PIL.Image.Image) – A second image with a separate color layer (red layer for the QL-800 series)
add_print(last_page=True)[source]

brother_ql.reader module

hex_format(data)[source]
chunker(data, raise_exception=False)[source]

Breaks data stream (bytes) into a list of bytes objects containing single instructions each.

Logs warnings for unknown opcodes or raises an exception instead, if raise_exception is set to True.

returns: list of bytes objects

match_opcode(data)[source]
interpret_response(data)[source]
merge_specific_instructions(chunks, join_preamble=True, join_raster=True)[source]

Process a list of instructions by merging subsequent instuctions with identical opcodes into “large instructions”.

class BrotherQLReader(brother_file)[source]

Bases: object

DEFAULT_FILENAME_FMT = 'label{counter:04d}.png'
analyse()[source]