Skip to main content

A Python wrapper library for subprocess module.

Project description

Summary

A Python wrapper library for subprocess module.

PyPI package version Supported Python versions Supported Python implementations Linux/macOS/Windows CI status Test coverage

Examples

Execute a command

Sample Code:
from subprocrunner import SubprocessRunner

runner = SubprocessRunner("echo test")
print("command: {:s}".format(runner.command))
print("return code: {:d}".format(runner.run()))
print("stdout: {:s}".format(runner.stdout))

runner = SubprocessRunner("ls __not_exist_dir__")
print("command: {:s}".format(runner.command))
print("return code: {:d}".format(runner.run()))
print("stderr: {:s}".format(runner.stderr))
Output:
command: echo test
return code: 0
stdout: test

command: ls __not_exist_dir__
return code: 2
stderr: ls: cannot access '__not_exist_dir__': No such file or directory

Execute a command with retry

Sample Code:
from subprocrunner import Retry, SubprocessRunner

SubprocessRunner(command).run(retry=Retry(total=3, backoff_factor=0.2, jitter=0.2))

dry run

Commands are not actually run when passing dry_run=True to SubprocessRunner class constructor.

Sample Code:
from subprocrunner import SubprocessRunner

runner = SubprocessRunner("echo test", dry_run=True)
print("command: {:s}".format(runner.command))
print("return code: {:d}".format(runner.run()))
print("stdout: {:s}".format(runner.stdout))
Output:
command: echo test
return code: 0
stdout:

Get execution command history

Sample Code:
from subprocrunner import SubprocessRunner

SubprocessRunner.clear_history()
SubprocessRunner.is_save_history = True

SubprocessRunner("echo hoge").run()
SubprocessRunner("echo foo").run()

print("\n".join(SubprocessRunner.get_history()))
Output:
echo hoge
echo foo

Get a command information

>>> from subprocrunner import Which
>>> which = Which("ls")
>>> which.is_exist()
True
>>> which.abspath()
'/usr/bin/ls'
>>> which
command=ls, is_exist=True, abspath=/usr/bin/ls

Installation

Install from PyPI

pip install subprocrunner

Install from PPA (for Ubuntu)

sudo add-apt-repository ppa:thombashi/ppa
sudo apt update
sudo apt install python3-subprocrunner

Dependencies

Optional dependencies

  • loguru
    • Used for logging if the package installed

Download files

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

Source Distribution

subprocrunner-1.4.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

subprocrunner-1.4.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file subprocrunner-1.4.1.tar.gz.

File metadata

  • Download URL: subprocrunner-1.4.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for subprocrunner-1.4.1.tar.gz
Algorithm Hash digest
SHA256 db118f749fccdd8c492f93d71cfde25bc171841f66039e0f2f8eaeb4af770dcb
MD5 4cca049ba825f1e5e125b398be2c142a
BLAKE2b-256 f7ffd7849e1f66d8e48b248d6389df14c226c69a35a2f089eb736d4197b96964

See more details on using hashes here.

File details

Details for the file subprocrunner-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: subprocrunner-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for subprocrunner-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17f8cef88ba6ef68d46fc7f72966b0a140b56f0b085d9af559c72d26257dcda2
MD5 45319faa67cfc4f248470598f67c58e0
BLAKE2b-256 472bad1f031dd35971022d38c93096cb0fd67c004b12c5b26db5e1b8c65956ae

See more details on using hashes here.

Supported by

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