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.2.0.tar.gz (24.2 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.2.0-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_sh-0.2.0.tar.gz
  • Upload date:
  • Size: 24.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 7b83bd840163c588777ede6f06d306b17642be29011353fc26c7d985b6cd367c
MD5 93faaf6a7f02d3328ea6fcd1190d8de0
BLAKE2b-256 253e0437001bb46531131a904856bba3a9a351ce9abd96e345cd7c623fbcdedd

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_sh-0.2.0.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: scitex_sh-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ace0560623b4808606ebed8796849eac3e8f8514579fbab0996c702d4d36a6e0
MD5 58f1e243f2a21c6dfbcd7bf4f6326252
BLAKE2b-256 887076eafaee7bc7933ba948199e2fdedbe298da5a0e36434abeb29cd61be76b

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_sh-0.2.0-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