Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 69
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/datamini%2Fasktable-4bee800ad604492e6ee5776c10e1668037755aeaae6ff6faa2d09a0c3763eeee.yml
configured_endpoints: 81
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/datamini%2Fasktable-f78191153cae54be3e273ca76fbb91453dec4696f00fc6d679ca2ffc3d533ede.yml
73 changes: 69 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ from asktable import Asktable

client = Asktable()

datasource = client.datasources.list()
print(datasource.items)
datasource = client.datasources.create(
engine="mysql",
)
print(datasource.id)
```

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


async def main() -> None:
datasource = await client.datasources.list()
print(datasource.items)
datasource = await client.datasources.create(
engine="mysql",
)
print(datasource.id)


asyncio.run(main())
Expand All @@ -67,6 +71,67 @@ 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 Asktable 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 asktable import Asktable

client = Asktable()

all_datasources = []
# Automatically fetches more pages as needed.
for datasource in client.datasources.list():
# Do something with datasource here
all_datasources.append(datasource)
print(all_datasources)
```

Or, asynchronously:

```python
import asyncio
from asktable import AsyncAsktable

client = AsyncAsktable()


async def main() -> None:
all_datasources = []
# Iterate through items across all pages, issuing requests as needed.
async for datasource in client.datasources.list():
all_datasources.append(datasource)
print(all_datasources)


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.datasources.list()
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.items)}")

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

Or just work directly with the returned data:

```python
first_page = await client.datasources.list()
for datasource in first_page.items:
print(datasource.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 `asktable.APIConnectionError` is raised.
Expand Down
302 changes: 120 additions & 182 deletions api.md

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/asktable/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@


class Asktable(SyncAPIClient):
sys: resources.SysResource
securetunnels: resources.SecuretunnelsResource
roles: resources.RolesResource
policies: resources.PoliciesResource
Expand All @@ -57,7 +58,7 @@ class Asktable(SyncAPIClient):
single_turn: resources.SingleTurnResource
caches: resources.CachesResource
integration: resources.IntegrationResource
sys: resources.SysResource
business_glossary: resources.BusinessGlossaryResource
with_raw_response: AsktableWithRawResponse
with_streaming_response: AsktableWithStreamedResponse

Expand Down Expand Up @@ -102,7 +103,7 @@ def __init__(
if base_url is None:
base_url = os.environ.get("ASKTABLE_BASE_URL")
if base_url is None:
base_url = f"/v1"
base_url = f"https://api.asktable.com/v1"

super().__init__(
version=__version__,
Expand All @@ -115,6 +116,7 @@ def __init__(
_strict_response_validation=_strict_response_validation,
)

self.sys = resources.SysResource(self)
self.securetunnels = resources.SecuretunnelsResource(self)
self.roles = resources.RolesResource(self)
self.policies = resources.PoliciesResource(self)
Expand All @@ -126,7 +128,7 @@ def __init__(
self.single_turn = resources.SingleTurnResource(self)
self.caches = resources.CachesResource(self)
self.integration = resources.IntegrationResource(self)
self.sys = resources.SysResource(self)
self.business_glossary = resources.BusinessGlossaryResource(self)
self.with_raw_response = AsktableWithRawResponse(self)
self.with_streaming_response = AsktableWithStreamedResponse(self)

Expand Down Expand Up @@ -236,6 +238,7 @@ def _make_status_error(


class AsyncAsktable(AsyncAPIClient):
sys: resources.AsyncSysResource
securetunnels: resources.AsyncSecuretunnelsResource
roles: resources.AsyncRolesResource
policies: resources.AsyncPoliciesResource
Expand All @@ -247,7 +250,7 @@ class AsyncAsktable(AsyncAPIClient):
single_turn: resources.AsyncSingleTurnResource
caches: resources.AsyncCachesResource
integration: resources.AsyncIntegrationResource
sys: resources.AsyncSysResource
business_glossary: resources.AsyncBusinessGlossaryResource
with_raw_response: AsyncAsktableWithRawResponse
with_streaming_response: AsyncAsktableWithStreamedResponse

Expand Down Expand Up @@ -292,7 +295,7 @@ def __init__(
if base_url is None:
base_url = os.environ.get("ASKTABLE_BASE_URL")
if base_url is None:
base_url = f"/v1"
base_url = f"https://api.asktable.com/v1"

super().__init__(
version=__version__,
Expand All @@ -305,6 +308,7 @@ def __init__(
_strict_response_validation=_strict_response_validation,
)

self.sys = resources.AsyncSysResource(self)
self.securetunnels = resources.AsyncSecuretunnelsResource(self)
self.roles = resources.AsyncRolesResource(self)
self.policies = resources.AsyncPoliciesResource(self)
Expand All @@ -316,7 +320,7 @@ def __init__(
self.single_turn = resources.AsyncSingleTurnResource(self)
self.caches = resources.AsyncCachesResource(self)
self.integration = resources.AsyncIntegrationResource(self)
self.sys = resources.AsyncSysResource(self)
self.business_glossary = resources.AsyncBusinessGlossaryResource(self)
self.with_raw_response = AsyncAsktableWithRawResponse(self)
self.with_streaming_response = AsyncAsktableWithStreamedResponse(self)

Expand Down Expand Up @@ -427,6 +431,7 @@ def _make_status_error(

class AsktableWithRawResponse:
def __init__(self, client: Asktable) -> None:
self.sys = resources.SysResourceWithRawResponse(client.sys)
self.securetunnels = resources.SecuretunnelsResourceWithRawResponse(client.securetunnels)
self.roles = resources.RolesResourceWithRawResponse(client.roles)
self.policies = resources.PoliciesResourceWithRawResponse(client.policies)
Expand All @@ -438,11 +443,12 @@ def __init__(self, client: Asktable) -> None:
self.single_turn = resources.SingleTurnResourceWithRawResponse(client.single_turn)
self.caches = resources.CachesResourceWithRawResponse(client.caches)
self.integration = resources.IntegrationResourceWithRawResponse(client.integration)
self.sys = resources.SysResourceWithRawResponse(client.sys)
self.business_glossary = resources.BusinessGlossaryResourceWithRawResponse(client.business_glossary)


class AsyncAsktableWithRawResponse:
def __init__(self, client: AsyncAsktable) -> None:
self.sys = resources.AsyncSysResourceWithRawResponse(client.sys)
self.securetunnels = resources.AsyncSecuretunnelsResourceWithRawResponse(client.securetunnels)
self.roles = resources.AsyncRolesResourceWithRawResponse(client.roles)
self.policies = resources.AsyncPoliciesResourceWithRawResponse(client.policies)
Expand All @@ -454,11 +460,12 @@ def __init__(self, client: AsyncAsktable) -> None:
self.single_turn = resources.AsyncSingleTurnResourceWithRawResponse(client.single_turn)
self.caches = resources.AsyncCachesResourceWithRawResponse(client.caches)
self.integration = resources.AsyncIntegrationResourceWithRawResponse(client.integration)
self.sys = resources.AsyncSysResourceWithRawResponse(client.sys)
self.business_glossary = resources.AsyncBusinessGlossaryResourceWithRawResponse(client.business_glossary)


class AsktableWithStreamedResponse:
def __init__(self, client: Asktable) -> None:
self.sys = resources.SysResourceWithStreamingResponse(client.sys)
self.securetunnels = resources.SecuretunnelsResourceWithStreamingResponse(client.securetunnels)
self.roles = resources.RolesResourceWithStreamingResponse(client.roles)
self.policies = resources.PoliciesResourceWithStreamingResponse(client.policies)
Expand All @@ -470,11 +477,12 @@ def __init__(self, client: Asktable) -> None:
self.single_turn = resources.SingleTurnResourceWithStreamingResponse(client.single_turn)
self.caches = resources.CachesResourceWithStreamingResponse(client.caches)
self.integration = resources.IntegrationResourceWithStreamingResponse(client.integration)
self.sys = resources.SysResourceWithStreamingResponse(client.sys)
self.business_glossary = resources.BusinessGlossaryResourceWithStreamingResponse(client.business_glossary)


class AsyncAsktableWithStreamedResponse:
def __init__(self, client: AsyncAsktable) -> None:
self.sys = resources.AsyncSysResourceWithStreamingResponse(client.sys)
self.securetunnels = resources.AsyncSecuretunnelsResourceWithStreamingResponse(client.securetunnels)
self.roles = resources.AsyncRolesResourceWithStreamingResponse(client.roles)
self.policies = resources.AsyncPoliciesResourceWithStreamingResponse(client.policies)
Expand All @@ -486,7 +494,7 @@ def __init__(self, client: AsyncAsktable) -> None:
self.single_turn = resources.AsyncSingleTurnResourceWithStreamingResponse(client.single_turn)
self.caches = resources.AsyncCachesResourceWithStreamingResponse(client.caches)
self.integration = resources.AsyncIntegrationResourceWithStreamingResponse(client.integration)
self.sys = resources.AsyncSysResourceWithStreamingResponse(client.sys)
self.business_glossary = resources.AsyncBusinessGlossaryResourceWithStreamingResponse(client.business_glossary)


Client = Asktable
Expand Down
50 changes: 50 additions & 0 deletions src/asktable/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import List, Generic, TypeVar, Optional, cast
from typing_extensions import override

from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage

__all__ = ["SyncPage", "AsyncPage"]

_T = TypeVar("_T")


class SyncPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]
page: Optional[int] = None
size: Optional[int] = None
pages: Optional[int] = None

@override
def _get_page_items(self) -> List[_T]:
items = self.items
if not items:
return []
return items

@override
def next_page_info(self) -> Optional[PageInfo]:
last_page = cast("int | None", self._options.params.get("page")) or 1

return PageInfo(params={"page": last_page + 1})


class AsyncPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]
page: Optional[int] = None
size: Optional[int] = None
pages: Optional[int] = None

@override
def _get_page_items(self) -> List[_T]:
items = self.items
if not items:
return []
return items

@override
def next_page_info(self) -> Optional[PageInfo]:
last_page = cast("int | None", self._options.params.get("page")) or 1

return PageInfo(params={"page": last_page + 1})
26 changes: 20 additions & 6 deletions src/asktable/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,22 @@
SecuretunnelsResourceWithStreamingResponse,
AsyncSecuretunnelsResourceWithStreamingResponse,
)
from .business_glossary import (
BusinessGlossaryResource,
AsyncBusinessGlossaryResource,
BusinessGlossaryResourceWithRawResponse,
AsyncBusinessGlossaryResourceWithRawResponse,
BusinessGlossaryResourceWithStreamingResponse,
AsyncBusinessGlossaryResourceWithStreamingResponse,
)

__all__ = [
"SysResource",
"AsyncSysResource",
"SysResourceWithRawResponse",
"AsyncSysResourceWithRawResponse",
"SysResourceWithStreamingResponse",
"AsyncSysResourceWithStreamingResponse",
"SecuretunnelsResource",
"AsyncSecuretunnelsResource",
"SecuretunnelsResourceWithRawResponse",
Expand Down Expand Up @@ -164,10 +178,10 @@
"AsyncIntegrationResourceWithRawResponse",
"IntegrationResourceWithStreamingResponse",
"AsyncIntegrationResourceWithStreamingResponse",
"SysResource",
"AsyncSysResource",
"SysResourceWithRawResponse",
"AsyncSysResourceWithRawResponse",
"SysResourceWithStreamingResponse",
"AsyncSysResourceWithStreamingResponse",
"BusinessGlossaryResource",
"AsyncBusinessGlossaryResource",
"BusinessGlossaryResourceWithRawResponse",
"AsyncBusinessGlossaryResourceWithRawResponse",
"BusinessGlossaryResourceWithStreamingResponse",
"AsyncBusinessGlossaryResourceWithStreamingResponse",
]
Loading