utils
utils
¶
Finder service utility functions.
Helpers for relay URL extraction from Nostr event data and API responses, and cursor-paginated streaming of event-relay rows.
Classes¶
Functions¶
fetch_api
async
¶
fetch_api(
session: ClientSession,
source: ApiSourceConfig,
max_response_size: int,
) -> list[Relay]
Fetch and validate relay URLs from a single API endpoint.
Parameters:
-
session(ClientSession) –Shared aiohttp ClientSession for connection pooling.
-
source(ApiSourceConfig) –API source configuration (URL, timeout, extraction params).
-
max_response_size(int) –Maximum response body size in bytes.
Returns:
-
list[Relay]–Deduplicated list of Relay objects.
Source code in src/bigbrotr/services/finder/utils.py
extract_relays_from_response
¶
extract_relays_from_response(
data: Any, expression: str
) -> list[Relay]
Extract and validate relay URLs from a JSON API response.
Applies expression to the parsed JSON data, filters to string values, validates each through parse_relay, and returns a deduplicated list of Relay objects.
Parameters:
-
data(Any) –Parsed JSON response (any type).
-
expression(str) –JMESPath expression that should evaluate to a list of strings.
Returns:
Source code in src/bigbrotr/services/finder/utils.py
stream_event_relays
async
¶
stream_event_relays(
brotr: Brotr, cursor: FinderCursor, batch_size: int
) -> AsyncGenerator[dict[str, Any], None]
Stream event-relay rows for a single relay using cursor pagination.
Fetches rows in batches of batch_size via scan_event_relay, advancing the cursor after each batch. Yields individual rows.
Parameters:
-
brotr(Brotr) –Brotr database interface.
-
cursor(FinderCursor) –FinderCursor with relay URL and pagination position.
-
batch_size(int) –Maximum rows per DB query.
Yields:
-
AsyncGenerator[dict[str, Any], None]–Event-relay row dicts with
event_id,tagvalues,seen_at, -
AsyncGenerator[dict[str, Any], None]–and other event columns.
Source code in src/bigbrotr/services/finder/utils.py
extract_relays_from_tagvalues
¶
extract_relays_from_tagvalues(
rows: list[dict[str, Any]],
) -> list[Relay]
Extract and deduplicate relay URLs from event tagvalues.
Strips the tag prefix (everything up to the first :) from each
value and passes the remainder to parse_relay. All tag
types are examined -- not just r: -- since relay URLs can appear
in any tag. Invalid values are rejected by parse_relay.
Parameters:
-
rows(list[dict[str, Any]]) –Event rows with
tagvalueskey (fromscan_event_relay).
Returns: