Check out marcel: https://marceltheshell.org. This is a bash-like shell that pipes Python values, and you can write Python functions on the command line. It also has a Python API (a marcel module) that allows you to shell out far more cleanly than with Popen and friends.