Skip to main content
A raw stream is a one-shot iterator: you attach, you read, and you accumulate the text yourself. A handle reads the stream for you, buffers the output, records the exit code, and lets you wait until the shell is connected or finished.
Creating a handle performs no I/O. Nothing is sent until you call connect().

Use async

AsyncPtyHandle is the same surface with await and an async context manager.

Call the handle

Read what the handle stored

  • wait_for_connection means the stream was opened. A short command can finish before you call it, and that still returns true. Use is_connected to see if the stream is open at this instant.
  • wait_for_connection connects for you only if you never called connect(). It does not re-attach a stream that has already finished, so buffered output is not duplicated.
  • The output buffer stops at 1 MiB. Once full, the oldest bytes are dropped. For a full transcript, pass an on_data callback, or redirect the program’s output to a file in the runtime.
  • Disconnecting leaves the shell and its scrollback running. Call kill() to stop it. You can attach again later with a new handle.
  • The context manager disconnects on exit, including on exception.

From the CLI

The CLI calls the same session endpoints. pty attach owns the stream while it is open. Ctrl-C detaches and the shell keeps running.