nostr_tools.fetch_events

async nostr_tools.fetch_events(client, filter)[source]

Fetch events matching the filter using an existing client connection.

This function subscribes to events matching the filter criteria, collects all matching events, and returns them as a list. The subscription is automatically closed when all stored events have been received.

Parameters:
  • client (Client) – An instance of Client already connected to a relay

  • filter (Filter) – A Filter instance defining the criteria for fetching events

Returns:

A list of Event instances matching the filter

Return type:

List[Event]

Raises:

ClientConnectionError – If client is not connected

Examples

Fetch recent text notes:

>>> async with Client(relay) as client:
...     filter = Filter(kinds=[1], limit=10)
...     events = await fetch_events(client, filter)
...     print(f"Found {len(events)} events")

Fetch events from specific author:

>>> filter = Filter(authors=["abc123..."], kinds=[1, 3])
>>> events = await fetch_events(client, filter)
>>> for event in events:
...     print(f"Event {event.id}: {event.content[:50]}...")