The terminal is a just way for a person to issue commands to the operating system and for the operating system to show results back to the person. With Python and other languages, you can issue commands to the operation system without a terminal and programmatically process responses received back from the OS or the program you had the OS run. For python, use the subprocess module. For example, you might write something like subprocess.POpen(["apt-get", "install", "firefox"], ...)
. I am on Windows, so cannot test a specific example on Ubuntu. Read the docs and experiment with the examples and options.