CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-i3ipc

Python library for controlling the i3 window manager and sway compositor through their IPC interface

Pending
Overview
Eval results
Files

connection.mddocs/

Connection Management

Core connection functionality for establishing and managing IPC communication with i3/sway window managers. Handles socket path discovery, connection establishment, message sending/receiving, and automatic reconnection.

Capabilities

Connection Initialization

class Connection:
    def __init__(self, socket_path=None, auto_reconnect=False):
        """
        Create a connection to the i3/sway IPC socket.
        
        Parameters:
        - socket_path: Optional[str], path to IPC socket (auto-detected if None)
        - auto_reconnect: bool, whether to reconnect automatically on disconnect
        
        Raises:
        Exception: if connection to i3/sway cannot be established
        """

Connection Properties

@property
def socket_path(self) -> str:
    """
    Get the path to the IPC socket.
    
    Returns:
    str: absolute path to the IPC socket file
    """

@property  
def auto_reconnect(self) -> bool:
    """
    Get the auto-reconnect setting.
    
    Returns:
    bool: whether automatic reconnection is enabled
    """

Command Execution

def command(self, payload: str) -> List[CommandReply]:
    """
    Execute i3/sway commands.
    
    Parameters:
    - payload: str, command string to execute (can contain multiple semicolon-separated commands)
    
    Returns:
    List[CommandReply]: results of command execution, one per command
    """

def send_tick(self, payload: str = "") -> TickReply:
    """
    Send a tick event with optional payload.
    
    Parameters:
    - payload: str, optional data to include with tick event
    
    Returns:
    TickReply: confirmation of tick processing
    """

Event Handling

def on(self, event: Union[Event, str], handler: Callable[[Connection, IpcBaseEvent], None]) -> None:
    """
    Subscribe to window manager events.
    
    Parameters:
    - event: Union[Event, str], event type to subscribe to
    - handler: Callable, function called when event occurs (receives connection and event data)
    """

def off(self, handler: Callable[[Connection, IpcBaseEvent], None]) -> None:
    """
    Remove event handler from all subscriptions.
    
    Parameters:
    - handler: Callable, handler function to remove
    """

def main(self, timeout: float = 0.0) -> None:
    """
    Start the main event loop to process subscribed events.
    
    Parameters:
    - timeout: float, timeout in seconds (0 = run forever until main_quit called)
    """

def main_quit(self) -> None:
    """
    Stop the main event loop and exit event processing.
    """

Core Query Methods

def get_version(self) -> VersionReply:
    """
    Get i3/sway version information and configuration details.
    
    Returns:
    VersionReply: version numbers, human-readable string, and config file path
    """

def get_tree(self) -> Con:
    """
    Get the complete window/container tree structure.
    
    Returns:
    Con: root container with full tree hierarchy
    """

def get_workspaces(self) -> List[WorkspaceReply]:
    """
    Get information about all workspaces.
    
    Returns:
    List[WorkspaceReply]: workspace details including visibility and focus state
    """

def get_outputs(self) -> List[OutputReply]:
    """
    Get information about all outputs/monitors.
    
    Returns:
    List[OutputReply]: output details including resolution and active status
    """

def get_marks(self) -> List[str]:
    """
    Get all container marks currently set.
    
    Returns:
    List[str]: list of mark names
    """

def get_binding_modes(self) -> List[str]:
    """
    Get all available binding modes.
    
    Returns:
    List[str]: list of binding mode names
    """

def get_config(self) -> ConfigReply:
    """
    Get the current configuration file contents.
    
    Returns:
    ConfigReply: raw configuration file text
    """

Sway-Specific Methods

def get_inputs(self) -> List[InputReply]:
    """
    Get information about input devices (sway only).
    
    Returns:
    List[InputReply]: input device details including type and capabilities
    """

def get_seats(self) -> List[SeatReply]:
    """
    Get information about seats (sway only).
    
    Returns:
    List[SeatReply]: seat details including focus and attached devices
    """

Bar Configuration

def get_bar_config_list(self) -> List[str]:
    """
    Get list of all bar configuration IDs.
    
    Returns:
    List[str]: bar ID strings
    """

def get_bar_config(self, bar_id: str = None) -> Optional[BarConfigReply]:
    """
    Get bar configuration details.
    
    Parameters:
    - bar_id: Optional[str], specific bar ID (uses first bar if None)
    
    Returns:
    Optional[BarConfigReply]: bar configuration or None if not found
    """

Version Reply Structure

class VersionReply:
    """Response from GET_VERSION request."""
    major: int  # Major version number
    minor: int  # Minor version number  
    patch: int  # Patch version number
    human_readable: str  # Human-readable version string
    loaded_config_file_name: str  # Path to loaded config file
    ipc_data: dict  # Raw IPC response data

Config Reply Structure

class ConfigReply:
    """Response from GET_CONFIG request."""
    config: str  # Complete configuration file contents
    ipc_data: dict  # Raw IPC response data

Command Reply Structure

class CommandReply:
    """Response from command execution."""
    success: bool  # Whether command executed successfully
    error: str  # Error message if command failed (None if successful)
    ipc_data: dict  # Raw IPC response data

Tick Reply Structure

class TickReply:
    """Response from tick event transmission."""
    success: bool  # Whether tick was processed successfully
    ipc_data: dict  # Raw IPC response data

Bar Configuration Reply Structure

class BarConfigReply:
    """Response from GET_BAR_CONFIG request."""
    id: str  # Bar configuration ID
    mode: str  # Bar mode (dock, hide, invisible)
    position: str  # Bar position (top, bottom)
    status_command: str  # Command for status line
    font: str  # Font specification
    workspace_buttons: bool  # Whether to show workspace buttons
    binding_mode_indicator: bool  # Whether to show binding mode indicator
    verbose: bool  # Verbose output setting
    colors: dict  # Color configuration mapping
    separator_symbol: str  # Workspace button separator
    strip_workspace_numbers: bool  # Whether to strip workspace numbers
    ipc_data: dict  # Raw IPC response data

Input Reply Structure (Sway Only)

class InputReply:
    """Response from GET_INPUTS request (sway only)."""
    identifier: str  # Unique device identifier
    name: str  # Human-readable device name
    vendor: int  # Vendor ID code
    product: int  # Product ID code
    type: str  # Device type (keyboard, pointer, touch, etc.)
    xkb_active_layout_name: str  # Active keyboard layout name
    xkb_layout_names: List[str]  # Available keyboard layout names
    xkb_active_layout_index: int  # Index of active layout
    libinput: dict  # Libinput configuration settings
    ipc_data: dict  # Raw IPC response data

Seat Reply Structure (Sway Only)

class SeatReply:
    """Response from GET_SEATS request (sway only)."""
    name: str  # Seat name
    capabilities: int  # Seat capabilities bitmask
    focus: int  # ID of focused container
    devices: List[InputReply]  # Input devices attached to this seat
    ipc_data: dict  # Raw IPC response data

Install with Tessl CLI

npx tessl i tessl/pypi-i3ipc

docs

async.md

commands.md

connection.md

containers.md

events.md

index.md

outputs.md

workspaces.md

tile.json