Dear Dev.to!

Recently I am working on a project that need to control scanner using script.

The purpose of the script is to run the scanner with ADF(Auto Document Feed) mode and return the result(Destination Folder, Count of Scanned Images)

I am using pytwain library for this and current my python version is 3.13.2
And the scanner is Epson 580W scanner.

I want to control the scanning parameters using script.

Currently I have script that works in flat mode.

This is current python code.

from io import BytesIO
import twain
import tkinter
from tkinter import ttk
import logging
import PIL.ImageTk
import PIL.Image

scanned_image = None


def scan():
    global scanned_image
    with twain.SourceManager(root) as sm:
        # this will show UI to allow user to select source
        src = sm.open_source()
        if src:
            src.request_acquire(show_ui=False, modal_ui=False)
            (handle, remaining_count) = src.xfer_image_natively()
            bmp_bytes = twain.dib_to_bm_file(handle)
            img = PIL.Image.open(BytesIO(bmp_bytes), formats=["bmp"])
            width, height = img.size
            factor = 600.0 / width
            # Storing PhotoImage in global variable to prevent it from being deleted once this function exits
            # since PhotoImage has a __del__ destructor
            scanned_image = PIL.ImageTk.PhotoImage(img.resize(size=(int(width * factor), int(height * factor))))
            frm.destroy()
            ttk.Label(root, image=scanned_image).pack(side="left", fill="both", expand=1)
        else:
            print("User clicked cancel")


logging.basicConfig(level=logging.DEBUG)
root = tkinter.Tk()
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Button(frm, text="Scan", command=scan).grid(column=0, row=0)
root.mainloop()

Is there anybody who have experienced with pytwain especially Epson scanner or other scanners in ADF mode?

I appreciate your help.

Thanks.

PS: I found an github repo that can be useful, but I am not sure about the version. It uses Python 2.7 and 3.9.

This is github repo url: https://github.com/wlsc10th-info/auto-scan
But Currently I already built my codebase with python 3.13.2.
So now I am worring about the version conflict.

Do you have any experience or solution for this?