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.
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:
- Go to Manage > Label printers
- 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 successfully400 Bad Request- Invalid or missing data500 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
-
Check network connectivity:
telnet 192.168.1.100 9100
-
Verify printer profile: Some printers may need different profiles. Try:
TM-T20GenericTM-T88III
-
Check printer logs:
docker logs grocy-label-printer
Label Not Printing
-
Test with sample data:
curl http://localhost:5000/test -
Check Grocy data format:
curl -X POST http://localhost:5000/image \ -H "Content-Type: application/json" \ -d '{"product": "Test", "grocycode": "123"}'
-
Verify printer buffer: Ensure the printer connection is properly closed after each print job.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run the test suite
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grocy_label_printer_escpos-0.1.0.tar.gz.
File metadata
- Download URL: grocy_label_printer_escpos-0.1.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f66b95875b2619d9a6d005068667d061432043325d982e06d382a3262b686ef8
|
|
| MD5 |
6fea0188d70fb619270c6213592d6729
|
|
| BLAKE2b-256 |
820d135108b1355cdd471244555e6fa51685320c57df8335957725b02fde4a15
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grocy_label_printer_escpos-0.1.0.tar.gz -
Subject digest:
f66b95875b2619d9a6d005068667d061432043325d982e06d382a3262b686ef8 - Sigstore transparency entry: 584058804
- Sigstore integration time:
-
Permalink:
miguelangel-nubla/grocy-label-printer-escpos@5444f95be50666634231e1faf6f8a6863c7cf87a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/miguelangel-nubla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5444f95be50666634231e1faf6f8a6863c7cf87a -
Trigger Event:
push
-
Statement type:
File details
Details for the file grocy_label_printer_escpos-0.1.0-py3-none-any.whl.
File metadata
- Download URL: grocy_label_printer_escpos-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d753b6be82e7fd549947b08639d55c8d1a0113207b7800bdf97c86ecf1833c2
|
|
| MD5 |
713b58d67795745d7dae9914717ebaa0
|
|
| BLAKE2b-256 |
4fbd5dda7e453873a2237561a44f421a98b6a8843e5acdc50a8f7a3c49c88030
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grocy_label_printer_escpos-0.1.0-py3-none-any.whl -
Subject digest:
2d753b6be82e7fd549947b08639d55c8d1a0113207b7800bdf97c86ecf1833c2 - Sigstore transparency entry: 584058807
- Sigstore integration time:
-
Permalink:
miguelangel-nubla/grocy-label-printer-escpos@5444f95be50666634231e1faf6f8a6863c7cf87a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/miguelangel-nubla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5444f95be50666634231e1faf6f8a6863c7cf87a -
Trigger Event:
push
-
Statement type: