Personal tools
You are here: Home Software pkipplib
Document Actions

pkipplib's HomePage

by Jerome Alet last modified 2006-06-24 18:07

This document describes the pkipplib Python library.

Introduction :

pkipplib is a Python library which can prepare IPP requests with the help of a somewhat high level API. These requests can then be sent to an IPP printer or print server (e.g. CUPS).
This library can also parse IPP answers received, and create high level Python objects from them.
Both of these actions can be done through an IPPRequest class and its instance methods.
Finally, a CUPS class can be leveraged to easily deal with CUPS print servers. All of this library being written in the Python language, there's no need to link the code with the CUPS' API, which makes it independant of the CUPS version being installed. Some command line tools which rely on pkipplib are now included.

Installation :

See http://www.pykota.com/software/pkipplib/download for details on how to obtain and install pkipplib.

Examples :

Parsing :

# Parsing.py    EXAMPLE
from pkipplib import pkipplib

# Read IPP datas from a CUPS job control file
myfile = open("/var/spool/cups/c00155")
ippdatas = myfile.read()
myfile.close()

# Parse these datas
request = pkipplib.IPPRequest(ippdatas)
request.parse()

# Print the whole result as a string
print request

# Access one of the job's attributes directly
print request.job["job-name"]

Creating :

# Building.py   EXAMPLE
from pkipplib import pkipplib

# Create a CUPS_GET_DEFAULT request
request = pkipplib.IPPRequest(operation_id=pkipplib.CUPS_GET_DEFAULT)
request.operation["attributes-charset"] = ("charset", "utf-8")
request.operation["attributes-natural-language"] = ("naturalLanguage", "en-us")

# Get the request as binary datas
ippdatas = request.dump()

# Parse these datas back
newrequest = pkipplib.IPPRequest(ippdatas)
newrequest.parse()

# Of course, the result of parsing matches what we created before.
print newrequest.operation["attributes-natural-language"]

CUPS' API :

# CUPS' API
from pkipplib import pkipplib

# Create a CUPS client instance
# cups = pkipplib.CUPS(url="http://server:631, \
# username="john", \
# password="5.%!oyu")
cups = pkipplib.CUPS()

# High level API : retrieve info about job 3 :
answer = cups.getJobAttributes(3)
print answer.job["document-format"]
# That's all folks !

# Lower level API :
request = cups.newRequest(pkipplib.IPP_GET_PRINTER_ATTRIBUTES)
request.operation["printer-uri"] = ("uri",
cups.identifierToURI("printers", "HP2100"))
for attribute in ("printer-uri-supported",
"printer-type",
"member-uris") :
# IMPORTANT : here, despite the unusual syntax, we append to
# the list of requested attributes :
request.operation["requested-attributes"] = ("nameWithoutLanguage", attribute)

# Sends this request to the CUPS server
answer = cups.doRequest(request)

# Print the answer as a string of text
print answer

Command line tools :

pkipplib currently includes the following command line tools :

  • pksubscribe : can create or delete IPP subscriptions. See pksubscribe --help for details. examples :

$ pksubscribe --cups http://localhost:631 \
--events printer-added,printer-deleted \
 --recipient mynotifier \
 --duration 0

$ pksubscribe --username root \
--password HacKMe \
--delete 34 58 98
  • samplenotifier : can handle printer-added and printer-deleted notifications and automatically create or remove printers from PyKota's database (just adapt the code for other needs). samplenotifier is present in the notifiers/ directory, but won't be installed automatically.

In the future more command line tools will be included.


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: