cups
#
Description#
A plugin to interact with local and remote printers over a CUPS server.
Configuration#
cups:
# [Optional]
# CUPS host IP/name (default: localhost).
# host: localhost # type=str
# [Optional]
# CUPS port (default: 631).
# port: 631 # type=int
# [Optional]
# Default printer name that should be used.
# printer: # type=Optional[str]
Dependencies#
pip
pip install pycups
Alpine
apk add py3-pycups
Debian
apt install python3-cups libcups2-dev
Fedora
yum install python-cups
Arch Linux
pacman -S python-pycups
Actions#
Module reference#
- class platypush.plugins.cups.CupsPlugin(host: str = 'localhost', port: int = 631, printer: str | None = None, **kwargs)[source]#
Bases:
Plugin
A plugin to interact with local and remote printers over a CUPS server.
- __init__(host: str = 'localhost', port: int = 631, printer: str | None = None, **kwargs)[source]#
- Parameters:
host – CUPS host IP/name (default: localhost).
port – CUPS port (default: 631).
printer – Default printer name that should be used.
- accept_jobs(printer: str | None = None, host: str | None = None, port: int | None = None)[source]#
Start accepting jobs on a printer.
- Parameters:
printer – Printer name.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- add_printer(name: str, ppd_file: str, info: str, location: str | None = None, host: str | None = None, port: int | None = None)[source]#
Add a printer.
- Parameters:
name – Printer name - alphanumeric + underscore characters only.
ppd_file – Path to the PPD file with the printer information and configuration.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).info – Human-readable information about the printer.
location – Human-readable printer location info.
- add_printer_to_class(printer_class: str, printer: str | None = None, host: str | None = None, port: int | None = None)[source]#
Add a printer to a class.
- Parameters:
printer_class – Class name.
printer – Printer name.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- cancel_job(job_id: int, purge_job: bool = False, host: str | None = None, port: int | None = None)[source]#
Cancel a printer job.
- Parameters:
job_id – Job ID to cancel.
purge_job – Also remove the job from the server (default: False).
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- delete_printer(printer: str, host: str | None = None, port: int | None = None)[source]#
Delete a printer from a CUPS server.
- Parameters:
printer – Printer name.
host – CUPS server IP/name (default: default configured
host
).
- delete_printer_from_class(printer_class: str, printer: str | None = None, host: str | None = None, port: int | None = None)[source]#
Delete a printer from a class.
- Parameters:
printer_class – Class name.
printer – Printer name.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- disable_printer(printer: str | None = None, host: str | None = None, port: int | None = None)[source]#
Disable a printer on a CUPS server.
- Parameters:
printer – Printer name.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- enable_printer(printer: str | None, host: str | None = None, port: int | None = None)[source]#
Enable a printer on a CUPS server.
- Parameters:
printer – Printer name.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- finish_document(printer: str | None = None, host: str | None = None, port: int | None = None)[source]#
Finish sending a document to a printer.
- Parameters:
printer – Printer name (default: default configured
printer
).host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- get_classes(host: str | None = None, port: int | None = None) Dict[str, Dict[str, Any]] [source]#
Get the list of classes on a CUPS server.
- Parameters:
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- Returns:
dict - class_name -> class_info.
- get_jobs(host: str | None = None, port: int | None = None) Dict[int, Dict[str, Any]] [source]#
Get the list of active jobs.
- Parameters:
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- Returns:
A job_id -> job_info dict.
- get_printers(host: str | None = None, port: int | None = None) List[dict] [source]#
Get the list of printers registered on a CUPS server.
- Parameters:
host – CUPS server host IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- Returns:
[ { "info": "HP DeskJet 5820 series", "is_shared": "Whether the printer is shared.", "location": "Living Room", "make_and_model": "HP Officejet 5200 Series, hpcups 3.19.1", "name": "HP_DeskJet_5820_series_585C26", "printer_type": 2101260, "state": 3, "state_message": "Idle", "state_reasons": [ "none" ], "uri": "dnssd://HP%20DeskJet%205820%20series%20%5B585C26%5D._ipp._tcp.local/?uuid=1c852a4d-b800-1f08-abcd-705a0f585c26", "uri_supported": "ipp://localhost:631/printers/HP_OfficeJet_5230" } ]
- move_job(job_id: int, source_printer_uri: str, target_printer_uri: str, host: str | None = None, port: int | None = None)[source]#
Move a job to another printer/URI.
- Parameters:
job_id – Job ID to cancel.
source_printer_uri – Source printer URI.
target_printer_uri – Target printer URI.
host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- print_file(filename: str, printer: str | None = None, host: str | None = None, port: int | None = None, title: str | None = None, options: Dict[str, Any] | None = None) dict [source]#
Print a file.
- Parameters:
filename – Path to the file to print.
printer – Printer name (default: default configured
printer
).host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).title – Print title.
options – Extra CUPS name->value options.
- Returns:
{ "job_id": 1, "printer": "HP_DeskJet_5820_series_585C26" }
- print_files(filenames: List[str], printer: str | None = None, host: str | None = None, port: int | None = None, title: str | None = None, options: Dict[str, Any] | None = None) dict [source]#
Print a list of files.
- Parameters:
filenames – Paths to the files to print.
printer – Printer name (default: default configured
printer
).host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).title – Print title.
options – Extra CUPS name->value options.
- Returns:
{ "job_id": 1, "printer": "HP_DeskJet_5820_series_585C26" }
- print_test_page(printer: str | None = None, host: str | None = None, port: int | None = None) dict [source]#
Print the CUPS test page.
- Parameters:
printer – Printer name (default: default configured
printer
).host – CUPS server IP/name (default: default configured
host
).port – CUPS server port (default: default configured
port
).
- Returns:
{ "job_id": 1, "printer": "HP_DeskJet_5820_series_585C26" }