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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shell_session_manager-1.0.1.tar.gz.
File metadata
- Download URL: shell_session_manager-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ba0ec8c71a813bb12ffe0f7fc64285be8e67baf8384dbbf99352329c72b076e
|
|
| MD5 |
3f1bed8744ef98ad19bc98d2e4950094
|
|
| BLAKE2b-256 |
bbec5c4eecdfb20836c6f17b5398c7cd340fa3295fa2ad748ea90592b4515f03
|
Provenance
The following attestation bundles were made for shell_session_manager-1.0.1.tar.gz:
Publisher:
shell-session-manager-release.yml on BeautyyuYanli/Kapybara
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shell_session_manager-1.0.1.tar.gz -
Subject digest:
0ba0ec8c71a813bb12ffe0f7fc64285be8e67baf8384dbbf99352329c72b076e - Sigstore transparency entry: 1506595158
- Sigstore integration time:
-
Permalink:
BeautyyuYanli/Kapybara@5bf12b1d3bb275e292342217d534495e83627c2b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BeautyyuYanli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
shell-session-manager-release.yml@5bf12b1d3bb275e292342217d534495e83627c2b -
Trigger Event:
push
-
Statement type:
File details
Details for the file shell_session_manager-1.0.1-py3-none-any.whl.
File metadata
- Download URL: shell_session_manager-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a232ac6569c1b3a7f46ab8130558e662b177364578611b69bf2fb5eda1621bff
|
|
| MD5 |
19fafdc752e01dace3afc0b67ab27ed9
|
|
| BLAKE2b-256 |
f39ffa6fe5f390734dc9efde8be389aa0007815373e952f23903623bc48032c1
|
Provenance
The following attestation bundles were made for shell_session_manager-1.0.1-py3-none-any.whl:
Publisher:
shell-session-manager-release.yml on BeautyyuYanli/Kapybara
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shell_session_manager-1.0.1-py3-none-any.whl -
Subject digest:
a232ac6569c1b3a7f46ab8130558e662b177364578611b69bf2fb5eda1621bff - Sigstore transparency entry: 1506595187
- Sigstore integration time:
-
Permalink:
BeautyyuYanli/Kapybara@5bf12b1d3bb275e292342217d534495e83627c2b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/BeautyyuYanli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
shell-session-manager-release.yml@5bf12b1d3bb275e292342217d534495e83627c2b -
Trigger Event:
push
-
Statement type: