Skip to content

Commit f58065b

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): manual updates (#43)
1 parent 1e6ad9f commit f58065b

File tree

155 files changed

+5099
-5235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+5099
-5235
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 69
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/datamini%2Fasktable-4bee800ad604492e6ee5776c10e1668037755aeaae6ff6faa2d09a0c3763eeee.yml
1+
configured_endpoints: 81
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/datamini%2Fasktable-f78191153cae54be3e273ca76fbb91453dec4696f00fc6d679ca2ffc3d533ede.yml

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ from asktable import Asktable
2828

2929
client = Asktable()
3030

31-
datasource = client.datasources.list()
32-
print(datasource.items)
31+
datasource = client.datasources.create(
32+
engine="mysql",
33+
)
34+
print(datasource.id)
3335
```
3436

3537
While you can provide an `api_key` keyword argument,
@@ -49,8 +51,10 @@ client = AsyncAsktable()
4951

5052

5153
async def main() -> None:
52-
datasource = await client.datasources.list()
53-
print(datasource.items)
54+
datasource = await client.datasources.create(
55+
engine="mysql",
56+
)
57+
print(datasource.id)
5458

5559

5660
asyncio.run(main())
@@ -67,6 +71,67 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
6771

6872
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`.
6973

74+
## Pagination
75+
76+
List methods in the Asktable API are paginated.
77+
78+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
79+
80+
```python
81+
from asktable import Asktable
82+
83+
client = Asktable()
84+
85+
all_datasources = []
86+
# Automatically fetches more pages as needed.
87+
for datasource in client.datasources.list():
88+
# Do something with datasource here
89+
all_datasources.append(datasource)
90+
print(all_datasources)
91+
```
92+
93+
Or, asynchronously:
94+
95+
```python
96+
import asyncio
97+
from asktable import AsyncAsktable
98+
99+
client = AsyncAsktable()
100+
101+
102+
async def main() -> None:
103+
all_datasources = []
104+
# Iterate through items across all pages, issuing requests as needed.
105+
async for datasource in client.datasources.list():
106+
all_datasources.append(datasource)
107+
print(all_datasources)
108+
109+
110+
asyncio.run(main())
111+
```
112+
113+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
114+
115+
```python
116+
first_page = await client.datasources.list()
117+
if first_page.has_next_page():
118+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
119+
next_page = await first_page.get_next_page()
120+
print(f"number of items we just fetched: {len(next_page.items)}")
121+
122+
# Remove `await` for non-async usage.
123+
```
124+
125+
Or just work directly with the returned data:
126+
127+
```python
128+
first_page = await client.datasources.list()
129+
for datasource in first_page.items:
130+
print(datasource.id)
131+
132+
# Remove `await` for non-async usage.
133+
```
134+
70135
## Handling errors
71136

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

api.md

Lines changed: 120 additions & 182 deletions
Large diffs are not rendered by default.

src/asktable/_client.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747

4848
class Asktable(SyncAPIClient):
49+
sys: resources.SysResource
4950
securetunnels: resources.SecuretunnelsResource
5051
roles: resources.RolesResource
5152
policies: resources.PoliciesResource
@@ -57,7 +58,7 @@ class Asktable(SyncAPIClient):
5758
single_turn: resources.SingleTurnResource
5859
caches: resources.CachesResource
5960
integration: resources.IntegrationResource
60-
sys: resources.SysResource
61+
business_glossary: resources.BusinessGlossaryResource
6162
with_raw_response: AsktableWithRawResponse
6263
with_streaming_response: AsktableWithStreamedResponse
6364

@@ -102,7 +103,7 @@ def __init__(
102103
if base_url is None:
103104
base_url = os.environ.get("ASKTABLE_BASE_URL")
104105
if base_url is None:
105-
base_url = f"/v1"
106+
base_url = f"https://api.asktable.com/v1"
106107

107108
super().__init__(
108109
version=__version__,
@@ -115,6 +116,7 @@ def __init__(
115116
_strict_response_validation=_strict_response_validation,
116117
)
117118

119+
self.sys = resources.SysResource(self)
118120
self.securetunnels = resources.SecuretunnelsResource(self)
119121
self.roles = resources.RolesResource(self)
120122
self.policies = resources.PoliciesResource(self)
@@ -126,7 +128,7 @@ def __init__(
126128
self.single_turn = resources.SingleTurnResource(self)
127129
self.caches = resources.CachesResource(self)
128130
self.integration = resources.IntegrationResource(self)
129-
self.sys = resources.SysResource(self)
131+
self.business_glossary = resources.BusinessGlossaryResource(self)
130132
self.with_raw_response = AsktableWithRawResponse(self)
131133
self.with_streaming_response = AsktableWithStreamedResponse(self)
132134

@@ -236,6 +238,7 @@ def _make_status_error(
236238

237239

238240
class AsyncAsktable(AsyncAPIClient):
241+
sys: resources.AsyncSysResource
239242
securetunnels: resources.AsyncSecuretunnelsResource
240243
roles: resources.AsyncRolesResource
241244
policies: resources.AsyncPoliciesResource
@@ -247,7 +250,7 @@ class AsyncAsktable(AsyncAPIClient):
247250
single_turn: resources.AsyncSingleTurnResource
248251
caches: resources.AsyncCachesResource
249252
integration: resources.AsyncIntegrationResource
250-
sys: resources.AsyncSysResource
253+
business_glossary: resources.AsyncBusinessGlossaryResource
251254
with_raw_response: AsyncAsktableWithRawResponse
252255
with_streaming_response: AsyncAsktableWithStreamedResponse
253256

@@ -292,7 +295,7 @@ def __init__(
292295
if base_url is None:
293296
base_url = os.environ.get("ASKTABLE_BASE_URL")
294297
if base_url is None:
295-
base_url = f"/v1"
298+
base_url = f"https://api.asktable.com/v1"
296299

297300
super().__init__(
298301
version=__version__,
@@ -305,6 +308,7 @@ def __init__(
305308
_strict_response_validation=_strict_response_validation,
306309
)
307310

311+
self.sys = resources.AsyncSysResource(self)
308312
self.securetunnels = resources.AsyncSecuretunnelsResource(self)
309313
self.roles = resources.AsyncRolesResource(self)
310314
self.policies = resources.AsyncPoliciesResource(self)
@@ -316,7 +320,7 @@ def __init__(
316320
self.single_turn = resources.AsyncSingleTurnResource(self)
317321
self.caches = resources.AsyncCachesResource(self)
318322
self.integration = resources.AsyncIntegrationResource(self)
319-
self.sys = resources.AsyncSysResource(self)
323+
self.business_glossary = resources.AsyncBusinessGlossaryResource(self)
320324
self.with_raw_response = AsyncAsktableWithRawResponse(self)
321325
self.with_streaming_response = AsyncAsktableWithStreamedResponse(self)
322326

@@ -427,6 +431,7 @@ def _make_status_error(
427431

428432
class AsktableWithRawResponse:
429433
def __init__(self, client: Asktable) -> None:
434+
self.sys = resources.SysResourceWithRawResponse(client.sys)
430435
self.securetunnels = resources.SecuretunnelsResourceWithRawResponse(client.securetunnels)
431436
self.roles = resources.RolesResourceWithRawResponse(client.roles)
432437
self.policies = resources.PoliciesResourceWithRawResponse(client.policies)
@@ -438,11 +443,12 @@ def __init__(self, client: Asktable) -> None:
438443
self.single_turn = resources.SingleTurnResourceWithRawResponse(client.single_turn)
439444
self.caches = resources.CachesResourceWithRawResponse(client.caches)
440445
self.integration = resources.IntegrationResourceWithRawResponse(client.integration)
441-
self.sys = resources.SysResourceWithRawResponse(client.sys)
446+
self.business_glossary = resources.BusinessGlossaryResourceWithRawResponse(client.business_glossary)
442447

443448

444449
class AsyncAsktableWithRawResponse:
445450
def __init__(self, client: AsyncAsktable) -> None:
451+
self.sys = resources.AsyncSysResourceWithRawResponse(client.sys)
446452
self.securetunnels = resources.AsyncSecuretunnelsResourceWithRawResponse(client.securetunnels)
447453
self.roles = resources.AsyncRolesResourceWithRawResponse(client.roles)
448454
self.policies = resources.AsyncPoliciesResourceWithRawResponse(client.policies)
@@ -454,11 +460,12 @@ def __init__(self, client: AsyncAsktable) -> None:
454460
self.single_turn = resources.AsyncSingleTurnResourceWithRawResponse(client.single_turn)
455461
self.caches = resources.AsyncCachesResourceWithRawResponse(client.caches)
456462
self.integration = resources.AsyncIntegrationResourceWithRawResponse(client.integration)
457-
self.sys = resources.AsyncSysResourceWithRawResponse(client.sys)
463+
self.business_glossary = resources.AsyncBusinessGlossaryResourceWithRawResponse(client.business_glossary)
458464

459465

460466
class AsktableWithStreamedResponse:
461467
def __init__(self, client: Asktable) -> None:
468+
self.sys = resources.SysResourceWithStreamingResponse(client.sys)
462469
self.securetunnels = resources.SecuretunnelsResourceWithStreamingResponse(client.securetunnels)
463470
self.roles = resources.RolesResourceWithStreamingResponse(client.roles)
464471
self.policies = resources.PoliciesResourceWithStreamingResponse(client.policies)
@@ -470,11 +477,12 @@ def __init__(self, client: Asktable) -> None:
470477
self.single_turn = resources.SingleTurnResourceWithStreamingResponse(client.single_turn)
471478
self.caches = resources.CachesResourceWithStreamingResponse(client.caches)
472479
self.integration = resources.IntegrationResourceWithStreamingResponse(client.integration)
473-
self.sys = resources.SysResourceWithStreamingResponse(client.sys)
480+
self.business_glossary = resources.BusinessGlossaryResourceWithStreamingResponse(client.business_glossary)
474481

475482

476483
class AsyncAsktableWithStreamedResponse:
477484
def __init__(self, client: AsyncAsktable) -> None:
485+
self.sys = resources.AsyncSysResourceWithStreamingResponse(client.sys)
478486
self.securetunnels = resources.AsyncSecuretunnelsResourceWithStreamingResponse(client.securetunnels)
479487
self.roles = resources.AsyncRolesResourceWithStreamingResponse(client.roles)
480488
self.policies = resources.AsyncPoliciesResourceWithStreamingResponse(client.policies)
@@ -486,7 +494,7 @@ def __init__(self, client: AsyncAsktable) -> None:
486494
self.single_turn = resources.AsyncSingleTurnResourceWithStreamingResponse(client.single_turn)
487495
self.caches = resources.AsyncCachesResourceWithStreamingResponse(client.caches)
488496
self.integration = resources.AsyncIntegrationResourceWithStreamingResponse(client.integration)
489-
self.sys = resources.AsyncSysResourceWithStreamingResponse(client.sys)
497+
self.business_glossary = resources.AsyncBusinessGlossaryResourceWithStreamingResponse(client.business_glossary)
490498

491499

492500
Client = Asktable

src/asktable/pagination.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from typing import List, Generic, TypeVar, Optional, cast
4+
from typing_extensions import override
5+
6+
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
7+
8+
__all__ = ["SyncPage", "AsyncPage"]
9+
10+
_T = TypeVar("_T")
11+
12+
13+
class SyncPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
14+
items: List[_T]
15+
page: Optional[int] = None
16+
size: Optional[int] = None
17+
pages: Optional[int] = None
18+
19+
@override
20+
def _get_page_items(self) -> List[_T]:
21+
items = self.items
22+
if not items:
23+
return []
24+
return items
25+
26+
@override
27+
def next_page_info(self) -> Optional[PageInfo]:
28+
last_page = cast("int | None", self._options.params.get("page")) or 1
29+
30+
return PageInfo(params={"page": last_page + 1})
31+
32+
33+
class AsyncPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
34+
items: List[_T]
35+
page: Optional[int] = None
36+
size: Optional[int] = None
37+
pages: Optional[int] = None
38+
39+
@override
40+
def _get_page_items(self) -> List[_T]:
41+
items = self.items
42+
if not items:
43+
return []
44+
return items
45+
46+
@override
47+
def next_page_info(self) -> Optional[PageInfo]:
48+
last_page = cast("int | None", self._options.params.get("page")) or 1
49+
50+
return PageInfo(params={"page": last_page + 1})

src/asktable/resources/__init__.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,22 @@
9696
SecuretunnelsResourceWithStreamingResponse,
9797
AsyncSecuretunnelsResourceWithStreamingResponse,
9898
)
99+
from .business_glossary import (
100+
BusinessGlossaryResource,
101+
AsyncBusinessGlossaryResource,
102+
BusinessGlossaryResourceWithRawResponse,
103+
AsyncBusinessGlossaryResourceWithRawResponse,
104+
BusinessGlossaryResourceWithStreamingResponse,
105+
AsyncBusinessGlossaryResourceWithStreamingResponse,
106+
)
99107

100108
__all__ = [
109+
"SysResource",
110+
"AsyncSysResource",
111+
"SysResourceWithRawResponse",
112+
"AsyncSysResourceWithRawResponse",
113+
"SysResourceWithStreamingResponse",
114+
"AsyncSysResourceWithStreamingResponse",
101115
"SecuretunnelsResource",
102116
"AsyncSecuretunnelsResource",
103117
"SecuretunnelsResourceWithRawResponse",
@@ -164,10 +178,10 @@
164178
"AsyncIntegrationResourceWithRawResponse",
165179
"IntegrationResourceWithStreamingResponse",
166180
"AsyncIntegrationResourceWithStreamingResponse",
167-
"SysResource",
168-
"AsyncSysResource",
169-
"SysResourceWithRawResponse",
170-
"AsyncSysResourceWithRawResponse",
171-
"SysResourceWithStreamingResponse",
172-
"AsyncSysResourceWithStreamingResponse",
181+
"BusinessGlossaryResource",
182+
"AsyncBusinessGlossaryResource",
183+
"BusinessGlossaryResourceWithRawResponse",
184+
"AsyncBusinessGlossaryResourceWithRawResponse",
185+
"BusinessGlossaryResourceWithStreamingResponse",
186+
"AsyncBusinessGlossaryResourceWithStreamingResponse",
173187
]

0 commit comments

Comments
 (0)