gitmyhub

sh

Python ★ 7.2k updated 10d ago

Python process launching

A Python library that turns any command-line program into a callable Python function, replacing verbose subprocess calls with simple, readable one-liners.

PythonPyPysetup: easycomplexity 2/5

sh is a Python library that lets you run any command-line program as if it were an ordinary Python function. Instead of writing subprocess calls with long argument lists, you import the program by name and call it directly. For example, to run ifconfig on the eth0 interface, you write from sh import ifconfig and then call ifconfig("eth0"). The output comes back as a string you can use in your Python code.

The library is a replacement for Python's built-in subprocess module, which handles running external programs but requires more boilerplate to use. sh aims to make that same task feel natural and concise. It works on Linux, macOS, and other Unix-like operating systems, but it does not support Windows because it relies on Unix system calls internally.

Compatible Python versions are 3.8 through 3.12 and also PyPy. Installing it takes one pip command. The full documentation with usage examples and advanced options is hosted at sh.readthedocs.io. The README itself is brief and mostly covers installation and how to run the test suite for developers who want to contribute.

The project is actively maintained, currently at version 2, and there is a migration guide for users upgrading from the earlier 1.x version. Tests run inside Docker containers against all supported Python versions.

Where it fits