import subprocess subprocess.call(["sudo", "apt", "update"])

Read more of this post