Skip to main content

Python library for Polono P31S thermal label printer via BLE

Project description

polono-p31s

A Python library for printing labels on Polono P31S thermal printers via Bluetooth Low Energy (BLE).

Installation

pip install polono-p31s

Quick Start

As a Library

import asyncio
from polono_p31s import PolonoP31S

async def print_label():
    printer = PolonoP31S(width_mm=14, height_mm=40)
    
    # Render text to image
    img = printer.render_text("Hello World", font_size=48)
    
    # Connect and print
    if await printer.connect_ble():
        await printer.print_ble(img)
        await printer.disconnect_ble()

asyncio.run(print_label())

As a CLI Tool

# Print text
polono text "Hello World" --font-size 48

# Print QR code
polono qr "https://example.com"

# Print image
polono image logo.png

# Print barcode
polono barcode "123456789" --type code128

# Preview without printing
polono text "Test" --preview

# Scan for printers
polono scan

Features

  • BLE Communication: Connect to P31S printers via Bluetooth Low Energy
  • Text Rendering: Print text with customizable fonts, sizes, and alignment
  • QR Codes: Generate and print QR codes
  • Barcodes: Support for Code128, Code39, EAN13, and more
  • Image Printing: Print any image file
  • Preview Mode: Generate preview images without printing
  • Auto-fit: Automatically scale text to fit labels

Label Specifications

  • Default size: 14mm × 40mm with 5mm gap
  • Resolution: 203 DPI (8 dots/mm)
  • Density: Adjustable 1-15 (default: 15)

API Reference

PolonoP31S Class

class PolonoP31S:
    def __init__(
        self,
        width_mm: float = 14.0,
        height_mm: float = 40.0,
        gap_mm: float = 5.0,
        density: int = 15,
    ): ...

    # Connection
    async def connect_ble(self, address: Optional[str] = None) -> bool: ...
    async def disconnect_ble(self) -> None: ...

    # Rendering (returns PIL Image)
    def render_text(self, text: str, font_size: int = 24, ...) -> Image: ...
    def render_image(self, image_path: str) -> Image: ...
    def render_qr(self, data: str) -> Optional[Image]: ...
    def render_barcode(self, data: str, barcode_type: str = "code128") -> Optional[Image]: ...

    # Printing
    async def print_ble(self, img: Image, copies: int = 1) -> None: ...

    # Utilities
    def check_text_fit(self, text: str, font_size: int) -> dict: ...
    def find_fitting_font_size(self, text: str, max_font_size: int = 200) -> int: ...

Environment Variables

  • POLONO_ADDRESS: Default printer BLE address (skips scanning)

Dependencies

  • bleak - BLE communication
  • Pillow - Image processing
  • click - CLI framework
  • rich - Console output formatting
  • qrcode - QR code generation
  • python-barcode - Barcode generation

License

MIT License

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

polono_p31s-0.1.0.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

polono_p31s-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for polono_p31s-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2f6ccfdfec494b103ae7316d36404d4b09dc5d4908efbdfc18e483c0216d2948
MD5 ef451765ec9e43d0d827d290114cc254
BLAKE2b-256 1c38c0994250ba19d4dc275fc706aa5393c6ae12a68d037e2b83406475b2a4dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polono_p31s-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for polono_p31s-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc746d6bca78ece6be7e97c1d2b02c1673f12e08c324f1cfc3727f48ba30107b
MD5 9bbd26ef18f9eea3779f5fbd183053d7
BLAKE2b-256 85ac97d7627ff4ce620671a03839bda09987b19ddfb54f453f24ff57aed41ed6

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