Skip to main content

ezprinting

IMPORTANT NOTE!

As of version 0.3, support for GCP has been removed (Google announced that Google Cloud Print service will be discontinued at the end of 2020).

Description

Python package to easily submit print jobs to a printer configured on a CUPS server.

Installation

pip install ezprinting or poetry add ezpriting

pyCups is a dependency which needs libcups2-dev (this is the name on Ubuntu/Debian) to be installed (sudo apt install libcups2-dev).

Quick Start Guide

Note: success=True/False in the examples below indicate whether or not the print job was successfully submitted to CUPS, not that it was successfully printed.

1. Option one:

from ezprinting import PrintJob


with open('dummy.pdf', 'rb') as f:
    content = f.read()

# Use host="cups.domain.tld:631", username="lpadmin", password="123456" to specify
# a remote cups server with authentication.
# By default "localhost:631" is assumed with blank user/passwd
pjob = PrintJob.new_cups(printer_name='cups-printer-name', content=content)
success = pjob.print()




If content is PDF, there is no need to specify content_type. Auto detection of content-type is not available yet, if you skip content_type than "application/pdf" is assumed.

2. Option two:

from ezprinting import PrintServer, Printer, PrintJob
import json

with open('dummy.pdf', 'rb') as f:
    content = f.read()

# If we want CUPS on localhost...
print_server = PrintServer.cups()
# If we want remote CUPS server...
print_server = PrintServer.cups(host="cups.domain.tld:631", username="lpadmin", password="123456")

connection_ok, message = print_server.test_connection()
print("Testing connection: {} - {}".format(connection_ok, message))

# Let's check what printers we have available
if connection_ok:
    printers = print_server.get_printers()
    print(json.dumps(printers, sort_keys=True, indent=4))
    printer = Printer(print_server, 'printer name (CUPS) or printer ID (GCP)')
    printer_exists = printer.check_printer_exists() 
    print("Does the printer exist on that print server? {}".format(printer_exists))
    if printer_exists:
        pjob = PrintJob(printer=printer, content=content)
        success = pjob.print()
        print('Print job submitted with success? {}'.format(success))
        if success:
            print('Print job id: {}'.format(pjob.job_id))

Testing

You can easily test the functionality of this package by making use of the built in test code.

To test CUPS functionality you must have a valid tests/private_data/cups.json.

To define the documents you want to test print and the printers where those documents should be test printed you must have the files:

  • tests/private_data/printers.json
  • tests/data/print_tests.json

Commented sample json files are provided (do not forget to delete the comments, JSON does not support comments).

State of this package

The code in this repository is being used in production and mostly works. However, it is very new and does not handle well exceptional cases. A large piece that is still missing is functionality on the PrintJob class to track the lifecycle of a print job and being able to figure out what went wrong when something goes wrong (e.g. paper jam, out of paper, out of ink, etc). Your help is welcome to fill in the gaps. And please, do file bug reports.

Main TO-DOs

  • Develop functionality on the PrintJob class to track the state of a print job and identify causes of failure (e.g. jam, out of paper, out of ink, etc)
  • Enable printing directly to IPP printers;
  • Add-on: mqtt monitor to send print jobs received on mqtt topics, with full QoS implementation;

Feel free to help fill-in the gaps!

Other notes

  • pycups <=1.9.73 has a bug that prevents CUPS from working. You will see a filter failed or some kind of "document corrupted" message;

Metadata

Release files for ezprinting 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ezprinting 0.3.0
File Size Uploaded
ezprinting-0.3.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ezprinting 0.3.0
File Interpreter ABI Platform
ezprinting-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / ezprinting-0.3.0.tar.gz

Download URL ezprinting-0.3.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d3ff68276fa306efba25ebd86382e11ee31eb4dc863f914a4f796cb62632b9f1
BLAKE2b-256 checksum
How to use checksums
bd82f40cc5c5af7cff4bf553d357dc24bb2168ac28c283a4e3fcc60601f30098
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.5 Linux/5.3.0-40-generic

Release files / ezprinting-0.3.0-py3-none-any.whl

Download URL ezprinting-0.3.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db5060526e237ca348dbafa8afc46209065987f90ea65e2b30eb16f52b99b21c
BLAKE2b-256 checksum
How to use checksums
4beb658e1b30375f67762e4712c3bde49ce685c2c870374d04a0310bc9fd9b10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.7.5 Linux/5.3.0-40-generic

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page