aio.Connection

class i3ipc.aio.Connection(socket_path: Optional[str] = None, auto_reconnect: bool = False)

A connection to the i3 ipc used for querying window manager state and listening to events.

The Connection class is the entry point into all features of the library. You must call connect() before using this Connection.

Example

i3 = await Connection().connect()
workspaces = await i3.get_workspaces()
await i3.command('focus left')
Parameters
  • socket_path (str) – A path to the i3 ipc socket path to connect to. If not given, find the socket path through the default search path.

  • auto_reconnect (bool) – Whether to attempt to reconnect if the connection to the socket is broken when i3 restarts.

Raises

Exception – If the connection to i3 cannot be established.

property auto_reconect

Whether this Connection will attempt to reconnect when the connection to the socket is broken.

Return type

bool

main_quit(_error=None)

Quits the running main loop for this connection.

off(handler: Callable[[Connection, i3ipc.events.IpcBaseEvent], None])

Unsubscribe the handler from being called on ipc events.

Parameters

handler (Callable) – The handler that was previously attached with on().

on(event: Union[i3ipc.events.Event, str], handler: Callable[[Connection, i3ipc.events.IpcBaseEvent], None])

Subscribe to the event and call the handler when it is emitted by the i3 ipc.

Parameters
  • event (Event or str) – The event to subscribe to.

  • handler (Callable) – The event handler to call.

property socket_path

The path of the socket this Connection is connected to.

Return type

str