Skip to content

Commit c38851f

Browse files
feat(api): support file management, prolong timeout (#102)
1 parent cdea94b commit c38851f

File tree

8 files changed

+394
-8
lines changed

8 files changed

+394
-8
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
configured_endpoints: 90
1+
configured_endpoints: 92
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/datamini%2Fasktable-812fbef9135838630557abadedcc8c593c10d2133388aaea70b9a313fc546941.yml

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ client.with_options(max_retries=5).datasources.create(
202202

203203
### Timeouts
204204

205-
By default requests time out after 1 minute. You can configure this with a `timeout` option,
205+
By default requests time out after 5 minutes. You can configure this with a `timeout` option,
206206
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
207207

208208
```python
209209
from asktable import Asktable
210210

211211
# Configure the default for all requests:
212212
client = Asktable(
213-
# 20 seconds (default is 1 minute)
213+
# 20 seconds (default is 5 minutes)
214214
timeout=20.0,
215215
)
216216

api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ from asktable.types import (
150150
Meta,
151151
DatasourceRetrieveResponse,
152152
DatasourceDeleteResponse,
153+
DatasourceAddFileResponse,
154+
DatasourceDeleteFileResponse,
153155
)
154156
```
155157

@@ -160,6 +162,8 @@ Methods:
160162
- <code title="patch /datasources/{datasource_id}">client.datasources.<a href="./src/asktable/resources/datasources/datasources.py">update</a>(datasource_id, \*\*<a href="src/asktable/types/datasource_update_params.py">params</a>) -> <a href="./src/asktable/types/datasource.py">Datasource</a></code>
161163
- <code title="get /datasources">client.datasources.<a href="./src/asktable/resources/datasources/datasources.py">list</a>(\*\*<a href="src/asktable/types/datasource_list_params.py">params</a>) -> <a href="./src/asktable/types/datasource.py">SyncPage[Datasource]</a></code>
162164
- <code title="delete /datasources/{datasource_id}">client.datasources.<a href="./src/asktable/resources/datasources/datasources.py">delete</a>(datasource_id) -> <a href="./src/asktable/types/datasource_delete_response.py">object</a></code>
165+
- <code title="post /datasources/{datasource_id}/files">client.datasources.<a href="./src/asktable/resources/datasources/datasources.py">add_file</a>(datasource_id, \*\*<a href="src/asktable/types/datasource_add_file_params.py">params</a>) -> <a href="./src/asktable/types/datasource_add_file_response.py">object</a></code>
166+
- <code title="delete /datasources/{datasource_id}/files/{file_id}">client.datasources.<a href="./src/asktable/resources/datasources/datasources.py">delete_file</a>(file_id, \*, datasource_id) -> <a href="./src/asktable/types/datasource_delete_file_response.py">object</a></code>
163167

164168
## Meta
165169

src/asktable/_constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
66
OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
77

8-
# default timeout is 1 minute
9-
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
8+
# default timeout is 5 minutes
9+
DEFAULT_TIMEOUT = httpx.Timeout(timeout=300.0, connect=5.0)
1010
DEFAULT_MAX_RETRIES = 2
1111
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
1212

src/asktable/resources/datasources/datasources.py

Lines changed: 190 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
5+
from typing import List, Mapping, Optional, cast
66
from typing_extensions import Literal
77

88
import httpx
@@ -15,7 +15,12 @@
1515
MetaResourceWithStreamingResponse,
1616
AsyncMetaResourceWithStreamingResponse,
1717
)
18-
from ...types import datasource_list_params, datasource_create_params, datasource_update_params
18+
from ...types import (
19+
datasource_list_params,
20+
datasource_create_params,
21+
datasource_update_params,
22+
datasource_add_file_params,
23+
)
1924
from .indexes import (
2025
IndexesResource,
2126
AsyncIndexesResource,
@@ -24,9 +29,11 @@
2429
IndexesResourceWithStreamingResponse,
2530
AsyncIndexesResourceWithStreamingResponse,
2631
)
27-
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
32+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
2833
from ..._utils import (
34+
extract_files,
2935
maybe_transform,
36+
deepcopy_minimal,
3037
async_maybe_transform,
3138
)
3239
from ..._compat import cached_property
@@ -340,6 +347,84 @@ def delete(
340347
cast_to=object,
341348
)
342349

350+
def add_file(
351+
self,
352+
datasource_id: str,
353+
*,
354+
files: List[FileTypes],
355+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
356+
# The extra values given here take precedence over values defined on the client or passed to this method.
357+
extra_headers: Headers | None = None,
358+
extra_query: Query | None = None,
359+
extra_body: Body | None = None,
360+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
361+
) -> object:
362+
"""
363+
为数据源添加文件
364+
365+
Args:
366+
extra_headers: Send extra headers
367+
368+
extra_query: Add additional query parameters to the request
369+
370+
extra_body: Add additional JSON properties to the request
371+
372+
timeout: Override the client-level default timeout for this request, in seconds
373+
"""
374+
if not datasource_id:
375+
raise ValueError(f"Expected a non-empty value for `datasource_id` but received {datasource_id!r}")
376+
body = deepcopy_minimal({"files": files})
377+
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
378+
# It should be noted that the actual Content-Type header that will be
379+
# sent to the server will contain a `boundary` parameter, e.g.
380+
# multipart/form-data; boundary=---abc--
381+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
382+
return self._post(
383+
f"/datasources/{datasource_id}/files",
384+
body=maybe_transform(body, datasource_add_file_params.DatasourceAddFileParams),
385+
files=extracted_files,
386+
options=make_request_options(
387+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
388+
),
389+
cast_to=object,
390+
)
391+
392+
def delete_file(
393+
self,
394+
file_id: str,
395+
*,
396+
datasource_id: str,
397+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
398+
# The extra values given here take precedence over values defined on the client or passed to this method.
399+
extra_headers: Headers | None = None,
400+
extra_query: Query | None = None,
401+
extra_body: Body | None = None,
402+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
403+
) -> object:
404+
"""
405+
删除数据源的单个文件
406+
407+
Args:
408+
extra_headers: Send extra headers
409+
410+
extra_query: Add additional query parameters to the request
411+
412+
extra_body: Add additional JSON properties to the request
413+
414+
timeout: Override the client-level default timeout for this request, in seconds
415+
"""
416+
if not datasource_id:
417+
raise ValueError(f"Expected a non-empty value for `datasource_id` but received {datasource_id!r}")
418+
if not file_id:
419+
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
420+
return self._delete(
421+
f"/datasources/{datasource_id}/files/{file_id}",
422+
options=make_request_options(
423+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
424+
),
425+
cast_to=object,
426+
)
427+
343428

344429
class AsyncDatasourcesResource(AsyncAPIResource):
345430
@cached_property
@@ -628,6 +713,84 @@ async def delete(
628713
cast_to=object,
629714
)
630715

716+
async def add_file(
717+
self,
718+
datasource_id: str,
719+
*,
720+
files: List[FileTypes],
721+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
722+
# The extra values given here take precedence over values defined on the client or passed to this method.
723+
extra_headers: Headers | None = None,
724+
extra_query: Query | None = None,
725+
extra_body: Body | None = None,
726+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
727+
) -> object:
728+
"""
729+
为数据源添加文件
730+
731+
Args:
732+
extra_headers: Send extra headers
733+
734+
extra_query: Add additional query parameters to the request
735+
736+
extra_body: Add additional JSON properties to the request
737+
738+
timeout: Override the client-level default timeout for this request, in seconds
739+
"""
740+
if not datasource_id:
741+
raise ValueError(f"Expected a non-empty value for `datasource_id` but received {datasource_id!r}")
742+
body = deepcopy_minimal({"files": files})
743+
extracted_files = extract_files(cast(Mapping[str, object], body), paths=[["files", "<array>"]])
744+
# It should be noted that the actual Content-Type header that will be
745+
# sent to the server will contain a `boundary` parameter, e.g.
746+
# multipart/form-data; boundary=---abc--
747+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
748+
return await self._post(
749+
f"/datasources/{datasource_id}/files",
750+
body=await async_maybe_transform(body, datasource_add_file_params.DatasourceAddFileParams),
751+
files=extracted_files,
752+
options=make_request_options(
753+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
754+
),
755+
cast_to=object,
756+
)
757+
758+
async def delete_file(
759+
self,
760+
file_id: str,
761+
*,
762+
datasource_id: str,
763+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
764+
# The extra values given here take precedence over values defined on the client or passed to this method.
765+
extra_headers: Headers | None = None,
766+
extra_query: Query | None = None,
767+
extra_body: Body | None = None,
768+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
769+
) -> object:
770+
"""
771+
删除数据源的单个文件
772+
773+
Args:
774+
extra_headers: Send extra headers
775+
776+
extra_query: Add additional query parameters to the request
777+
778+
extra_body: Add additional JSON properties to the request
779+
780+
timeout: Override the client-level default timeout for this request, in seconds
781+
"""
782+
if not datasource_id:
783+
raise ValueError(f"Expected a non-empty value for `datasource_id` but received {datasource_id!r}")
784+
if not file_id:
785+
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
786+
return await self._delete(
787+
f"/datasources/{datasource_id}/files/{file_id}",
788+
options=make_request_options(
789+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
790+
),
791+
cast_to=object,
792+
)
793+
631794

632795
class DatasourcesResourceWithRawResponse:
633796
def __init__(self, datasources: DatasourcesResource) -> None:
@@ -648,6 +811,12 @@ def __init__(self, datasources: DatasourcesResource) -> None:
648811
self.delete = to_raw_response_wrapper(
649812
datasources.delete,
650813
)
814+
self.add_file = to_raw_response_wrapper(
815+
datasources.add_file,
816+
)
817+
self.delete_file = to_raw_response_wrapper(
818+
datasources.delete_file,
819+
)
651820

652821
@cached_property
653822
def meta(self) -> MetaResourceWithRawResponse:
@@ -681,6 +850,12 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
681850
self.delete = async_to_raw_response_wrapper(
682851
datasources.delete,
683852
)
853+
self.add_file = async_to_raw_response_wrapper(
854+
datasources.add_file,
855+
)
856+
self.delete_file = async_to_raw_response_wrapper(
857+
datasources.delete_file,
858+
)
684859

685860
@cached_property
686861
def meta(self) -> AsyncMetaResourceWithRawResponse:
@@ -714,6 +889,12 @@ def __init__(self, datasources: DatasourcesResource) -> None:
714889
self.delete = to_streamed_response_wrapper(
715890
datasources.delete,
716891
)
892+
self.add_file = to_streamed_response_wrapper(
893+
datasources.add_file,
894+
)
895+
self.delete_file = to_streamed_response_wrapper(
896+
datasources.delete_file,
897+
)
717898

718899
@cached_property
719900
def meta(self) -> MetaResourceWithStreamingResponse:
@@ -747,6 +928,12 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
747928
self.delete = async_to_streamed_response_wrapper(
748929
datasources.delete,
749930
)
931+
self.add_file = async_to_streamed_response_wrapper(
932+
datasources.add_file,
933+
)
934+
self.delete_file = async_to_streamed_response_wrapper(
935+
datasources.delete_file,
936+
)
750937

751938
@cached_property
752939
def meta(self) -> AsyncMetaResourceWithStreamingResponse:

src/asktable/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from .role_get_polices_response import RoleGetPolicesResponse as RoleGetPolicesResponse
5959
from .role_get_variables_params import RoleGetVariablesParams as RoleGetVariablesParams
6060
from .chat_send_message_response import ChatSendMessageResponse as ChatSendMessageResponse
61+
from .datasource_add_file_params import DatasourceAddFileParams as DatasourceAddFileParams
6162
from .preference_create_response import PreferenceCreateResponse as PreferenceCreateResponse
6263
from .preference_update_response import PreferenceUpdateResponse as PreferenceUpdateResponse
6364
from .securetunnel_create_params import SecuretunnelCreateParams as SecuretunnelCreateParams
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
from typing import List
6+
from typing_extensions import Required, TypedDict
7+
8+
from .._types import FileTypes
9+
10+
__all__ = ["DatasourceAddFileParams"]
11+
12+
13+
class DatasourceAddFileParams(TypedDict, total=False):
14+
files: Required[List[FileTypes]]

0 commit comments

Comments
 (0)