sh
Python subprocess replacement
What it is and what it does
sh is a subprocess wrapper that lets you import and call Unix programs directly as Python functions, eliminating the need to construct command strings or manage subprocess objects manually. Instead of writing subprocess code, you write `from sh import git; git('status', '--short')`. The package is designed for Unix-like systems only (Linux, macOS, BSD) and does not support Windows.
It works by dynamically creating callable objects that map to system programs and handling the underlying process spawning, argument passing, and output capture. With no external dependencies and a pure-Python implementation, it installs cleanly and runs on Python 3.10 through 3.14 and PyPy. The interface is intentionally simple: it is not a reimplementation of Unix tools in Python, but a thin layer that makes calling existing programs feel native to Python code.
Use it for:
- Automating git workflows in deployment or CI scripts by calling git commands directly as functions.
- Building command-line tools that orchestrate multiple system utilities without subprocess boilerplate.
- Writing system administration scripts that invoke tools like grep, sed, or find with natural Python syntax.
- Testing shell scripts or system behavior from Python test suites by invoking the actual programs.
- Capturing and processing output from external programs in data pipelines or build systems.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Calls any Unix program as a Python function, replacing subprocess with a simpler interface that treats external commands as callable objects.
Yes. sh is actively maintained, has no dependencies, installs with low friction, carries no known vulnerabilities, and solves a real pain point in subprocess handling. Install it if you regularly call Unix programs from Python and prefer a cleaner syntax than subprocess. Not applicable on Windows.
Install
sh on PyPI
pip
pip install shuv
uv add shpoetry
poetry add shInstalling sh
Before you install
Low friction—pure Python wheel with no runtime dependencies. Actively maintained with a recent release (20 days ago) and 7245 repository stars.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install sh
from sh import git
print(git("status", "--short"))
Unix-like operating system required (Linux, macOS, BSD); Windows is not supported.
Verify before relying
- Whether the package handles shell metacharacters and escaping automatically or requires manual quoting.
- Performance characteristics compared to subprocess.run() for high-volume command execution.
- Behavior when called programs write to stderr or exit with non-zero status codes.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 20 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 12,232,375/month — #1,334 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sh-2.4.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
EasyProcessEasyProcess wraps Python's subprocess module to…
permissive · top 5,000 on PyPI
subprocess-teeA drop-in replacement for subprocess.run that…
permissive · top 5,000 on PyPI
runsRuns multiple subprocess commands from a text…
permissive · top 5,000 on PyPI
executorWraps Python's subprocess module to simplify…
permissive · top 15,000 on PyPI
subprocess.runProvides a simplified interface to run shell…
permissive · top 15,000 on PyPI
ptyprocessRun a subprocess in a pseudo terminal (pty) and…
permissive · top 1,000 on PyPI
subprocess-multiteeMultiplexes subprocess stdout/stderr to…
unclear · top 15,000 on PyPI
subprocess32A backport of Python 3's subprocess module to…
permissive · top 15,000 on PyPI
fabricFabric executes shell commands remotely over…
permissive · top 5,000 on PyPI
sargeSarge wraps Python's subprocess module to…
permissive · top 15,000 on PyPI