Skip to main content

A Python package for generating barcode labels and printing to various printers including Niimbot

Project description

Barcode Label Printer

A Python package for generating barcode labels from JSON configuration and printing to various printers including Niimbot thermal printers.

Features

  • Label Rendering: Generate SVG labels from JSON configuration
  • Barcode Generation: Support for EAN13, Code128 barcode formats
  • Multiple Element Types: Text, barcode, box, and picture elements
  • Printer Support:
    • Windows native printing
    • PDF printing via SumatraPDF
    • Niimbot thermal printers (USB/Bluetooth)
  • Flexible Configuration: JSON-based label configuration

Installation

pip install barcode-label-printer

Optional Dependencies

For Windows native printing:

pip install barcode-label-printer[windows]

For Bluetooth support (Niimbot):

pip install barcode-label-printer[bluetooth]

Quick Start

Generate a Label

from barcode_label_printer import LabelRenderer
import json

# Load configuration
with open("label_config.json", "r") as f:
    config = json.load(f)

# Render label to SVG
renderer = LabelRenderer()
renderer.render(config, "output_label.svg")

Print a Label

from barcode_label_printer import SvgPrinter

# Print to default printer
printer = SvgPrinter()
printer.print_svg_to_default("output_label.svg")

# Print to specific printer
printer.set_printer("HP LaserJet")
printer.print_svg("output_label.svg")

Print with Niimbot Printer

from barcode_label_printer import NiimbotPrinter

# Connect and print
printer = NiimbotPrinter(model="b21", connection_type="usb")
if printer.connect():
    printer.print_image_file("label.png", density=3)
    printer.disconnect()

Label Configuration Format

{
    "canvas": {
        "width_mm": 100,
        "height_mm": 50
    },
    "elements": [
        {
            "type": "text",
            "value": "Product Name",
            "x_mm": 5,
            "y_mm": 5,
            "font_size_pt": 12,
            "bold": true
        },
        {
            "type": "barcode",
            "barcode_type": "code128",
            "value": "123456789012",
            "x_mm": 5,
            "y_mm": 15,
            "width_mm": 80,
            "height_mm": 20,
            "write_text": false
        }
    ]
}

Supported Element Types

Text Element

  • type: "text"
  • value: Text content
  • x_mm, y_mm: Position
  • font_size_pt: Font size in points
  • bold: Boolean
  • text_color: Color (default: "black")
  • bg_color: Background color (optional)

Barcode Element

  • type: "barcode"
  • barcode_type: "ean13" or "code128"
  • value: Barcode value
  • x_mm, y_mm: Position
  • width_mm, height_mm: Size
  • write_text: Show text below barcode

Box Element

  • type: "box"
  • x_mm, y_mm: Position
  • width_mm, height_mm: Size
  • fill_color: Fill color

Picture Element

  • type: "picture"
  • svg_file: Path to SVG file (relative to config)
  • x_mm, y_mm: Position
  • width_mm, height_mm: Size (optional, maintains aspect ratio)

Supported Niimbot Models

  • B1, B18, B21, B31 (384px width)
  • D11, D110 (96px width)

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

barcode_label_printer-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

barcode_label_printer-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file barcode_label_printer-0.1.0.tar.gz.

File metadata

  • Download URL: barcode_label_printer-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for barcode_label_printer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dc03a760c6b6967b186ccc85e9df65d57f87a5243fefb1621bde28488e6110a6
MD5 3dbd414c87802a4aa2d77123bf7d7dc3
BLAKE2b-256 537d930ab87cd403f866423a6fee110cf02a8a699df3f715e17ed8d27bb3e747

See more details on using hashes here.

File details

Details for the file barcode_label_printer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for barcode_label_printer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f682c0e2727a2b820a4a6904c877db1f06f5514b7e0d4d85fc36c1b9e48f3ebe
MD5 2c70e642bc38a1903cf0b41bcef4d207
BLAKE2b-256 a3a165968751f3a08a1cee2ce8d2c10df67817572bd4da63e44baf7a8ab58b70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page