You can use win32print
module.
Please read the following documents first:
Applications that print create a printer device context (DC). When an
application creates a printer DC, the spooler performs necessary tasks
such as determining the location of the required printer driver and
then loading that driver. The print spooler also determines the data
type used to record the print job.
The print spooler supports the following data types:
- Enhanced metafile (EMF).
- ASCII text.
- Raw data, which includes printer data types such as PostScript, PCL, and custom data types.
Custom data types can be added to the spooler by installing
additional printer
drivers and print processors. A print job is a document stored
internally and encoded by using one of the supported data types, and a
print job may contain one or more pages of output.
The spooler deletes these files when the job has successfully printed.
It is indeed possible to print jobs directly without saving them as files, because the spooler will delete these files directly after printing.
Related: https://stackoverflow.com/a/14615664/11128312