Skip to main content

Python SDK for Star TSP100 Graphic Mode thermal printers

Project description

py-star-tsp

Python SDK for Star thermal printers operating in Graphic Mode over USB.

Following the STAR Graphic Mode Command Specifications Rev. 2.31.

AI Generated, poorly reviewed, and hardly supervised.

Supported Models

Model Interface Tested
TSP100U USB -
TSP100PU USB + Parallel -
TSP100GT USB + Ethernet -
TSP100LAN Ethernet -
TSP100IIU USB Y
TSP100IIIW USB + Wi-Fi -
TSP100IIILAN USB + Ethernet -
TSP100IIIBI USB + Bluetooth -
TSP100IIIU USB -

Installation

pip install py-star-tsp

Usage example

import datetime
import py_star_tsp

with py_star_tsp.StarTSP100() as printer:
    # Changing print speed to slow
    printer.print_speed = 2

    # Changing print quality to high
    printer.raster_print_quality = 2

    # Device discovery
    printer.find_device()

    # Preparing timestamp label
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Preparing content
    title = "Before Flying Circus"
    paragraph = """Jones and Palin met at Oxford University, where they performed togethe
r with the Oxford Revue. Chapman and Cleese met at Cambridge Universit
y. Idle was also at Cambridge, but started a year after Chapman and Cl
eese. Cleese met Gilliam in New York City while on tour with the Cambr
idge University Footlights revue Cambridge Circus (originally entitled
 A Clump of Plinths). Chapman, Cleese, and Idle were members of the Fo
otlights, which at that time also included the future Goodies (Tim Bro
oke-Taylor, Bill Oddie, and Graeme Garden), and Jonathan Lynn (co-writ
er of Yes Minister and Yes, Prime Minister).[12] During Idle's preside
ncy of the club, feminist writer Germaine Greer and broadcaster Clive 
James were members. Recordings of Footlights' revues (called "Smokers"
) at Pembroke College include sketches and performances by Cleese and 
Idle, which, along with tapes of Idle's performances in some of the dr
ama society's theatrical productions, are kept in the archives of the 
Pembroke Players.
    """

    # Adding content to the printing "queue"
    printer.add_text(timestamp, font_size=30, invert=True)
    printer.add_bar(width=0, height=15)
    printer.add_image(py_star_tsp.KITTENS_SPINNING)
    printer.add_bar(width=0, height=15)
    printer.add_text(title, font_size=50)
    printer.add_bar(width=0, height=15)
    printer.add_text(paragraph, font_size=20)
    printer.add_image(py_star_tsp.KITTENS_SPINNING, invert=True)

    # Exporting a preview
    printer.save_rendered("/tmp/rendered_example.bmp")

    # Printing out
    printer.print()

Linux USB Access (udev rule)

By default, USB devices are accessible only to root. Add the following udev rule to grant access to all users in the plugdev group:

# /etc/udev/rules.d/99-star-tsp100.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="0519", MODE="0666", GROUP="plugdev"

Reload rules and reconnect the printer:

sudo udevadm control --reload-rules
sudo udevadm trigger

Add your user to the plugdev group if necessary:

sudo usermod -aG plugdev $USER

Font Discovery and Fallback

The text renderer automatically scans standard OS directories for .ttf and .otf fonts:

OS Search paths
Linux /usr/share/fonts, /usr/local/share/fonts, ~/.local/share/fonts, ~/.fonts
macOS /System/Library/Fonts, /Library/Fonts, ~/Library/Fonts
Windows %WINDIR%\Fonts

You can also set the FONTPATH environment variable to add custom directories (separated by os.pathsep).

Fallback font order

When no specific font is requested, the following are tried in order:

  1. DejaVu Sans Mono
  2. Liberation Mono
  3. FreeMono
  4. Arial
  5. Consolas
  6. Courier New

If no TrueType/OpenType fonts are found at all, Pillow's built-in bitmap font is used. This bitmap font does not support sizing, bold, italic, or underline — a warning is logged.

Font source packages

Install these Python/system packages to ensure fonts are available:

  • matplotlib — ships DejaVu Sans / DejaVu Sans Mono
  • fonttools — useful for font metadata inspection
  • fonts-dejavu (Debian/Ubuntu) / dejavu-sans-mono-fonts (Fedora/Rocky) — DejaVu family
  • fonts-liberation (Debian/Ubuntu) / liberation-mono-fonts (Fedora/Rocky) — Liberation family

Midtones / Grayscale (Dithering)

TBD

Preview / Export

You can save the queued raster output to an image file before sending it to the printer.

from py_star_tsp import StarTSP

printer = StarTSP()
printer.add_text("Preview me")
printer.add_bar(width=576, height=8)

printer.save_rendered("preview.bmp")
printer.save_rendered("preview.jpg", quality=95)

image = printer.render_image()
print(image.size)

Use BMP if you want an exact 1-bit preview of what will be sent to the printer. JPEG is supported too, but it is exported as grayscale because JPEG does not support 1-bit images.

ESC/POS Compatibility

TBD

Specification Reference

Commands are implemented from the STAR Graphic Mode Command Specifications Rev. 2.31 (star_graphic_cm_en.pdf).

Licensing

  • Kitten in the demos by Deni Sudibyo

TODO

  • 2d code implementation (barcode, qr, etc)
  • Python version compatibility
  • ESC/POS compatibility (very long term)
  • Usage with external rendering (just printing ready to use raster)
  • Turn demo to a reference sheet
  • Generate a preview of what's rendered to be printed

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

py_star_tsp-1.1.0.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

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

py_star_tsp-1.1.0-py3-none-any.whl (49.4 kB view details)

Uploaded Python 3

File details

Details for the file py_star_tsp-1.1.0.tar.gz.

File metadata

  • Download URL: py_star_tsp-1.1.0.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_star_tsp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0f903ee0736e5ca39233d057bf666dc1c06e420bc935c68d6cbff75c1777fbee
MD5 69d5dacf07b1d71d360c3ab7d37fa821
BLAKE2b-256 747cb1042f7209b19b112289d39225f594532d4ce163f0a7e3004dd7f0b7ec95

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_star_tsp-1.1.0.tar.gz:

Publisher: release.yml on printer-stream/py-star-tsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_star_tsp-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_star_tsp-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_star_tsp-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76a0217fe199a9c91ef8c723049d796e45416e56510b0a261c0d96a60813db56
MD5 5a9c620a88887dbe1fa7ca899cd04328
BLAKE2b-256 9e5f7f5ab5004ad2b3ac136def461091bd6c98f2c41cede13af2c45ea8a11d38

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_star_tsp-1.1.0-py3-none-any.whl:

Publisher: release.yml on printer-stream/py-star-tsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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