Printer implementations
Module escpos.printer
printer implementations.
- class escpos.printer.Usb(idVendor=None, idProduct=None, usb_args={}, timeout=0, in_ep=130, out_ep=1, *args, **kwargs)[source]
Bases:
Escpos
USB printer.
This class describes a printer that natively speaks USB.
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- class escpos.printer.File(devfile='', auto_flush=True, *args, **kwargs)[source]
Bases:
Escpos
Generic file printer.
This class is used for parallel port printer or other printers that are directly attached to the filesystem. Note that you should stay away from using USB-to-Parallel-Adapter since they are unreliable and produce arbitrary errors.
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- class escpos.printer.Network(host='', port=9100, timeout=60, *args, **kwargs)[source]
Bases:
Escpos
Network printer.
This class is used to attach to a networked printer. You can also use this in order to attach to a printer that is forwarded with
socat
.If you have a local printer on parallel port
/dev/usb/lp0
then you could startsocat
with:socat -u TCP4-LISTEN:4242,reuseaddr,fork OPEN:/dev/usb/lp0
Then you should be able to attach to port
4242
with this class. Otherwise the normal use case would be to have a printer with Ethernet interface. This type of printer should work the same with this class. For the address of the printer check its manuals.inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- class escpos.printer.Serial(devfile='', baudrate=9600, bytesize=8, timeout=1, parity=None, stopbits=None, xonxoff=False, dsrdtr=True, *args, **kwargs)[source]
Bases:
Escpos
Serial printer.
This class describes a printer that is connected by serial interface.
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- class escpos.printer.LP(printer_name='', *args, **kwargs)[source]
Bases:
Escpos
Simple UNIX lp command raw printing.
Thanks to Oyami-Srk comment.
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- property printers: dict
Available CUPS printers.
- open(job_name='python-escpos', raise_not_found=True, _close_opened=True)[source]
Invoke _lp_ in a new subprocess and wait for commands.
By default raise an exception if device is not found.
- Parameters:
raise_not_found (
bool
) – Default True. False to log error but do not raise exception.- Raises:
- Return type:
None
- class escpos.printer.Dummy(*args, **kwargs)[source]
Bases:
Escpos
Dummy printer.
This class is used for saving commands to a variable, for use in situations where there is no need to send commands to an actual printer. This includes generating print jobs for later use, or testing output.
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- property output: bytes
Get the data that was sent to this printer.
- class escpos.printer.CupsPrinter(printer_name='', *args, **kwargs)[source]
Bases:
Escpos
Simple CUPS printer connector.
Note
- Requires
pycups
which in turn needs the cups development library package: Ubuntu/Debian:
libcups2-dev
OpenSuse/Fedora:
cups-devel
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- property printers: dict
Available CUPS printers.
- open(job_name='python-escpos', raise_not_found=True)[source]
Set up a new print job and target the printer.
A call to this method is required to send new jobs to the CUPS connection after close.
Defaults to default CUPS printer. Creates a new temporary file buffer.
By default raise an exception if device is not found.
- Parameters:
raise_not_found (
bool
) – Default True. False to log error but do not raise exception.- Raises:
- Return type:
None
- Requires
- class escpos.printer.Win32Raw(printer_name='', *args, **kwargs)[source]
Bases:
Escpos
Printer binding for win32 API.
Uses the module pywin32 for printing.
inheritance:
- static is_usable()[source]
Indicate whether this printer class is usable.
Will return True if dependencies are available. Will return False if not.
- Return type:
bool
- property printers: dict
Available Windows printers.