Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ with ProoflineClient() as client:
print(row)
```

When page metadata and raw text are not needed, `iter_export_rows` yields decoded rows directly while fetching pages lazily:

```python
with ProoflineClient() as client:
for row in client.iter_export_rows(
UUID(os.environ["PROOFLINE_ORGANIZATION_ID"]),
"reviews",
from_time="2026-10-01T00:00:00Z",
to_time="2026-10-25T00:00:00Z",
):
print(row)
```

The async client exposes the same method as an async iterator. Both methods keep the page bound and cursor-cycle checks used by `iter_export_pages`.

Use `async for` with `AsyncProoflineClient`. Each yielded page retains its raw text, decoded rows, and metadata; CSV pages retain their individual headers. Pass `cursor=` to resume an export. Iteration stops only when the server omits the next cursor, including when an intermediate page has no rows. Empty or repeated continuation cursors raise `ProoflineError` with type `urn:proofline:sdk:invalid-pagination`, and the page that carries such a cursor is never yielded. The default bound is 100 pages; set `max_pages` to an integer from 1 to 1000. Exhausting that bound while a cursor remains raises `urn:proofline:sdk:pagination-limit`, so a partial export cannot silently appear complete. Stop iteration early when only a prefix is needed.

## Coverage uploads
Expand Down
51 changes: 51 additions & 0 deletions proofline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,31 @@ def iter_export_pages(
return
raise _pagination_limit("Export")

def iter_export_rows(
self,
organization_id: UUID,
dataset: ExportDataset,
*,
from_time: str,
to_time: str,
format: ExportFormat = "ndjson",
cursor: str | None = None,
group_by: str | None = None,
max_pages: int = 100,
) -> Iterator[dict[str, Any]]:
"""Stream decoded rows across pages without exposing page boundaries."""
for page in self.iter_export_pages(
organization_id,
dataset,
from_time=from_time,
to_time=to_time,
format=format,
cursor=cursor,
group_by=group_by,
max_pages=max_pages,
):
yield from page.rows

def list_reviews(self, organization_id: UUID, **filters: Unpack[ReviewFilters]) -> ReviewPage:
return self._call(list_reviews.sync_detailed, ReviewPage, organization_id, **filters)

Expand Down Expand Up @@ -705,6 +730,32 @@ async def iter_export_pages(
return
raise _pagination_limit("Export")

async def iter_export_rows(
self,
organization_id: UUID,
dataset: ExportDataset,
*,
from_time: str,
to_time: str,
format: ExportFormat = "ndjson",
cursor: str | None = None,
group_by: str | None = None,
max_pages: int = 100,
) -> AsyncIterator[dict[str, Any]]:
"""Stream decoded rows across pages without exposing page boundaries."""
async for page in self.iter_export_pages(
organization_id,
dataset,
from_time=from_time,
to_time=to_time,
format=format,
cursor=cursor,
group_by=group_by,
max_pages=max_pages,
):
for row in page.rows:
yield row

async def list_reviews(
self, organization_id: UUID, **filters: Unpack[ReviewFilters]
) -> ReviewPage:
Expand Down
46 changes: 46 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,52 @@ def respond(request: Request, index: int) -> Reply:
assert len(server.requests) == 2


@MODES
async def test_export_row_iterator_flattens_pages_lazily(mode: str) -> None:
def respond(request: Request, index: int) -> Reply:
query = parse_qs(urlsplit(request.path).query)
assert query.get("cursor") == (["second"] if index else None)
headers = {
"Content-Type": "application/x-ndjson",
"X-Proofline-Export-Version": "1",
"X-Proofline-Export-Settled-Until": "2026-10-25T00:00:00Z",
}
if index == 0:
headers["X-Proofline-Export-Next-Cursor"] = "second"
body = (
b'{"dataset_version":1,"claim":"first"}\n'
b'{"dataset_version":1,"claim":"second"}\n'
)
else:
body = b'{"dataset_version":1,"claim":"third"}\n'
return Reply(
body=body,
headers=headers,
)

with Server(respond) as server:
async with session(mode, server.url) as client:
rows = client.iter_export_rows(
ORG,
"reviews",
from_time="2026-10-01T00:00:00Z",
to_time="2026-10-25T00:00:00Z",
)
assert not server.requests
assert (await next_export(rows))["claim"] == "first"
assert len(server.requests) == 1
assert (await next_export(rows))["claim"] == "second"
assert len(server.requests) == 1
assert (await next_export(rows))["claim"] == "third"
if mode == "sync":
with pytest.raises(StopIteration):
next(rows)
else:
with pytest.raises(StopAsyncIteration):
await anext(rows)
assert len(server.requests) == 2


@MODES
@pytest.mark.parametrize("failure", ["empty", "repeat", "resume", "cycle", "bound", "refused"])
async def test_export_iterator_refuses_invalid_continuations_and_bounds(
Expand Down