Skip to main content

Module

Query result wrapper for easy data access and pagination.

QueryResult

A list-like wrapper for query results that provides easy access to records and pagination. This class makes it simple to work with query results by:
  • Providing list-like indexing and iteration (e.g., result[0], for record in result)
  • Flattening nested record structures into simple dictionaries
  • Exposing pagination metadata (limit, next_starting_token, paginated)
  • Offering a next_page() method to easily fetch subsequent pages
Examples

Basic iteration

agent_stream = LogStream.get(name=“Production Logs”, project_name=“My AI Project”) result = log_stream.get_spans(limit=10) for record in result: print(record[“id”], record[“input”])

Index access

first_record = result[0] print(first_record[“created_at”])

Pagination (in-place - extends the current result)

if result.has_next_page: result.next_page() print(f”Now have {len(result)} records after fetching next page”)

Pagination (with assignment - same object returned)

result = log_stream.get_spans(limit=10) if result.has_next_page: result = result.next_page() for record in result: print(record[“id”])

Check pagination status

print(f”Total records in this page: {len(result)}”) print(f”Has next page: {result.has_next_page}“)

has_next_page

Whether there is a next page available.

last_row_id

The ID of the last row in this result set.

limit

The maximum number of records per page.

next_page

Fetch the next page and extend current results. Examples

In-place usage (mutates the result)

result = log_stream.get_spans(limit=10) if result.has_next_page: result.next_page() print(f”Now have {len(result)} records”)

Assignment usage (same object, supports chaining)

result = log_stream.get_spans(limit=10) if result.has_next_page: result = result.next_page() for record in result: print(record[“id”])

next_starting_token

Token for fetching the next page, or None if this is the last page.

paginated

Whether pagination is enabled.

starting_token

The starting token used for this page.

to_list

Convert the result to a plain list of dictionaries. Examples result = log_stream.get_spans() records_list = result.to_list()