For anyone seeing this in the future, i highly recommend this decorator from kbarnes3: https://gist.github.com/kbarnes3/3fb7d353e9bdd3efccd5
Just download the file, put it in your script directory and use as follows:
from powermanagement import long_running
@long_running
def your_function():
#do stuff
your_function()
As long as your_function() is running, the pc won't turn the screen off and thus not go to sleep.
It works by using the ctypes module and thread Execuion States. As far as I know this is also the method used by most media players etc. And it's a really clean solution since you don't have to move your mouse or press keys.