skillfed

sh

Python subprocess replacement

sh v2.4.0 12.2M downloads/30d#1,334 on PyPI7,245
Permissive license MIT Active released

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 sh

uv

uv add sh

poetry

poetry add sh

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: System AdministratorsLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Build ToolsTopic :: Software Development :: Libraries :: Python Modules

Tags

subprocess replacementcall unix commands from pythonshell command wrapperpython subprocess alternativeexecute external programsunix system calls pythoncommand line interface wrapper
subprocessunix-onlycli-wrapper

More Python Modules packages