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.3.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.3-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_sh-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 2ecd02bd95c336c6c67cd60214d2e4bb89f5231b626eb0252fdd1b77f623863a
MD5 1a314aebac9f611aee662f32f44c457c
BLAKE2b-256 ed97797ffd284106a6e856e17b39f1e464f042469119fbc017b2c24ed0a40301

See more details on using hashes here.

Provenance

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

Publisher: publish-pypi.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.3-py3-none-any.whl.

File metadata

  • Download URL: scitex_sh-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9bc2a8c58fd9d2721e72846bf497868461274c90c6ad2d3b90852ffa904a6d20
MD5 741a9a4aa493863a845073272b7ee469
BLAKE2b-256 207adca03a277937e60658079c9de2f1c7258683ae6f5c972f5734ed6d38d602

See more details on using hashes here.

Provenance

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

Publisher: publish-pypi.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