Skip to main content

Simplify the use of Bash/Shell commands in Python

Project description

GitHub license Unit Tests Project Status PyPI - Python Version PyPI

Py Bash Wrapper

Logo

Description

Py Bash Wrapper helps Python developers run bash/shell/subprocess commands with two convenience functions:

  • The run_command function takes in an argv list and provides no advances shell features likes pipes.
  • The run_bash function provides real Bash (e.g., pipes, redirects, globs, etc.).

Results come back as CommandResult with stdout, stderr, exit code, and an ok flag; The argument check=True will cause failures to raise a CommandError.

Installation

From PyPI:

pip install py_bash_wrapper

Documentation

Full API details live in docstrings under py_bash_wrapper/bash_utils.py and in the usage doc above.

Security note

run_bash executes shell code. Do not pass untrusted input as the Bash command string. Prefer run_command with a fixed argv when shell features are not required. See docs/usage_examples.md.

Quick start

Prerequisites: Initial setup (uv, make, and a supported version of Python3).

make install
from py_bash_wrapper.bash_utils import run_command, run_bash

print(run_command(["python", "-c", "print(1+1)"], check=True).stdout.strip())
print(run_bash("echo hello | wc -c", check=True).stdout.strip())
make run-tests

Initial setup

Prerequisites:

  • uv (package and tool runner):
    • macOS: brew install uv (see Homebrew if needed).
    • Other: Installing uv (official installer and package managers).
  • make:
    • macOS: Xcode Command Line Tools or a build toolchain that provides make.
    • Linux: install build-essential.
    • Windows: use Git Bash, WSL, or another environment that provides make, or run the same uv run ... commands from the Makefile by hand.
  • Python 3.12+: install via OS package manager, via uv with uv python install 3.12, or via python.org.

Common operations

  • Install dependencies and pre-commit hooks: make install
  • Run tests (coverage HTML): make run-tests
  • Run tests (terminal coverage summary): make run-tests-terminal
  • Lint and format check: make lint
  • Lint with auto-fix and format write: make lint-fix
  • Pre-commit gate (Ruff + pytest): make pre-commit
  • Build sdist and wheel: make build
  • Print version from VERSION: make version-show
  • After a v* tag on HEAD, verify it matches VERSION: make version-check-tag

Versioning

Releases follow SemVer. The canonical version string is the repo-root VERSION file (which contains no v prefix). Git tags use a v prefix (e.g., v0.2.0). Packaging reads VERSION via pyproject.toml dynamic metadata.

To cut a release: bump VERSION on a branch, open a PR, and merge to main. When VERSION changes on main, the Tag and release from VERSION workflow (.github/workflows/release-from-version.yml) creates an annotated tag vX.Y.Z on that commit. Then, if that tag does not already exist on the remote, and if no GitHub Release already exists for that same tag, then the workflow pushes it. The same workflow then verifies tag/version consistency, builds the wheel and sdist artifacts, publishes a GitHub Release immediately with auto-generated notes, and uploads the same artifacts to PyPI (Trusted Publishing; GitHub environment pypi). Configure the publisher in PyPI before the first upload; see docs/maintainers.md.

After a tag exists (or locally before pushing), make version-check-tag can be run to confirm the current v* tag matches VERSION. CI runs scripts/verify_version_matches_tag.py on tag pushes for the same check.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_bash_wrapper-0.3.1.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_bash_wrapper-0.3.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file py_bash_wrapper-0.3.1.tar.gz.

File metadata

  • Download URL: py_bash_wrapper-0.3.1.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_bash_wrapper-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fa1c9557f277b4b548b918ffb46d6b143019e4256d70c52fb8275f3f8bee08b7
MD5 da59891265b4407109a1445c77994b28
BLAKE2b-256 281940f98c154df22fbe38814a42ebd4447f78d10d323fefc2cc249e731e171f

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_bash_wrapper-0.3.1.tar.gz:

Publisher: release-from-version.yml on themarkrogers/py_bash_wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_bash_wrapper-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: py_bash_wrapper-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py_bash_wrapper-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d6310bc13b61d4d34cd07d99f68c6ebcb0c26c0210ad10e5b6ba1eebbeec229
MD5 0f7750216e56bf2e4eccf4d87e5104f2
BLAKE2b-256 c17160c2ff0fbffabded633e675291de7b28936692c2d3b5384d4ef4d3863952

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_bash_wrapper-0.3.1-py3-none-any.whl:

Publisher: release-from-version.yml on themarkrogers/py_bash_wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page