Skip to main content

ESC/POS receipt printing library in pure Python

Project description

escpos-python

A pure Python 3 library for printing ESC/POS receipts, barcodes, and QR codes directly via the operating system print spooler.
Works on macOS, Linux, and Windows using lp or print system commands.


🚀 Features

✅ ESC/POS command generation
✅ Text formatting (bold, underline, alignments, double width/height)
✅ Barcodes (EAN13, Code128, and more)
✅ QR codes (size, error correction)
✅ Cross-platform printing (no C extensions)
✅ Mock printer for testing


📦 Installation

pip install escpos-python

Or build from source using flit or twine


🖨️ Usage Example

from escpos import (
    POSPrinter,
    POSReceiptBuilder,
    POSTextBuilder,
    POSPrintStyle,
    POSTextAlignment,
    POSBarcodeBuilder,
    POSBarcodeType,
    POSQRCodeBuilder,
    POSQRCodeSize,
    POSQRCodeErrorCorrection
)

printer = POSPrinter("Your_Printer_Name")

receipt = (
    POSReceiptBuilder()
    .set_title("ESC/POS PYTHON DEMO")
    .add_component(POSTextBuilder("Left").set_alignment(POSTextAlignment.LEFT).build())
    .add_component(POSTextBuilder("Center").set_alignment(POSTextAlignment.CENTER).build())
    .add_component(POSTextBuilder("Right").set_alignment(POSTextAlignment.RIGHT).build())
    .add_component(POSTextBuilder("Bold").set_style(POSPrintStyle.BOLD).build())
    .add_component(POSTextBuilder("Underlined").set_style(POSPrintStyle.UNDERLINE).build())
    .add_item("Item A", 3.5)
    .add_item("Item B", 5.0)
    .add_component(
        POSBarcodeBuilder("123456789012")
        .set_type(POSBarcodeType.JAN13_EAN13)
        .build()
    )
    .add_component(
        POSQRCodeBuilder("https://example.com")
        .set_size(POSQRCodeSize.LARGE)
        .set_error_correction(POSQRCodeErrorCorrection.HIGH)
        .build()
    )
    .set_footer("Thank you!")
    .build()
)

printer.print(receipt)

🖨️ How to Find Printer Names

macOS / Linux

lpstat -p

Windows (PowerShell)

Get-Printer | Select Name

🧪 Testing with a Mock Printer

from escpos import POSPrinterMock, POSReceiptBuilder, POSTextBuilder

mock = POSPrinterMock()
receipt = (
    POSReceiptBuilder()
    .set_title("Test Receipt")
    .add_component(POSTextBuilder("Line 1").build())
    .build()
)

mock.print(receipt)
print("Printed buffers:", len(mock.get_printed_data()))

📣 Feature Request?

This repository is only for bug reports and maintenance related to the language-specific implementation.

Please open all feature requests, enhancements, and cross-language discussions in the central repository:

👉 DrBackmischung/ESCPOS


📜 License

MIT

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

escpos_python-1.0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

escpos_python-1.0.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file escpos_python-1.0.2.tar.gz.

File metadata

  • Download URL: escpos_python-1.0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for escpos_python-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7a1b3ca11d57e6cba0d3ce4828fc9a6a01cbb094294486d0c9b52e6ab3dc4f04
MD5 de585f557c6594a428352210d4d72860
BLAKE2b-256 8beffcacb28a363af2cc84d6b22053da2d7ed49b06d3afa8c2aee834e5079898

See more details on using hashes here.

Provenance

The following attestation bundles were made for escpos_python-1.0.2.tar.gz:

Publisher: python-publish.yml on DrBackmischung/ESCPOS-Python

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

File details

Details for the file escpos_python-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: escpos_python-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for escpos_python-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c27f30637c4044211934c7cb75b785911096cd910181210942483c9ffda854b6
MD5 dad6703c89a4a50447422ac27e2131dc
BLAKE2b-256 65007e8718af60972fe44aa2341943682da388c368caa1d24d07a54de98085cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for escpos_python-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on DrBackmischung/ESCPOS-Python

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