Skip to main content

Python package to easily print to a printer configured on either a CUPS server or Google Cloud Print.

Project description

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;

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

ezprinting-0.3.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

ezprinting-0.3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file ezprinting-0.3.0.tar.gz.

File metadata

  • Download URL: ezprinting-0.3.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.5 Linux/5.3.0-40-generic

File hashes

Hashes for ezprinting-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d3ff68276fa306efba25ebd86382e11ee31eb4dc863f914a4f796cb62632b9f1
MD5 266e14487c386417615ddf8eb7e2024b
BLAKE2b-256 bd82f40cc5c5af7cff4bf553d357dc24bb2168ac28c283a4e3fcc60601f30098

See more details on using hashes here.

File details

Details for the file ezprinting-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ezprinting-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.5 Linux/5.3.0-40-generic

File hashes

Hashes for ezprinting-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db5060526e237ca348dbafa8afc46209065987f90ea65e2b30eb16f52b99b21c
MD5 4ab055d2cf2f7517ac98babddf586a9c
BLAKE2b-256 4beb658e1b30375f67762e4712c3bde49ce685c2c870374d04a0310bc9fd9b10

See more details on using hashes here.

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