Skip to content
Merged
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
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,77 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ

Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.

## Pagination

List methods in the Zeroentropy API are paginated.

This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:

```python
from zeroentropy import Zeroentropy

client = Zeroentropy()

all_documents = []
# Automatically fetches more pages as needed.
for document in client.documents.get_info_list(
collection_name="collection_name",
):
# Do something with document here
all_documents.append(document)
print(all_documents)
```

Or, asynchronously:

```python
import asyncio
from zeroentropy import AsyncZeroentropy

client = AsyncZeroentropy()


async def main() -> None:
all_documents = []
# Iterate through items across all pages, issuing requests as needed.
async for document in client.documents.get_info_list(
collection_name="collection_name",
):
all_documents.append(document)
print(all_documents)


asyncio.run(main())
```

Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:

```python
first_page = await client.documents.get_info_list(
collection_name="collection_name",
)
if first_page.has_next_page():
print(f"will fetch next page using these details: {first_page.next_page_info()}")
next_page = await first_page.get_next_page()
print(f"number of items we just fetched: {len(next_page.documents)}")

# Remove `await` for non-async usage.
```

Or just work directly with the returned data:

```python
first_page = await client.documents.get_info_list(
collection_name="collection_name",
)

print(f"next page cursor: {first_page.id_gt}") # => "next page cursor: ..."
for document in first_page.documents:
print(document.id)

# Remove `await` for non-async usage.
```

## Handling errors

When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `zeroentropy.APIConnectionError` is raised.
Expand Down