Skip to main content

Flask server that receives Grocy label requests and prints to ESC/P thermal printers

Project description

Grocy Label Printer ESC/P

A Flask server that receives Grocy label requests and prints them to ESC/P thermal printers.

CI PyPI version Docker

Features

  • Grocy Integration: Compatible with Grocy's label printing system
  • ESC/P Support: Works with ESC/P thermal printers via network
  • QR Code Generation: Automatically generates QR codes from Grocy barcodes
  • Smart Layout: QR code at top, product information below
  • Font Management: Uses Roboto Bold fonts in multiple sizes
  • Container Support: Available as Docker images for easy deployment
  • Multi-Architecture: Supports AMD64 and ARM64 architectures

Quick Start

Docker (Recommended)

docker run -d \
  --name grocy-label-printer \
  -p 5000:5000 \
  -e PRINTER_HOST=192.168.1.100 \
  -e PRINTER_PORT=9100 \
  ghcr.io/miguelangel-nubla/grocy-label-printer-escpos:latest

Python Package

pip install grocy-label-printer-escpos
grocy-label-printer-escpos

From Source

git clone https://github.com/miguelangel-nubla/grocy-label-printer-escpos.git
cd grocy-label-printer-escpos
pip install -e .
python -m grocy_label_printer_escpos.server

Configuration

Environment Variables

Variable Default Description
PRINTER_HOST 192.168.1.100 IP address of the thermal printer
PRINTER_PORT 9100 Port of the thermal printer
LABEL_WIDTH 384 Width of labels in pixels
SERVER_HOST 0.0.0.0 Server bind address
SERVER_PORT 5000 Server port

Grocy Configuration

In Grocy, configure a new label printer:

  1. Go to Manage > Label printers
  2. Add a new printer with these settings:
    • Name: ESC/P Thermal Printer
    • Type: Generic
    • URL: http://your-server:5000/print
    • HTTP Method: POST

API Endpoints

POST /print

Print a label from Grocy data.

Request Body: Grocy label data (JSON or form-encoded)

Response:

  • 200 OK - Label printed successfully
  • 400 Bad Request - Invalid or missing data
  • 500 Internal Server Error - Print failed

GET|POST /image

Preview label image without printing.

Parameters: Same as /print

Response: PNG image of the label

GET /test

Print a test label with sample data.

Response:

{"status": "success", "message": "Test label printed"}

GET /

Server status and configuration.

Response:

{
  "status": "running",
  "printer": "192.168.1.100:9001",
  "service": "Grocy Thermal Label Server"
}

Label Format

Labels include:

  • QR Code: Generated from Grocy barcode (top, centered)
  • Product Name: Large bold font (centered)
  • Amount & Unit: Medium font (if available)
  • Best Before Date: Medium font (if available)
  • Purchase Date: Medium font (if available)

Special handling:

  • Long product names are automatically split across lines
  • Container weight items exclude amount/date information
  • Proper singular/plural unit names

Printer Compatibility

Tested with:

  • Sunmi integrated 58mm thermal printers

Development

Setup

git clone https://github.com/miguelangel-nubla/grocy-label-printer-escpos.git
cd grocy-label-printer-escpos
pip install -e ".[dev]"
pre-commit install

Testing

pytest

Code Quality

black src/ tests/
isort src/ tests/
flake8 src/ tests/
mypy src/

Building

python -m build

Deployment

Docker Compose

version: '3.8'
services:
  grocy-label-printer:
    image: ghcr.io/miguelangel-nubla/grocy-label-printer-escpos:latest
    ports:
      - "5000:5000"
    environment:
      - PRINTER_HOST=192.168.1.100
      - PRINTER_PORT=9100
    restart: unless-stopped

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grocy-label-printer
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grocy-label-printer
  template:
    metadata:
      labels:
        app: grocy-label-printer
    spec:
      containers:
      - name: grocy-label-printer
        image: ghcr.io/miguelangel-nubla/grocy-label-printer-escpos:latest
        ports:
        - containerPort: 5000
        env:
        - name: PRINTER_HOST
          value: "192.168.1.100"
        - name: PRINTER_PORT
          value: "9100"
---
apiVersion: v1
kind: Service
metadata:
  name: grocy-label-printer
spec:
  selector:
    app: grocy-label-printer
  ports:
  - port: 5000
    targetPort: 5000

Troubleshooting

Printer Connection Issues

  1. Check network connectivity:

    telnet 192.168.1.100 9100
    
  2. Verify printer profile: Some printers may need different profiles. Try:

    • TM-T20
    • Generic
    • TM-T88III
  3. Check printer logs:

    docker logs grocy-label-printer
    

Label Not Printing

  1. Test with sample data:

    curl http://localhost:5000/test
    
  2. Check Grocy data format:

    curl -X POST http://localhost:5000/image \
      -H "Content-Type: application/json" \
      -d '{"product": "Test", "grocycode": "123"}'
    
  3. Verify printer buffer: Ensure the printer connection is properly closed after each print job.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Run the test suite
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Releases

See GitHub Releases for version history and changes.

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

grocy_label_printer_escpos-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

grocy_label_printer_escpos-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for grocy_label_printer_escpos-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f66b95875b2619d9a6d005068667d061432043325d982e06d382a3262b686ef8
MD5 6fea0188d70fb619270c6213592d6729
BLAKE2b-256 820d135108b1355cdd471244555e6fa51685320c57df8335957725b02fde4a15

See more details on using hashes here.

Provenance

The following attestation bundles were made for grocy_label_printer_escpos-0.1.0.tar.gz:

Publisher: release.yml on miguelangel-nubla/grocy-label-printer-escpos

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

File details

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

File metadata

File hashes

Hashes for grocy_label_printer_escpos-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d753b6be82e7fd549947b08639d55c8d1a0113207b7800bdf97c86ecf1833c2
MD5 713b58d67795745d7dae9914717ebaa0
BLAKE2b-256 4fbd5dda7e453873a2237561a44f421a98b6a8843e5acdc50a8f7a3c49c88030

See more details on using hashes here.

Provenance

The following attestation bundles were made for grocy_label_printer_escpos-0.1.0-py3-none-any.whl:

Publisher: release.yml on miguelangel-nubla/grocy-label-printer-escpos

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