Skip to content

Commit 7cfedb5

Browse files
chore(internal): codegen related update (#48)
1 parent 95360bc commit 7cfedb5

File tree

5 files changed

+24
-99
lines changed

5 files changed

+24
-99
lines changed

README.md

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -88,77 +88,6 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
8888

8989
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`.
9090

91-
## Pagination
92-
93-
List methods in the ZeroEntropy API are paginated.
94-
95-
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
96-
97-
```python
98-
from zeroentropy import ZeroEntropy
99-
100-
client = ZeroEntropy()
101-
102-
all_documents = []
103-
# Automatically fetches more pages as needed.
104-
for document in client.documents.get_info_list(
105-
collection_name="example_collection",
106-
):
107-
# Do something with document here
108-
all_documents.append(document)
109-
print(all_documents)
110-
```
111-
112-
Or, asynchronously:
113-
114-
```python
115-
import asyncio
116-
from zeroentropy import AsyncZeroEntropy
117-
118-
client = AsyncZeroEntropy()
119-
120-
121-
async def main() -> None:
122-
all_documents = []
123-
# Iterate through items across all pages, issuing requests as needed.
124-
async for document in client.documents.get_info_list(
125-
collection_name="example_collection",
126-
):
127-
all_documents.append(document)
128-
print(all_documents)
129-
130-
131-
asyncio.run(main())
132-
```
133-
134-
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
135-
136-
```python
137-
first_page = await client.documents.get_info_list(
138-
collection_name="example_collection",
139-
)
140-
if first_page.has_next_page():
141-
print(f"will fetch next page using these details: {first_page.next_page_info()}")
142-
next_page = await first_page.get_next_page()
143-
print(f"number of items we just fetched: {len(next_page.documents)}")
144-
145-
# Remove `await` for non-async usage.
146-
```
147-
148-
Or just work directly with the returned data:
149-
150-
```python
151-
first_page = await client.documents.get_info_list(
152-
collection_name="example_collection",
153-
)
154-
155-
print(f"next page cursor: {first_page.id_gt}") # => "next page cursor: ..."
156-
for document in first_page.documents:
157-
print(document.id)
158-
159-
# Remove `await` for non-async usage.
160-
```
161-
16291
## Handling errors
16392

16493
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.

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Methods:
6161
- <code title="post /documents/delete-document">client.documents.<a href="./src/zeroentropy/resources/documents.py">delete</a>(\*\*<a href="src/zeroentropy/types/document_delete_params.py">params</a>) -> <a href="./src/zeroentropy/types/document_delete_response.py">DocumentDeleteResponse</a></code>
6262
- <code title="post /documents/add-document">client.documents.<a href="./src/zeroentropy/resources/documents.py">add</a>(\*\*<a href="src/zeroentropy/types/document_add_params.py">params</a>) -> <a href="./src/zeroentropy/types/document_add_response.py">DocumentAddResponse</a></code>
6363
- <code title="post /documents/get-document-info">client.documents.<a href="./src/zeroentropy/resources/documents.py">get_info</a>(\*\*<a href="src/zeroentropy/types/document_get_info_params.py">params</a>) -> <a href="./src/zeroentropy/types/document_get_info_response.py">DocumentGetInfoResponse</a></code>
64-
- <code title="post /documents/get-document-info-list">client.documents.<a href="./src/zeroentropy/resources/documents.py">get_info_list</a>(\*\*<a href="src/zeroentropy/types/document_get_info_list_params.py">params</a>) -> <a href="./src/zeroentropy/types/document_get_info_list_response.py">SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse]</a></code>
64+
- <code title="post /documents/get-document-info-list">client.documents.<a href="./src/zeroentropy/resources/documents.py">get_info_list</a>(\*\*<a href="src/zeroentropy/types/document_get_info_list_params.py">params</a>) -> <a href="./src/zeroentropy/types/document_get_info_list_response.py">DocumentGetInfoListResponse</a></code>
6565
- <code title="post /documents/get-page-info">client.documents.<a href="./src/zeroentropy/resources/documents.py">get_page_info</a>(\*\*<a href="src/zeroentropy/types/document_get_page_info_params.py">params</a>) -> <a href="./src/zeroentropy/types/document_get_page_info_response.py">DocumentGetPageInfoResponse</a></code>
6666

6767
# Queries

src/zeroentropy/resources/documents.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
async_to_raw_response_wrapper,
2828
async_to_streamed_response_wrapper,
2929
)
30-
from ..pagination import SyncGetDocumentInfoListCursor, AsyncGetDocumentInfoListCursor
31-
from .._base_client import AsyncPaginator, make_request_options
30+
from .._base_client import make_request_options
3231
from ..types.document_add_response import DocumentAddResponse
3332
from ..types.document_delete_response import DocumentDeleteResponse
3433
from ..types.document_update_response import DocumentUpdateResponse
@@ -317,7 +316,7 @@ def get_info_list(
317316
extra_query: Query | None = None,
318317
extra_body: Body | None = None,
319318
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
320-
) -> SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse]:
319+
) -> DocumentGetInfoListResponse:
321320
"""
322321
Retrives a list of document metadata information that matches the provided
323322
filters.
@@ -346,9 +345,8 @@ def get_info_list(
346345
347346
timeout: Override the client-level default timeout for this request, in seconds
348347
"""
349-
return self._get_api_list(
348+
return self._post(
350349
"/documents/get-document-info-list",
351-
page=SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse],
352350
body=maybe_transform(
353351
{
354352
"collection_name": collection_name,
@@ -360,8 +358,7 @@ def get_info_list(
360358
options=make_request_options(
361359
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
362360
),
363-
model=DocumentGetInfoListResponse,
364-
method="post",
361+
cast_to=DocumentGetInfoListResponse,
365362
)
366363

367364
def get_page_info(
@@ -693,7 +690,7 @@ async def get_info(
693690
cast_to=DocumentGetInfoResponse,
694691
)
695692

696-
def get_info_list(
693+
async def get_info_list(
697694
self,
698695
*,
699696
collection_name: str,
@@ -705,7 +702,7 @@ def get_info_list(
705702
extra_query: Query | None = None,
706703
extra_body: Body | None = None,
707704
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
708-
) -> AsyncPaginator[DocumentGetInfoListResponse, AsyncGetDocumentInfoListCursor[DocumentGetInfoListResponse]]:
705+
) -> DocumentGetInfoListResponse:
709706
"""
710707
Retrives a list of document metadata information that matches the provided
711708
filters.
@@ -734,10 +731,9 @@ def get_info_list(
734731
735732
timeout: Override the client-level default timeout for this request, in seconds
736733
"""
737-
return self._get_api_list(
734+
return await self._post(
738735
"/documents/get-document-info-list",
739-
page=AsyncGetDocumentInfoListCursor[DocumentGetInfoListResponse],
740-
body=maybe_transform(
736+
body=await async_maybe_transform(
741737
{
742738
"collection_name": collection_name,
743739
"id_gt": id_gt,
@@ -748,8 +744,7 @@ def get_info_list(
748744
options=make_request_options(
749745
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
750746
),
751-
model=DocumentGetInfoListResponse,
752-
method="post",
747+
cast_to=DocumentGetInfoListResponse,
753748
)
754749

755750
async def get_page_info(

src/zeroentropy/types/document_get_info_list_response.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from .._models import BaseModel
77

8-
__all__ = ["DocumentGetInfoListResponse"]
8+
__all__ = ["DocumentGetInfoListResponse", "Document"]
99

1010

11-
class DocumentGetInfoListResponse(BaseModel):
11+
class Document(BaseModel):
1212
id: str
1313

1414
collection_name: str
@@ -27,3 +27,7 @@ class DocumentGetInfoListResponse(BaseModel):
2727
"""
2828

2929
path: str
30+
31+
32+
class DocumentGetInfoListResponse(BaseModel):
33+
documents: List[Document]

tests/api_resources/test_documents.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
DocumentGetInfoListResponse,
1818
DocumentGetPageInfoResponse,
1919
)
20-
from zeroentropy.pagination import SyncGetDocumentInfoListCursor, AsyncGetDocumentInfoListCursor
2120

2221
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
2322

@@ -210,7 +209,7 @@ def test_method_get_info_list(self, client: ZeroEntropy) -> None:
210209
document = client.documents.get_info_list(
211210
collection_name="collection_name",
212211
)
213-
assert_matches_type(SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
212+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
214213

215214
@parametrize
216215
def test_method_get_info_list_with_all_params(self, client: ZeroEntropy) -> None:
@@ -219,7 +218,7 @@ def test_method_get_info_list_with_all_params(self, client: ZeroEntropy) -> None
219218
id_gt="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
220219
limit=0,
221220
)
222-
assert_matches_type(SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
221+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
223222

224223
@parametrize
225224
def test_raw_response_get_info_list(self, client: ZeroEntropy) -> None:
@@ -230,7 +229,7 @@ def test_raw_response_get_info_list(self, client: ZeroEntropy) -> None:
230229
assert response.is_closed is True
231230
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
232231
document = response.parse()
233-
assert_matches_type(SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
232+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
234233

235234
@parametrize
236235
def test_streaming_response_get_info_list(self, client: ZeroEntropy) -> None:
@@ -241,7 +240,7 @@ def test_streaming_response_get_info_list(self, client: ZeroEntropy) -> None:
241240
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
242241

243242
document = response.parse()
244-
assert_matches_type(SyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
243+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
245244

246245
assert cast(Any, response.is_closed) is True
247246

@@ -481,7 +480,7 @@ async def test_method_get_info_list(self, async_client: AsyncZeroEntropy) -> Non
481480
document = await async_client.documents.get_info_list(
482481
collection_name="collection_name",
483482
)
484-
assert_matches_type(AsyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
483+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
485484

486485
@parametrize
487486
async def test_method_get_info_list_with_all_params(self, async_client: AsyncZeroEntropy) -> None:
@@ -490,7 +489,7 @@ async def test_method_get_info_list_with_all_params(self, async_client: AsyncZer
490489
id_gt="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
491490
limit=0,
492491
)
493-
assert_matches_type(AsyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
492+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
494493

495494
@parametrize
496495
async def test_raw_response_get_info_list(self, async_client: AsyncZeroEntropy) -> None:
@@ -501,7 +500,7 @@ async def test_raw_response_get_info_list(self, async_client: AsyncZeroEntropy)
501500
assert response.is_closed is True
502501
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
503502
document = await response.parse()
504-
assert_matches_type(AsyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"])
503+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
505504

506505
@parametrize
507506
async def test_streaming_response_get_info_list(self, async_client: AsyncZeroEntropy) -> None:
@@ -512,9 +511,7 @@ async def test_streaming_response_get_info_list(self, async_client: AsyncZeroEnt
512511
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
513512

514513
document = await response.parse()
515-
assert_matches_type(
516-
AsyncGetDocumentInfoListCursor[DocumentGetInfoListResponse], document, path=["response"]
517-
)
514+
assert_matches_type(DocumentGetInfoListResponse, document, path=["response"])
518515

519516
assert cast(Any, response.is_closed) is True
520517

0 commit comments

Comments
 (0)