Skip to content

PtyManagerProtocol

Sub classes

Name Children Inherits
SpawnPtyManager
exxec.spawn_pty_manager
PTY sessions for any environment implementing `spawn(pty\=...)`.

    Base classes

    Name Children Inherits
    Protocol
    typing
    Base class for protocol classes.

    â‹” Inheritance diagram

    graph TD
      3356615053["pty_manager.PtyManagerProtocol"]
      1073422405["typing.Protocol"]
      3481597255["typing.Generic"]
      2751680898["builtins.object"]
      1073422405 --> 3356615053
      3481597255 --> 1073422405
      2751680898 --> 3481597255

    🛈 DocStrings

    Bases: Protocol

    Protocol for managing PTY (pseudo-terminal) sessions.

    This protocol defines the interface that all PTY managers must implement, allowing interactive terminal sessions across different execution environments.

    Implementations
    • SpawnPtyManager: Any environment with supports_pty
    Source code in src/exxec/pty_manager.py
    @runtime_checkable
    class PtyManagerProtocol(Protocol):
        """Protocol for managing PTY (pseudo-terminal) sessions.
    
        This protocol defines the interface that all PTY managers must implement,
        allowing interactive terminal sessions across different execution environments.
    
        Implementations:
            - SpawnPtyManager: Any environment with `supports_pty`
        """
    
        async def create(
            self,
            size: PtySize | None = None,
            command: str | None = None,
            args: list[str] | None = None,
            cwd: str | None = None,
            env: dict[str, str] | None = None,
        ) -> PtyInfo:
            """Create a new PTY session.
    
            Args:
                size: Initial terminal size (defaults to 24x80)
                command: Shell command to run (defaults to user's shell or /bin/bash)
                args: Arguments for the command
                cwd: Working directory
                env: Environment variables
    
            Returns:
                PtyInfo with session details including the PTY ID
            """
            ...
    
        async def resize(self, pty_id: str, size: PtySize) -> None:
            """Resize a PTY session.
    
            Args:
                pty_id: The PTY session ID
                size: New terminal size
            """
            ...
    
        async def write(self, pty_id: str, data: bytes) -> None:
            """Write data to a PTY's stdin.
    
            Args:
                pty_id: The PTY session ID
                data: Data to write (typically user input)
            """
            ...
    
        async def read(self, pty_id: str, size: int = 4096) -> bytes:
            """Read data from a PTY's stdout.
    
            Args:
                pty_id: The PTY session ID
                size: Maximum bytes to read
    
            Returns:
                Output data from the PTY
            """
            ...
    
        def stream(self, pty_id: str) -> AsyncIterator[bytes]:
            """Stream output from a PTY session.
    
            Args:
                pty_id: The PTY session ID
    
            Yields:
                Chunks of output data as they become available
            """
            ...
    
        async def kill(self, pty_id: str) -> bool:
            """Kill a PTY session.
    
            Args:
                pty_id: The PTY session ID
    
            Returns:
                True if killed successfully, False if not found
            """
            ...
    
        async def get_info(self, pty_id: str) -> PtyInfo | None:
            """Get information about a PTY session.
    
            Args:
                pty_id: The PTY session ID
    
            Returns:
                PtyInfo if found, None otherwise
            """
            ...
    
        async def list_sessions(self) -> list[PtyInfo]:
            """List all active PTY sessions.
    
            Returns:
                List of PtyInfo for all active sessions
            """
            ...
    

    create async

    create(
        size: PtySize | None = None,
        command: str | None = None,
        args: list[str] | None = None,
        cwd: str | None = None,
        env: dict[str, str] | None = None,
    ) -> PtyInfo
    

    Create a new PTY session.

    Parameters:

    Name Type Description Default
    size PtySize | None

    Initial terminal size (defaults to 24x80)

    None
    command str | None

    Shell command to run (defaults to user's shell or /bin/bash)

    None
    args list[str] | None

    Arguments for the command

    None
    cwd str | None

    Working directory

    None
    env dict[str, str] | None

    Environment variables

    None

    Returns:

    Type Description
    PtyInfo

    PtyInfo with session details including the PTY ID

    Source code in src/exxec/pty_manager.py
    async def create(
        self,
        size: PtySize | None = None,
        command: str | None = None,
        args: list[str] | None = None,
        cwd: str | None = None,
        env: dict[str, str] | None = None,
    ) -> PtyInfo:
        """Create a new PTY session.
    
        Args:
            size: Initial terminal size (defaults to 24x80)
            command: Shell command to run (defaults to user's shell or /bin/bash)
            args: Arguments for the command
            cwd: Working directory
            env: Environment variables
    
        Returns:
            PtyInfo with session details including the PTY ID
        """
        ...
    

    get_info async

    get_info(pty_id: str) -> PtyInfo | None
    

    Get information about a PTY session.

    Parameters:

    Name Type Description Default
    pty_id str

    The PTY session ID

    required

    Returns:

    Type Description
    PtyInfo | None

    PtyInfo if found, None otherwise

    Source code in src/exxec/pty_manager.py
    async def get_info(self, pty_id: str) -> PtyInfo | None:
        """Get information about a PTY session.
    
        Args:
            pty_id: The PTY session ID
    
        Returns:
            PtyInfo if found, None otherwise
        """
        ...
    

    kill async

    kill(pty_id: str) -> bool
    

    Kill a PTY session.

    Parameters:

    Name Type Description Default
    pty_id str

    The PTY session ID

    required

    Returns:

    Type Description
    bool

    True if killed successfully, False if not found

    Source code in src/exxec/pty_manager.py
    async def kill(self, pty_id: str) -> bool:
        """Kill a PTY session.
    
        Args:
            pty_id: The PTY session ID
    
        Returns:
            True if killed successfully, False if not found
        """
        ...
    

    list_sessions async

    list_sessions() -> list[PtyInfo]
    

    List all active PTY sessions.

    Returns:

    Type Description
    list[PtyInfo]

    List of PtyInfo for all active sessions

    Source code in src/exxec/pty_manager.py
    async def list_sessions(self) -> list[PtyInfo]:
        """List all active PTY sessions.
    
        Returns:
            List of PtyInfo for all active sessions
        """
        ...
    

    read async

    read(pty_id: str, size: int = 4096) -> bytes
    

    Read data from a PTY's stdout.

    Parameters:

    Name Type Description Default
    pty_id str

    The PTY session ID

    required
    size int

    Maximum bytes to read

    4096

    Returns:

    Type Description
    bytes

    Output data from the PTY

    Source code in src/exxec/pty_manager.py
    async def read(self, pty_id: str, size: int = 4096) -> bytes:
        """Read data from a PTY's stdout.
    
        Args:
            pty_id: The PTY session ID
            size: Maximum bytes to read
    
        Returns:
            Output data from the PTY
        """
        ...
    

    resize async

    resize(pty_id: str, size: PtySize) -> None
    

    Resize a PTY session.

    Parameters:

    Name Type Description Default
    pty_id str

    The PTY session ID

    required
    size PtySize

    New terminal size

    required
    Source code in src/exxec/pty_manager.py
    async def resize(self, pty_id: str, size: PtySize) -> None:
        """Resize a PTY session.
    
        Args:
            pty_id: The PTY session ID
            size: New terminal size
        """
        ...
    

    stream

    stream(pty_id: str) -> AsyncIterator[bytes]
    

    Stream output from a PTY session.

    Parameters:

    Name Type Description Default
    pty_id str

    The PTY session ID

    required

    Yields:

    Type Description
    AsyncIterator[bytes]

    Chunks of output data as they become available

    Source code in src/exxec/pty_manager.py
    def stream(self, pty_id: str) -> AsyncIterator[bytes]:
        """Stream output from a PTY session.
    
        Args:
            pty_id: The PTY session ID
    
        Yields:
            Chunks of output data as they become available
        """
        ...
    

    write async

    write(pty_id: str, data: bytes) -> None
    

    Write data to a PTY's stdin.

    Parameters:

    Name Type Description Default
    pty_id str

    The PTY session ID

    required
    data bytes

    Data to write (typically user input)

    required
    Source code in src/exxec/pty_manager.py
    async def write(self, pty_id: str, data: bytes) -> None:
        """Write data to a PTY's stdin.
    
        Args:
            pty_id: The PTY session ID
            data: Data to write (typically user input)
        """
        ...
    

    :fa-brands-github: Show source on GitHub