PyCUPS - Python CUPS Bindings

2.0.4 · active · verified Thu Apr 16

PyCUPS provides Python bindings for libcups, the Common Unix Printing System library. It allows Python applications to interact with CUPS servers to manage printers, print jobs, and monitor printer status. The current version is 2.0.4, with releases primarily focusing on bug fixes and compatibility with newer Python versions, rather than new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to the local CUPS server and list all configured printers. It's a common first step to verify PyCUPS installation and CUPS server connectivity.

import cups

# Connect to the local CUPS server
conn = cups.Connection()

# List all available printers
printers = conn.getPrinters()

if printers:
    print("Available Printers:")
    for printer_name, printer_attrs in printers.items():
        print(f"  - {printer_name}")
        # print(f"    Location: {printer_attrs.get('printer-location')}")
        # print(f"    State: {printer_attrs.get('printer-state-message')}")
else:
    print("No printers found or CUPS server is not accessible.")

# Example: Get default printer (if set)
default_printer = conn.getDefault() # Returns string or None
if default_printer:
    print(f"\nDefault Printer: {default_printer}")

view raw JSON →