From 38f9400eb577eaba073f2f93151e4df6c819c25c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Jan 2025 05:43:22 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- README.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/README.md b/README.md index 4b5b5b7..cf55225 100644 --- a/README.md +++ b/README.md @@ -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.