Printing Via LPR

If you have a Python app, or almost any kind of app, the accepted manner for printing is to use some kind of subprocess to invoke some command-line utility to submit the print job.  Of course this requires that the underlying subsystems are aware of printers [and thus run a printer subsystem].  It also assumes the name of the command-line utility, the permissions are adequate to execute it, and all manner of other things.  To put it simply: this is terrible!  Why does my web server, workflow server, etc... need to run a print service?  Why can't my environment just support submitting a job to an actual print server?  Good question!  To answer this OpenGroupware Coils now has a simple implementation of the LPR/LPD protocol.  This code is under the MIT/X11 license so you are free to copy-and-paste it into your own application.  Sending a job to the server is as simple as:

f = open('Draft.ps', 'rb')
pr = LPR('crew.mormail.com', user='adam')
lpr.send_stream('cisps', 'test job', f, job_name='my awesome job')

This sends the contents of the file "Draft.ps" to the printer "cisps" on the LPD server "crew.mormail.com" with user name "adam", job name "my awesome job" and job file name "test job".

The code for the LPR class can be found here.


  1. If you are using the OpenGroupware OIE workflow engine this functionality is available via the new "printToLPR" action.

  2. Native support for printing means that if the application cannot connect to the print server, the print server rejects the job, etc... you get an exception! Using the clunky old subprocess technique maybe you know that submitting the job failed but you have no idea why,

  3. This is great. I am new to this blog commenting and not sure why I havent done this before. This blog is awsome, very informative and straight to the point. Great job!!!
    Contract manufacturing

  4. Replies
    1. Since the BLOG post the printing related files have moved to an API module which contains a collection of third-party bits which are collected into the code base. Take a look at https://sourceforge.net/p/coils/code/ci/default/tree/coils/foundation/api/printing/

    2. Thank you very much. It is exactly that I was needing.

  5. This comment has been removed by the author.