Flash firmware with hex file over serial with Python (no avrdude, Arduino IDE)
This isn't the exact answer but it helps.
Uploading without avrdude is complicated and generally slow. The best solution to not using the IDE is to open and close a port then use the avrdude command that the ide usually uses.
from serial import Serial
from time import sleep
from subprocess import run

while input('Press enter to upload ') == '':
    Serial('COM5',baudrate=1200).close()
    sleep(1)
    run([&quot;C:\\Progra~2\\Arduino\\hardware\\tools\\avr/bin/avrdude&quot;, &quot;-CC:\\Progra~2\\Arduino\\hardware\\tools\\avr/etc/avrdude.conf&quot;, &quot;-v&quot;, &quot;-patmega32u4&quot;, &quot;-cavr109&quot;, &quot;-PCOM6&quot;, &quot;-b57600&quot;, &quot;-D&quot;, &quot;-Uflash:w:C:\\Users\\USER\\Desktop\\Python\\tclab_v2/tclab_v2.ino.hex:i&quot;])