Search code examples
pythonpassword-protection

Password protect a Python Script that is Scheduled to run daily


I have a python script that is scheduled to run at a fixed time daily

If I am not around my colleague will be able to access my computer to run the script if there is any error with the windows task scheduler

I like to allow him to run my windows task scheduler but also to protect my source code in the script... is there any good way to do this, please?

(I have read methods to use C code to hide it but I am only familiar with Python)

Thank you


Solution

  • Compile the source to the .pyc bytecode, and then move the source somewhere inaccessible.

    • Open a terminal window in the directory containing your script
    • Run python -m py-compile <yourfile.py> (you should get a yourfile.pyc file)
    • Move <yourfile.py> somewhere secure
    • your script can now be run as python <yourfile.pyc>

    Note that is is not necessarily secure as such - there are ways to decompile the bytecode - but it does obfuscate it, if that is your requirement.