brotherql

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: MIT Imports: 8 Imported by: 0

README

brotherql

Go library and CLI for printing to Brother QL label printers over USB.

Status: Early development (v0.x). API may change before v1.0.

Acknowledgements

Inspired by the brother_ql Python library by Philipp Klaus, which served as a protocol reference and inspiration for this Go port.

Features

  • Idiomatic Go API: pass an image.Image, get a printed label.
  • CLI tool for ad-hoc printing and shell-script integration.
  • Native USB communication via gousb — no CUPS or system driver required.
  • Status query (paper present, errors, media dimensions).
  • Tested via golden files cross-validated against the Python reference.

Supported hardware

  • Brother QL-700 over USB.
  • Brother QL-710W over USB (wireless interface not used; USB only).

Other Brother QL models (QL-720NW, QL-800, QL-1100, QL-820NWB, etc.) are not yet supported in v1. Contributions welcome.

Installation

Prerequisites

libusb and pkg-config must be installed on your system:

OS Install
macOS brew install libusb pkg-config
Debian/Ubuntu sudo apt install libusb-1.0-0-dev pkg-config
Fedora sudo dnf install libusb1-devel pkgconf-pkg-config
As a library
go get github.com/kurtinge/brotherql
As a CLI
go install github.com/kurtinge/brotherql/cmd/brotherql@latest

Pre-built binaries are also available on the Releases page.

Quick start (library)

package main

import (
    "image/png"
    "log"
    "os"

    "github.com/kurtinge/brotherql"
)

func main() {
    p, err := brotherql.Open()
    if err != nil {
        log.Fatal(err)
    }
    defer p.Close()

    f, err := os.Open("label.png")
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()
    img, err := png.Decode(f)
    if err != nil {
        log.Fatal(err)
    }

    err = p.Print(img, brotherql.PrintOptions{
        Label:   brotherql.Label62,
        AutoCut: true,
    })
    if err != nil {
        log.Fatal(err)
    }
}

Quick start (CLI)

List connected printers:

brotherql list
# QL-700 serial=000D5G103245 (bus 2 addr 5)

Show printer status:

brotherql status
# Ready: yes
# Media: 62mm continuous
# Error: none

Print a label:

brotherql print --label 62 image.png

Print to a specific printer (multiple connected):

brotherql print --label 62 --serial 000D5G103245 image.png

Supported labels

Constant Description
Label62 62mm continuous tape (DK-22205 etc.)
Label62x29 62mm × 29mm die-cut
Label12 12mm continuous tape (DK-22214)

More to come; PRs welcome.

Testing

# Pure unit tests (no hardware)
go test ./...

# Hardware integration tests (requires connected printer)
go test -tags=hardware ./...

The test suite uses golden files cross-validated against the Python brother_ql reference. To regenerate them, see testdata/bootstrap.sh.

Contributing

Open an issue first for non-trivial changes. PRs welcome — please include tests.

License

MIT — see LICENSE.

Documentation

Overview

Package brotherql is a Go library and CLI for printing to Brother QL label printers over USB.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPrinterNotFound = errors.New("brotherql: no Brother QL printer found")
	ErrInvalidSerial   = errors.New("brotherql: invalid serial number")
)

Error sentinels for predictable error matching.

View Source
var (
	Label12    = LabelType{Name: "12", WidthMM: 12, HeightMM: 0, WidthPx: 106, OffsetPx: 29}
	Label62    = LabelType{Name: "62", WidthMM: 62, HeightMM: 0, WidthPx: 696, OffsetPx: 12}
	Label62x29 = LabelType{Name: "62x29", WidthMM: 62, HeightMM: 29, WidthPx: 696, OffsetPx: 12}
)

Predefined label types supported by QL printers.

Functions

This section is empty.

Types

type Info

type Info struct {
	Serial  string // printer serial number
	Model   string // e.g. "QL-700" or "QL-710W"
	USBPath string // human-readable USB location
}

Info describes a discovered printer (returned by List, not opened).

func List

func List() ([]Info, error)

List returns all currently connected Brother QL printers without opening them. The returned Infos can be used to call OpenBySerial.

func (Info) String

func (i Info) String() string

String formats Info as a one-line human-readable description.

type LabelType

type LabelType struct {
	Name     string // identifier like "62" or "12"
	WidthMM  int    // physical width of the label media in mm
	HeightMM int    // physical height in mm; 0 indicates continuous tape
	WidthPx  int    // printable dots (brother_ql dots_printable)
	OffsetPx int    // brother_ql offset_r; left pad (dots) of the emitted raster row
}

LabelType describes a Brother label specification.

type PrintOptions

type PrintOptions struct {
	Label   LabelType // required: which label media is loaded
	Copies  int       // number of copies; 0 or 1 prints once
	AutoCut bool      // cut paper after print
	HighDPI bool      // 600 DPI mode (default 300)
}

PrintOptions configures a single print job.

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer represents an open connection to a Brother QL printer. Always Close() when done; defer is recommended.

func Open

func Open() (*Printer, error)

Open finds and opens the first connected Brother QL printer over USB. Returns ErrPrinterNotFound if none are connected.

func OpenBySerial

func OpenBySerial(serial string) (*Printer, error)

OpenBySerial opens a specific Brother QL printer by serial number. Useful when multiple printers are connected.

func (*Printer) Close

func (p *Printer) Close() error

Close releases the underlying transport.

func (*Printer) Print

func (p *Printer) Print(img image.Image, opts PrintOptions) error

Print sends an image to the printer and waits for completion. The image is resized and thresholded to fit opts.Label.

func (*Printer) Status

func (p *Printer) Status() (Status, error)

Status sends a status request to the printer and parses the response.

type Status

type Status struct {
	Ready       bool   // true if printer is ready to accept a job
	Error       string // human-readable error message; empty if no error
	MediaWidth  int    // mm
	MediaLength int    // mm; 0 indicates continuous tape
}

Status describes the printer's current state.

Directories

Path Synopsis
cmd
brotherql command
Command brotherql is a CLI for printing to Brother QL-700 label printers.
Command brotherql is a CLI for printing to Brother QL-700 label printers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL