Skip to content

subscribe

Open a long-lived asynchronous subscription for server-pushed events.

Create an async context manager for pushed Herdr events.

Parameters:

Name Type Description Default
subscriptions Iterable[EventSubscription]

Event filters to register with the server.

required

Returns:

Type Description
AsyncSubscription

An async subscription context manager. Enter it before iterating over

AsyncSubscription

events().

The subscriptions iterable contains event filters, for example {"event": "pane.output"}.

Example
async with client.subscribe([{"event": "pane.output"}]) as stream:
    async for event in stream.events():
        print(event)
Source code in src/herdr_client/async_client/client.py
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
def subscribe(
    self, subscriptions: Iterable[EventSubscription]
) -> AsyncSubscription:
    """Create an async context manager for pushed Herdr events.

    Args:
        subscriptions: Event filters to register with the server.

    Returns:
        An async subscription context manager. Enter it before iterating over
        ``events()``.

    The ``subscriptions`` iterable contains event filters, for example
    ``{"event": "pane.output"}``.

    Example:
        ```python
        async with client.subscribe([{"event": "pane.output"}]) as stream:
            async for event in stream.events():
                print(event)
        ```
    """
    return AsyncSubscription(self.socket_path, self.timeout, subscriptions)