{"id":15659541,"url":"https://github.com/thombashi/subprocrunner","last_synced_at":"2025-04-14T19:33:40.560Z","repository":{"id":57472111,"uuid":"65528561","full_name":"thombashi/subprocrunner","owner":"thombashi","description":"A Python wrapper library for subprocess module.","archived":false,"fork":false,"pushed_at":"2024-04-06T16:03:15.000Z","size":272,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T07:05:40.080Z","etag":null,"topics":["python-library","subprocess","wrapper-library"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/subprocrunner","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thombashi.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-08-12T06:19:20.000Z","updated_at":"2025-01-23T01:40:36.000Z","dependencies_parsed_at":"2024-04-10T23:05:22.637Z","dependency_job_id":"b2314715-0b9d-44f4-bca6-0c71f307d284","html_url":"https://github.com/thombashi/subprocrunner","commit_stats":{"total_commits":477,"total_committers":2,"mean_commits":238.5,"dds":"0.20125786163522008","last_synced_commit":"a61fe4b65e32e486c2bbb2721e9ed88e16f2c945"},"previous_names":[],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsubprocrunner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsubprocrunner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsubprocrunner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsubprocrunner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thombashi","download_url":"https://codeload.github.com/thombashi/subprocrunner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248946145,"owners_count":21187459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python-library","subprocess","wrapper-library"],"created_at":"2024-10-03T13:17:22.921Z","updated_at":"2025-04-14T19:33:40.537Z","avatar_url":"https://github.com/thombashi.png","language":"Python","readme":".. contents:: **subprocrunner**\n   :backlinks: top\n   :depth: 2\n\n\nSummary\n=============\nA Python wrapper library for ``subprocess`` module.\n\n|PyPI pkg ver| |Supported Python versions| |Supported Python implementations| |CI status| |Test coverage| |CodeQL|\n\n.. |PyPI pkg ver| image:: https://badge.fury.io/py/subprocrunner.svg\n    :target: https://badge.fury.io/py/subprocrunner\n    :alt: PyPI package version\n\n.. |Supported Python versions| image:: https://img.shields.io/pypi/pyversions/subprocrunner.svg\n    :target: https://pypi.org/project/subprocrunner\n    :alt: Supported Python versions\n\n.. |Supported Python implementations| image:: https://img.shields.io/pypi/implementation/subprocrunner.svg\n    :target: https://pypi.org/project/subprocrunner\n    :alt: Supported Python implementations\n\n.. |CI status| image:: https://github.com/thombashi/subprocrunner/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/thombashi/subprocrunner/actions/workflows/ci.yml\n    :alt: CI status of Linux/macOS/Windows\n\n.. |Test coverage| image:: https://coveralls.io/repos/github/thombashi/subprocrunner/badge.svg?branch=master\n    :target: https://coveralls.io/github/thombashi/subprocrunner?branch=master\n    :alt: Test coverage\n\n.. |CodeQL| image:: https://github.com/thombashi/subprocrunner/actions/workflows/github-code-scanning/codeql/badge.svg\n    :target: https://github.com/thombashi/subprocrunner/actions/workflows/github-code-scanning/codeql\n    :alt: CodeQL\n\n\nUsage\n========\nExecute a command\n----------------------------\n:Sample Code:\n    .. code:: python\n\n        from subprocrunner import SubprocessRunner\n\n        runner = SubprocessRunner([\"echo\", \"test\"])\n        print(runner)\n        print(f\"return code: {runner.run()}\")\n        print(f\"stdout: {runner.stdout}\")\n        \n        runner = SubprocessRunner([\"ls\", \"__not_exist_dir__\"])\n        print(runner)\n        print(f\"return code: {runner.run()}\")\n        print(f\"stderr: {runner.stderr}\")\n        \n:Output:\n    .. code::\n\n        SubprocessRunner(command='echo test', returncode='not yet executed')\n        return code: 0\n        stdout: test\n        \n        SubprocessRunner(command='ls __not_exist_dir__', returncode='not yet executed')\n        return code: 2\n        stderr: ls: cannot access '__not_exist_dir__': No such file or directory\n\nExecute a command with retries\n--------------------------------------------------------\n\n:Sample Code:\n    .. code:: python\n\n        from subprocrunner import Retry, SubprocessRunner\n\n        SubprocessRunner(command).run(retry=Retry(total=3, backoff_factor=0.2, jitter=0.2))\n\nRaise an exception when a command execution failed\n--------------------------------------------------------\n:Sample Code:\n    .. code:: python\n\n        import sys\n        from subprocrunner import SubprocessRunner\n        from subprocrunner.error import CalledProcessError\n\n        runner = SubprocessRunner(\"ls not-exist-dir\")\n\n        # raise an exception at run\n        try:\n            runner.run(check=True)\n        except CalledProcessError as e:\n            print(f\"run(check=True): {e}\\n{e.stderr}\", file=sys.stderr)\n\n\n        # raise an exception after run\n        runner.run()\n        try:\n            runner.raise_for_returncode()\n        except CalledProcessError as e:\n            print(f\"raise_for_returncode(): {e}\\n{e.stderr}\", file=sys.stderr)\n\n:Output:\n    .. code::\n\n        run(check=True): Command 'ls not-exist-dir' returned non-zero exit status 2.\n        ls: cannot access 'not-exist-dir': No such file or directory\n\n        raise_for_returncode(): Command 'ls not-exist-dir' returned non-zero exit status 2.\n        ls: cannot access 'not-exist-dir': No such file or directory\n\ndry run\n----------------------------\nCommands are not actually run when passing ``dry_run=True`` to ``SubprocessRunner`` class constructor.\n\n:Sample Code:\n    .. code:: python\n\n        from subprocrunner import SubprocessRunner\n\n        runner = SubprocessRunner(\"echo test\", dry_run=True)\n        print(runner)\n        print(f\"return code: {runner.run()}\")\n        print(f\"stdout: {runner.stdout}\")\n        \n:Output:\n    .. code::\n\n        SubprocessRunner(command='echo test', returncode='not yet executed', dryrun=True)\n        return code: 0\n        stdout: \n\nGet execution command history\n--------------------------------------------------------\n:Sample Code:\n    .. code:: python\n\n        from subprocrunner import SubprocessRunner\n\n        SubprocessRunner.clear_history()\n        SubprocessRunner.is_save_history = True\n        \n        SubprocessRunner([\"echo\", \"hoge\"]).run()\n        SubprocessRunner([\"echo\", \"foo\"]).run()\n        \n        print(\"\\n\".join(SubprocessRunner.get_history()))\n\n:Output:\n    .. code::\n\n        echo hoge\n        echo foo\n\nGet a command information\n----------------------------\n.. code-block:: pycon\n\n    \u003e\u003e\u003e from subprocrunner import Which\n    \u003e\u003e\u003e which = Which(\"ls\")\n    \u003e\u003e\u003e which.is_exist()\n    True\n    \u003e\u003e\u003e which.abspath()\n    '/usr/bin/ls'\n    \u003e\u003e\u003e which\n    command=ls, is_exist=True, abspath=/usr/bin/ls\n\n\nInstallation\n============\n\nInstall from PyPI\n------------------------------\n::\n\n    pip install subprocrunner\n\nInstall from PPA (for Ubuntu)\n------------------------------\n::\n\n    sudo add-apt-repository ppa:thombashi/ppa\n    sudo apt update\n    sudo apt install python3-subprocrunner\n\n\nDependencies\n============\n- Python 3.7+\n- `Python package dependencies (automatically installed) \u003chttps://github.com/thombashi/subprocrunner/network/dependencies\u003e`__\n\nOptional dependencies\n----------------------------------\n- `loguru \u003chttps://github.com/Delgan/loguru\u003e`__\n    - Used for logging if the package installed\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fsubprocrunner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthombashi%2Fsubprocrunner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fsubprocrunner/lists"}