sh - executing system commands and applications in Python

Check out the new site at

sh is a wrapper around Python subprocess library. It offers a nice and easy to use API - it allows using programs or system commands like if they were a function.

The installation is typical: pip install sh. After installation you can import any system command or application from the sh module:

from sh import cd, ls, wesnoth

print ls('./')
print wesnoth('--version')
Arguments can also be passed as methods:
from sh import cd, ls

print ls.nginx('./')
from sh import git

If you want to execute a command in background then use _bg=True. Data passed to standard output or error can be redirected to a file or function passed by using _out and _err arguments. You can also controll interactive commands.


Python programming, 26 December 2012

Check out the new site at
Comment article
Comment article RkBlog main page Search RSS Contact