This page is about the Python bindings for the CUPS API, known as pycups. It was written for use with system-config-printer, but can be put to other uses as well.


Download tarball releases from the Python Package Index:

or older releases from:

Source Code

The git repository is available at GitHub.

Bug Reporting

Report issues using GitHub.

86 Responses to “pycups”

  1. Michael says:

    The package doesn’t build properly on fc10
    Here is the output from build:
    python build
    running build
    running build_ext
    building ‘cups’ extension
    creating build
    creating build/temp.linux-i686-2.6
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DVERSION=”1.9.54″ -I/usr/local/include/python2.6 -c cupsmodule.c -o build/temp.linux-i686-2.6/cupsmodule.o
    cupsmodule.c: In function ‘do_password_callback’:
    cupsmodule.c:155: error: ‘cups_password_callback’ undeclared (first use in this function)
    cupsmodule.c:155: error: (Each undeclared identifier is reported only once
    cupsmodule.c:155: error: for each function it appears in.)
    cupsmodule.c: In function ‘cups_setPasswordCB’:
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:343: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    error: command ‘gcc’ failed with exit status 1
    make: *** [] Error 1

  2. tim says:

    Fixed upstream (add “tls->” just before “cups_password_callback” at cupsmodule.c:155).

    However, be aware that Fedora 10 is no longer receiving security updates — you should upgrade to a newer version of Fedora.

  3. Michael says:

    Hm, it fixed the first error.
    The others are still there :
    namely the whole
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:342: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’
    cupsmodule.c:343: error: ‘struct TLS’ has no member named ‘cups_password_callback_context’

  4. Michael says:

    Could it be due to the fact that I have cups 1.31 and not 1.4 ?

  5. Michael says:

    Ok I removed the 2 lines referring to the cups_password_callback_context and was able to compile.
    Now there is another problem when trying to run some package using pycups (namely cloudprint).
    ImportError: /usr/local/lib/python2.6/site-packages/ undefined symbol: cupsGetPPD3
    It is most likely due to the fact that I have cups 1.31 .
    Any way to force the build so it uses 1.31 ?

  6. tim says:

    Both problems also fixed in the git repository now.

  7. Michael says:

    Actually I fixed them myself in the code and recompiled 🙂
    I also had a problem with getPPD3 and have to comment out the appropriate functions as well.
    Anyway it works fine now with the cloudprint.

  8. Rogier says:

    I am also getting this ImportError when starting the python cloudprint script:

    ImportError: /usr/local/lib/python2.6/site-packages/ undefined symbol: cupsGetPPD3

    Can you point me in the direction where to comment out the appropriate functions so this error will not occur?

    My OS is Ubuntu 8.04 server with python 2.6 and pycups-1.9.55 installed.


  9. tim says:

    Rogier: you need a newer version of cups or else wait for pycups-1.9.56 which will work around compiling against older versions.

  10. macaronij says:

    very good work, it could be very helpfull to have an intro / tutorial whit the basic
    something very easy just to start using the module

    #Connect to CUPS whit the default user
    printer = cups.Connection()

    #Define the default printer name
    default_printer = printer.getDefault()

    #Print a Test Page in the default printer

    #Print a file whit the default options

    perhaps some example adding a printer, etc…

    i know it s very noob but it can save some time to a lot of people, i dind’t find any tutorial on the web and didn t know if this module could do the stuff i need until i build it and ask help(cups)…

  11. tim says:

    Yes, good idea. Or maybe I should make it a bit more like pysmbc and have the full documentation online.

  12. mrbox says:

    Great lib! After some problems everything works like a charm 🙂

  13. Gowtham says:

    Hi Tim,

    Thanks for releasing this py binding library. Made my development time much shorter and I didn’t have to put in a lot of effort to write using C library.

    I could accomplish most of my tasks using pycups library. However, there is one API component which is available in C library but not exposed through pycups library, i.e cupsAdminExportSamba.

    I managed to write the PyObject method to extend pycups library for this API call. But, the major constraint is that this call relies on cups-windows drivers to be available on the local machine alongside with libcups. Now, I am not sure how this fits into the pycups library when there is an additional dependency. Perhaps, you have better idea.

  14. tim says:

    It just needs to behave the same as the libcups function would.

  15. Gowtham says:

    One (rather ignorant) question, How do I send you a pull request(like github) for you to check the changes I have made?

  16. tim says:

    Just let me know the URL to your git repository and I can take a look.

  17. tim says:

    Thanks. One comment:

    +  char str[80];
          fgets (str, 79, tf);

    That would be better as:

          fgets (str, sizeof (str), tf);

    and perhaps a comment explaining what that file is expected to look like and why the last line is relevant in this situation.

    (Note that fgets already leaves space for, and stores, a terminating nul character.)

  18. Gowtham says:

    Thanks for looking into it. Took some time to come back to this, blame on holiday time.

    Heres my commit with changes as per your suggestions-

  19. tim says:

    Thanks. Some warnings when building though:

    upsconnection.c: In function ‘Connection_adminExportSamba’:
    cupsconnection.c:3808:13: warning: ignoring return value of ‘fgets’, declared with
    attribute warn_unused_result [-Wunused-result]

    Should really check this.

    cupsconnection.c:3817:8: warning: attempt to free a non-heap object ‘str’ [enabled by default]

    I didn’t spot this when looking through first of all, but str is declared on the stack so we don’t need to free it.

    When I import your git repository it has a separate history of its own instead of branching from mine… isn’t it meant to share a common ancestor?

Leave a reply

Comments are moderated. Comments that are inappropriate, offensive, vulgar, badly written or insulting will be deleted or edited to make the author look silly.