Skip to main content

Async subprocess session manager with incremental stdin/stdout/stderr support

Project description

shell-session-manager

shell-session-manager provides async subprocess sessions that can be resumed across multiple calls. It drains stdout/stderr in background asyncio tasks, supports incremental stdin writes, exposes short session ids, and manages best-effort cleanup for long-lived command sessions.

Command construction is intentionally out of scope: callers should pass the exact command string they want to execute, including any shell, SSH, PTY, or environment bootstrap wrappers.

Usage

import anyio

from shell_session_manager import ShellSession, ShellSessionOptions


async def main() -> None:
    async with ShellSession(
        "python -u -c 'import sys; print(\"ready\"); line = sys.stdin.readline(); print(line.upper(), end=\"\")'",
        options=ShellSessionOptions(timeout_seconds=1),
    ) as session:
        stdout, stderr, code = await session.next()
        print(stdout.decode(), stderr.decode(), code)  # ready\n, "", None

        stdout, stderr, code = await session.next(b"hello\n")
        print(stdout.decode(), stderr.decode(), code)  # HELLO\n, "", 0


anyio.run(main)

For multiple long-lived sessions, use ShellSessionManager:

import anyio

from shell_session_manager import ShellSessionManager


async def main() -> None:
    async with ShellSessionManager() as manager:
        session_id = await manager.new_shell("python -c 'print(42)'")
        stdout, stderr, returncode = await manager.next(session_id)
        print(stdout.decode(), stderr.decode(), returncode)


anyio.run(main)

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

shell_session_manager-1.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

shell_session_manager-1.0.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file shell_session_manager-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for shell_session_manager-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c365e4f53db8ad01db655d64d9f19a25918431425032a6f1e30e4dc4e5e0545
MD5 c0291d21130200d7dd9dbdd2f9afd1fc
BLAKE2b-256 2ec25c730fc5797cd197a4cfc5ed5054793a1f02a3348bafbdcb7b90d1b1d281

See more details on using hashes here.

Provenance

The following attestation bundles were made for shell_session_manager-1.0.0.tar.gz:

Publisher: shell-session-manager-release.yml on BeautyyuYanli/Kapybara

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

File details

Details for the file shell_session_manager-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shell_session_manager-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06e4d6adabace839f499738017cab8cf5da9da97eb6893c208f744828c17ba64
MD5 ef46a3117bded97d5a850522806fb4bf
BLAKE2b-256 222b37a1395bb53b6b710d270529eecfe0a91e30d8a99258a17e826d22b02bb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for shell_session_manager-1.0.0-py3-none-any.whl:

Publisher: shell-session-manager-release.yml on BeautyyuYanli/Kapybara

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