nostr_tools.stream_events¶
- async nostr_tools.stream_events(client, filter)[source]¶
Stream events matching the filter using an existing client connection.
This function subscribes to events and yields them as they arrive from the relay. Unlike fetch_events, this continues indefinitely and yields both stored and new events.
- Parameters:
- Yields:
Event– Event instances matching the filter as they arrive- Raises:
ClientConnectionError – If client is not connected
- Return type:
AsyncGenerator[Event, None]
Examples
Stream text notes in real-time:
>>> async with Client(relay) as client: ... filter = Filter(kinds=[1], limit=10) ... async for event in stream_events(client, filter): ... print(f"New note: {event.content}") ... if event.content.startswith("STOP"): ... break
Stream events from specific authors:
>>> filter = Filter(authors=["abc123..."], kinds=[1]) >>> async for event in stream_events(client, filter): ... process_event(event)