Skip to main content

Safe subprocess wrapper (list-only, no shell injection) with stream/timeout support — standalone module from the SciTeX ecosystem

Project description

scitex-sh

SciTeX

Safe subprocess wrapper — list-only (no shell-string parsing), structured result, timeouts, streaming.

Full Documentation · uv pip install scitex-sh[all]

PyPI Python Tests Coverage (develop) Docs License: AGPL v3


Installation

pip install scitex-sh

Architecture

src/scitex_sh/
├── __init__.py         # public re-exports: sh, sh_run, quote
├── _execute.py         # core sh() — list-only argv, dict result, streaming, timeouts
├── _security.py        # reject shell=True / string-cmd inputs (refuse silent injection)
├── _shell_legacy.py    # opt-in legacy shell-string path (kept off by default)
└── _types.py           # ShResult TypedDict
flowchart LR
    user["sh.sh([cmd, arg, arg])"] --> guard["_security: reject str / shell=True"]
    guard --> sub["subprocess.run / Popen"]
    sub -->|"capture"| dict[("{stdout, stderr, returncode, success}")]
    sub -.->|"stream_output=True"| tty[("live stdout/stderr")]
    sub -.->|"timeout=N"| killed[("TimeoutExpired → returncode != 0")]

1 Interfaces

Python API
import scitex_sh as sh

# Dict result (stdout / stderr / returncode / success)
res = sh.sh(["git", "status"])

# String result
out = sh.sh(["ls", "-la"], return_as="str")

# Streamed output
sh.sh(["./long-running.sh"], stream_output=True)

# Timeout
sh.sh(["sleep", "10"], timeout=2)

# Lower-level
res = sh.sh_run(["echo", "hi"])
sh.quote("hello world")            # 'hello world' (POSIX-quoted)

Demo

flowchart LR
    A["sh.sh(['git', 'status'])"] --> R1[("{stdout, stderr,\nreturncode, success}")]
    B["sh.sh(['ls', '-la'], return_as='str')"] --> R2[("stdout str")]
    C["sh.sh(['./long.sh'], stream_output=True)"] --> R3[("live tty stream")]
    D["sh.sh(['sleep', '10'], timeout=2)"] --> R4[("TimeoutExpired")]
    E["sh.sh('rm -rf /')\n(string input)"] --> R5[("ValueError: list-only")]

Quick Start

import scitex_sh as sh

res = sh.sh(["git", "status"])
print(res["stdout"])

Status

Standalone fork of scitex.sh. Zero deps (pure stdlib). The umbrella package's scitex.sh import path is preserved via a sys.modules-alias bridge. The scitex.str.color_text dep used for terminal output is replaced with a tiny inline ANSI helper that respects NO_COLOR and TTY detection.

Part of SciTeX

scitex-sh is part of SciTeX. Install via the umbrella with pip install scitex[sh] to use as scitex.sh (Python) or scitex sh ... (CLI).

Four Freedoms for Research

  1. The freedom to run your research anywhere — your machine, your terms.
  2. The freedom to study how every step works — from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. The freedom to modify any module and share improvements with the community.

AGPL-3.0 — because we believe research infrastructure deserves the same freedoms as the software it runs on.

License

AGPL-3.0-only (see LICENSE).


SciTeX

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

scitex_sh-0.1.4.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scitex_sh-0.1.4-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file scitex_sh-0.1.4.tar.gz.

File metadata

  • Download URL: scitex_sh-0.1.4.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_sh-0.1.4.tar.gz
Algorithm Hash digest
SHA256 11b266bb57c7bd88c11e5d8af97abe7cec3b942ddbe3809f84346cde421dba95
MD5 66d01b613fb52625e2417cd1c5176142
BLAKE2b-256 219ecdef8032c0f0d93f680b2c96859fdea5e40739d633f1c50e9a98b35cb809

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_sh-0.1.4.tar.gz:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-sh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scitex_sh-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: scitex_sh-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_sh-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b52a129cb2b3aade26cc8773465c895a0c5b8d5b191542715dc95bf9733ca3d1
MD5 0ec8625e33e24c497b6662bd138aa276
BLAKE2b-256 5e9e87da43ca2da88b08982001fa6bacd5da5ca6be9bdca47c71698a3d98c98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_sh-0.1.4-py3-none-any.whl:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-sh

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