sh is a full-fledged subprocess replacement for Python 2.6 - 3.5, PyPy and PyPy3 that allows you to call any program as if it were a function.
It handles many tasks that make working with ‘Popen’ tedious:
- Easy, and concise way of passing arguments
- Handling of exit codes
- Output redirection (!)
- Piping
- Background processing
and much more! for example:
from sh import ifconfig |
Note that these aren’t Python functions, these are running the binary commands on your system by dynamically resolving your $PATH
, much like Bash does, and then wrapping the binary in a function. In this way, all the programs on your system are easily available to you from within Python.
Installation
$ pip install sh |
Docs & more: amoffat.github.io/sh
Disclaimer
I didn’t write sh, I’m just a fan :)