A library of small functions that simplify scripting in python


Keywords
python, shell, bash, script, scripting, pysh
License
MIT
Install
pip install pysh==3.3.1

Documentation

pysh

A library of small functions that simplify scripting in python

Installation

pip install pysh

Usage

sh

Run a shell command and display the output:

sh("git status")

Capture the output of a shell command:

res = sh("git status", capture=True)
print(res.stdout)

cd

Change the current working directory:

cd("path/to/dir")

Change the current working directory temporarily:

with cd("path/to/dir"):
    sh("git status")

env

Set an environment variable:

env(var="value")

Set an environment variable temporarily:

with env(PGPASSWORD="MyPassword", PGUSER="postgres"):
    sh("createdb -h localhost -p 5432 -O postgres mydb")

which

Checks whether an executable/script/builtin is available:

git_is_installed = which("git")