Skip to main content

shpyX - Configurable shell command execution in Python

Installation

Install with pip:

pip install shpyx

Usage

Run a command:

>>> import shpyx
>>> shpyx.run("echo 'Hello world'")
ShellCmdResult(cmd="echo 'Hello world'", stdout='Hello world\n', stderr='', all_output='Hello world\n', return_code=0)

Run a command and print the output:

>>> shpyx.run("echo 'Hello world'", log_output=True)
Hello world
ShellCmdResult(cmd="echo 'Hello world'", stdout='Hello world\n', stderr='', all_output='Hello world\n', return_code=0)

Get partial output during long commands:

>>> result = shpyx.run("echo 'Hello'; sleep 10000", log_output=True)
Hello

Motivation

Running shell commands in Python is often useful when the user is interested in combining shell and Python logic, or managing the outcome of shell commands in Python.

The Python standard library provides a simple way of doing so via the subprocess module:

import subprocess

cmd = "ls -l"
p = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd_stdout, cmd_stderr = p.communicate()

While this is sufficient for many cases, we might also want to:

  • Inspect the return code
  • See live command output (while it is being run)
  • Gracefully handle commands that are stuck (due to blocking I/O, for example)
  • Add formatted printing of every executed command and/or its output

The goal of this project is to provide a friendly API for running shell commands, with emphasis on configurability.

You might also want to check out other packages that deal with similar problems, like bash or invoke.

Security

The call to subprocess.Popen in this library uses shell=True which means that an actual system shell is being created. Untrusted commands should be checked twice before being run.

For more info, see security considerations.

Contributing

Running the linters:

docker-compose up --build linters

Release files for shpyx 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shpyx 0.0.5
File Size Uploaded
shpyx-0.0.5.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shpyx 0.0.5
File Interpreter ABI Platform
shpyx-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / shpyx-0.0.5.tar.gz

Download URL shpyx-0.0.5.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
689985fec03eaba456f88b61ffb8469053987aa254aeb13aa076cbf8095302a7
BLAKE2b-256 checksum
How to use checksums
7fbdef0711df027917ee63a808c81cb1700b563cf5be0731cfcf320279c0fbd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / shpyx-0.0.5-py3-none-any.whl

Download URL shpyx-0.0.5-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07afe332ab3e93582fd191101f7c9ef342bf5444b7b1449f5ee39bde0f72bb1c
BLAKE2b-256 checksum
How to use checksums
02a0a5c64ae5e98cee8d9a29f83a85a0c0c80cc4783406da2d83a114e6b4be06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release history Release notifications | RSS feed

0.0.38

2 release files

0.0.37

2 release files

0.0.36

2 release files

0.0.35

2 release files

0.0.34

2 release files

0.0.33

2 release files

0.0.32

2 release files

0.0.30

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.25

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page