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 provides no advances shell features likes pipes. This function takes in either a string or an argv list.
  • The run_bash function provides real Bash (e.g., pipes, redirects, globs, etc.). This function takes in a string.

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.3.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.3-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_bash_wrapper-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 fcbd4243c7e9ca728f6a7a50cdc897f87cd3fb850c34cc97798272a8eabf5a2c
MD5 5bb2d6958371d0f0f81940af5d858567
BLAKE2b-256 d5977e5daf580f3334583a5c16ce9b60e69828373a415b70c84dede189f1d496

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_bash_wrapper-0.3.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: py_bash_wrapper-0.3.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 72c7f51c1fef37b5bd0c5e9830e245a35e5aa52cafba5debfde6e3d33fe304bc
MD5 55ee03cfb8c3f7e7ead2923e1711a2c6
BLAKE2b-256 451ff250b7ca85c8289f28a3f77ce225cd36bbdf7a55ea75b43d44eaa428272c

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_bash_wrapper-0.3.3-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