Pagination and streams¶
SyncCursorPage
¶
SyncCursorPage(
*,
client: SyncAPIClient,
data: list[_T],
next_cursor: str | None,
previous_cursor: str | None,
options: RequestOptions,
response_type: Any,
)
Bases: _PageBase[_T]
One page of results. Iterating it walks this page and every page after it.
fetch
classmethod
¶
fetch(
client: SyncAPIClient,
options: RequestOptions,
response_type: Any,
) -> SyncCursorPage[Any]
build
classmethod
¶
build(
client: SyncAPIClient,
options: RequestOptions,
response_type: Any,
payload: Any,
) -> SyncCursorPage[Any]
Builds a page from an already parsed response.
next_page
¶
next_page() -> SyncCursorPage[_T]
Fetches the following page. Raises StopIteration on the last page.
previous_page
¶
previous_page() -> SyncCursorPage[_T]
Fetches the preceding page. Raises StopIteration on the first page.
iter_pages
¶
iter_pages() -> Generator[SyncCursorPage[_T], None, None]
Yields this page and then each following page.
AsyncCursorPage
¶
AsyncCursorPage(
*,
client: AsyncAPIClient,
data: list[_T],
next_cursor: str | None,
previous_cursor: str | None,
options: RequestOptions,
response_type: Any,
)
Bases: _PageBase[_T]
One page of results. async for walks this page and every page after it.
fetch
async
classmethod
¶
fetch(
client: AsyncAPIClient,
options: RequestOptions,
response_type: Any,
) -> AsyncCursorPage[Any]
build
classmethod
¶
build(
client: AsyncAPIClient,
options: RequestOptions,
response_type: Any,
payload: Any,
) -> AsyncCursorPage[Any]
Builds a page from an already parsed response.
next_page
async
¶
next_page() -> AsyncCursorPage[_T]
Fetches the following page. Raises StopAsyncIteration on the last page.
previous_page
async
¶
previous_page() -> AsyncCursorPage[_T]
Fetches the preceding page. Raises StopAsyncIteration on the first page.
iter_pages
async
¶
iter_pages() -> AsyncIterator[AsyncCursorPage[_T]]
Yields this page and then each following page.
AsyncPaginator
¶
AsyncPaginator(
client: AsyncAPIClient,
options: RequestOptions,
response_type: Any,
)
Bases: Generic[_T]
Returned by async list methods.
await it for the first page, or async for over it to walk every item across pages.
Stream
¶
Bases: _StreamBase[_T]
A synchronous stream of decoded events.
Iterate it to receive events. Close it, or use it as a context manager, to release the connection::
with client.event.subscribe() as events:
for event in events:
...
AsyncStream
¶
Bases: _StreamBase[_T]
An asynchronous stream of decoded events.
Iterate it with async for. Close it, or use it as an async context manager, to release the connection::
async with await client.event.subscribe() as events:
async for event in events:
...
Raw responses¶
Returned by with_raw_response and with_streaming_response on every resource. See
Accessing raw response data.
APIResponse
¶
Bases: _BaseAPIResponse[_R]
An HTTP response from a sync with_raw_response / with_streaming_response call.
parse
¶
Returns the value the plain method call would have returned, reading the body first if needed.
For event-stream endpoints this is the :class:~opencode.Stream, which consumes the body as you iterate.
iter_bytes
¶
Iterates over the body in byte chunks, decoding any content encoding.
iter_text
¶
Iterates over the body as decoded text chunks.
AsyncAPIResponse
¶
Bases: _BaseAPIResponse[_R]
An HTTP response from an async with_raw_response / with_streaming_response call.
parse
async
¶
Returns the value the plain method call would have returned, reading the body first if needed.
For event-stream endpoints this is the :class:~opencode.AsyncStream, which consumes the body as you
iterate.
iter_bytes
async
¶
iter_bytes(
chunk_size: int | None = None,
) -> AsyncIterator[bytes]
Iterates over the body in byte chunks, decoding any content encoding.
iter_text
async
¶
iter_text(
chunk_size: int | None = None,
) -> AsyncIterator[str]
Iterates over the body as decoded text chunks.