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)

shellctl server

Run the HTTP API locally with:

pdm run shellctl serve --listen 127.0.0.1:8765

Pass --auth-token your-token when you want bearer auth enforced. shellctl serve also reads SHELLCTL_AUTH_TOKEN, so you can export the token instead of passing the flag. Leave the flag/env var unset or empty to start without requiring an Authorization header.

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-2.1.1.tar.gz (47.1 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-2.1.1-py3-none-any.whl (45.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shell_session_manager-2.1.1.tar.gz
  • Upload date:
  • Size: 47.1 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-2.1.1.tar.gz
Algorithm Hash digest
SHA256 bf490809161244beb95cabad62d32a59b351b7b5993e375d49b6fcf3835ae31c
MD5 7eb998321aa256e070ff815b592a46e2
BLAKE2b-256 a4648d12611e48553d61423d5e302d178e67bd968a35f1709e26024f4e04fc3b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for shell_session_manager-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b53c813ac386bbf3244c375edf9cce675c89a2041d33a969ef69d8d74f89ac6
MD5 7bc21cd40e862dae8a68b7f22eb0bf96
BLAKE2b-256 fd7464d6db5888f6e7c7dcf0b4960e9ffa8c38425fa906cd60e99ed0bd88def7

See more details on using hashes here.

Provenance

The following attestation bundles were made for shell_session_manager-2.1.1-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