Skip to content

Commit c7f3137

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat(api): api update (#13)
1 parent 8ac4185 commit c7f3137

File tree

6 files changed

+226
-56
lines changed

6 files changed

+226
-56
lines changed

api.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,7 @@ Methods:
132132
- <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/data_source.py">DataSource</a></code>
133133
- <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_list_response.py">DatasourceListResponse</a></code>
134134
- <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>
135-
136-
## File
137-
138-
Methods:
139-
140-
- <code title="post /datasources/file">client.datasources.file.<a href="./src/asktable/resources/datasources/file.py">create</a>(\*\*<a href="src/asktable/types/datasources/file_create_params.py">params</a>) -> <a href="./src/asktable/types/data_source.py">DataSource</a></code>
135+
- <code title="post /datasources/file">client.datasources.<a href="./src/asktable/resources/datasources/datasources.py">create_from_file</a>(\*\*<a href="src/asktable/types/datasource_create_from_file_params.py">params</a>) -> <a href="./src/asktable/types/data_source.py">DataSource</a></code>
141136

142137
## Meta
143138

src/asktable/resources/datasources/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from .file import (
4-
FileResource,
5-
AsyncFileResource,
6-
FileResourceWithRawResponse,
7-
AsyncFileResourceWithRawResponse,
8-
FileResourceWithStreamingResponse,
9-
AsyncFileResourceWithStreamingResponse,
10-
)
113
from .meta import (
124
MetaResource,
135
AsyncMetaResource,
@@ -34,12 +26,6 @@
3426
)
3527

3628
__all__ = [
37-
"FileResource",
38-
"AsyncFileResource",
39-
"FileResourceWithRawResponse",
40-
"AsyncFileResourceWithRawResponse",
41-
"FileResourceWithStreamingResponse",
42-
"AsyncFileResourceWithStreamingResponse",
4329
"MetaResource",
4430
"AsyncMetaResource",
4531
"MetaResourceWithRawResponse",

src/asktable/resources/datasources/datasources.py

Lines changed: 136 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22

33
from __future__ import annotations
44

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

88
import httpx
99

10-
from .file import (
11-
FileResource,
12-
AsyncFileResource,
13-
FileResourceWithRawResponse,
14-
AsyncFileResourceWithRawResponse,
15-
FileResourceWithStreamingResponse,
16-
AsyncFileResourceWithStreamingResponse,
17-
)
1810
from .meta import (
1911
MetaResource,
2012
AsyncMetaResource,
@@ -23,10 +15,17 @@
2315
MetaResourceWithStreamingResponse,
2416
AsyncMetaResourceWithStreamingResponse,
2517
)
26-
from ...types import datasource_list_params, datasource_create_params, datasource_update_params
27-
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
18+
from ...types import (
19+
datasource_list_params,
20+
datasource_create_params,
21+
datasource_update_params,
22+
datasource_create_from_file_params,
23+
)
24+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
2825
from ..._utils import (
26+
extract_files,
2927
maybe_transform,
28+
deepcopy_minimal,
3029
async_maybe_transform,
3130
)
3231
from ..._compat import cached_property
@@ -53,10 +52,6 @@
5352

5453

5554
class DatasourcesResource(SyncAPIResource):
56-
@cached_property
57-
def file(self) -> FileResource:
58-
return FileResource(self._client)
59-
6055
@cached_property
6156
def meta(self) -> MetaResource:
6257
return MetaResource(self._client)
@@ -331,12 +326,65 @@ def delete(
331326
cast_to=object,
332327
)
333328

329+
def create_from_file(
330+
self,
331+
*,
332+
name: str,
333+
file: FileTypes,
334+
async_process_meta: bool | NotGiven = NOT_GIVEN,
335+
skip_process_meta: bool | NotGiven = NOT_GIVEN,
336+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
337+
# The extra values given here take precedence over values defined on the client or passed to this method.
338+
extra_headers: Headers | None = None,
339+
extra_query: Query | None = None,
340+
extra_body: Body | None = None,
341+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
342+
) -> DataSource:
343+
"""
344+
上传文件并创建数据源
345+
346+
Args:
347+
async_process_meta: 是否异步处理元数据
334348
335-
class AsyncDatasourcesResource(AsyncAPIResource):
336-
@cached_property
337-
def file(self) -> AsyncFileResource:
338-
return AsyncFileResource(self._client)
349+
skip_process_meta: 是否跳过元数据处理
350+
351+
extra_headers: Send extra headers
352+
353+
extra_query: Add additional query parameters to the request
339354
355+
extra_body: Add additional JSON properties to the request
356+
357+
timeout: Override the client-level default timeout for this request, in seconds
358+
"""
359+
body = deepcopy_minimal({"file": file})
360+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
361+
# It should be noted that the actual Content-Type header that will be
362+
# sent to the server will contain a `boundary` parameter, e.g.
363+
# multipart/form-data; boundary=---abc--
364+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
365+
return self._post(
366+
"/datasources/file",
367+
body=maybe_transform(body, datasource_create_from_file_params.DatasourceCreateFromFileParams),
368+
files=files,
369+
options=make_request_options(
370+
extra_headers=extra_headers,
371+
extra_query=extra_query,
372+
extra_body=extra_body,
373+
timeout=timeout,
374+
query=maybe_transform(
375+
{
376+
"name": name,
377+
"async_process_meta": async_process_meta,
378+
"skip_process_meta": skip_process_meta,
379+
},
380+
datasource_create_from_file_params.DatasourceCreateFromFileParams,
381+
),
382+
),
383+
cast_to=DataSource,
384+
)
385+
386+
387+
class AsyncDatasourcesResource(AsyncAPIResource):
340388
@cached_property
341389
def meta(self) -> AsyncMetaResource:
342390
return AsyncMetaResource(self._client)
@@ -611,6 +659,63 @@ async def delete(
611659
cast_to=object,
612660
)
613661

662+
async def create_from_file(
663+
self,
664+
*,
665+
name: str,
666+
file: FileTypes,
667+
async_process_meta: bool | NotGiven = NOT_GIVEN,
668+
skip_process_meta: bool | NotGiven = NOT_GIVEN,
669+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
670+
# The extra values given here take precedence over values defined on the client or passed to this method.
671+
extra_headers: Headers | None = None,
672+
extra_query: Query | None = None,
673+
extra_body: Body | None = None,
674+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
675+
) -> DataSource:
676+
"""
677+
上传文件并创建数据源
678+
679+
Args:
680+
async_process_meta: 是否异步处理元数据
681+
682+
skip_process_meta: 是否跳过元数据处理
683+
684+
extra_headers: Send extra headers
685+
686+
extra_query: Add additional query parameters to the request
687+
688+
extra_body: Add additional JSON properties to the request
689+
690+
timeout: Override the client-level default timeout for this request, in seconds
691+
"""
692+
body = deepcopy_minimal({"file": file})
693+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
694+
# It should be noted that the actual Content-Type header that will be
695+
# sent to the server will contain a `boundary` parameter, e.g.
696+
# multipart/form-data; boundary=---abc--
697+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
698+
return await self._post(
699+
"/datasources/file",
700+
body=await async_maybe_transform(body, datasource_create_from_file_params.DatasourceCreateFromFileParams),
701+
files=files,
702+
options=make_request_options(
703+
extra_headers=extra_headers,
704+
extra_query=extra_query,
705+
extra_body=extra_body,
706+
timeout=timeout,
707+
query=await async_maybe_transform(
708+
{
709+
"name": name,
710+
"async_process_meta": async_process_meta,
711+
"skip_process_meta": skip_process_meta,
712+
},
713+
datasource_create_from_file_params.DatasourceCreateFromFileParams,
714+
),
715+
),
716+
cast_to=DataSource,
717+
)
718+
614719

615720
class DatasourcesResourceWithRawResponse:
616721
def __init__(self, datasources: DatasourcesResource) -> None:
@@ -631,10 +736,9 @@ def __init__(self, datasources: DatasourcesResource) -> None:
631736
self.delete = to_raw_response_wrapper(
632737
datasources.delete,
633738
)
634-
635-
@cached_property
636-
def file(self) -> FileResourceWithRawResponse:
637-
return FileResourceWithRawResponse(self._datasources.file)
739+
self.create_from_file = to_raw_response_wrapper(
740+
datasources.create_from_file,
741+
)
638742

639743
@cached_property
640744
def meta(self) -> MetaResourceWithRawResponse:
@@ -664,10 +768,9 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
664768
self.delete = async_to_raw_response_wrapper(
665769
datasources.delete,
666770
)
667-
668-
@cached_property
669-
def file(self) -> AsyncFileResourceWithRawResponse:
670-
return AsyncFileResourceWithRawResponse(self._datasources.file)
771+
self.create_from_file = async_to_raw_response_wrapper(
772+
datasources.create_from_file,
773+
)
671774

672775
@cached_property
673776
def meta(self) -> AsyncMetaResourceWithRawResponse:
@@ -697,10 +800,9 @@ def __init__(self, datasources: DatasourcesResource) -> None:
697800
self.delete = to_streamed_response_wrapper(
698801
datasources.delete,
699802
)
700-
701-
@cached_property
702-
def file(self) -> FileResourceWithStreamingResponse:
703-
return FileResourceWithStreamingResponse(self._datasources.file)
803+
self.create_from_file = to_streamed_response_wrapper(
804+
datasources.create_from_file,
805+
)
704806

705807
@cached_property
706808
def meta(self) -> MetaResourceWithStreamingResponse:
@@ -730,10 +832,9 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
730832
self.delete = async_to_streamed_response_wrapper(
731833
datasources.delete,
732834
)
733-
734-
@cached_property
735-
def file(self) -> AsyncFileResourceWithStreamingResponse:
736-
return AsyncFileResourceWithStreamingResponse(self._datasources.file)
835+
self.create_from_file = async_to_streamed_response_wrapper(
836+
datasources.create_from_file,
837+
)
737838

738839
@cached_property
739840
def meta(self) -> AsyncMetaResourceWithStreamingResponse:

src/asktable/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
from .securetunnel_list_response import SecuretunnelListResponse as SecuretunnelListResponse
4141
from .securetunnel_update_params import SecuretunnelUpdateParams as SecuretunnelUpdateParams
4242
from .integration_excel_csv_ask_params import IntegrationExcelCsvAskParams as IntegrationExcelCsvAskParams
43+
from .datasource_create_from_file_params import DatasourceCreateFromFileParams as DatasourceCreateFromFileParams

src/asktable/types/datasources/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from .meta import Meta as Meta
6-
from .file_create_params import FileCreateParams as FileCreateParams
76
from .meta_update_params import MetaUpdateParams as MetaUpdateParams
87
from .meta_retrieve_params import MetaRetrieveParams as MetaRetrieveParams
98
from .upload_param_create_params import UploadParamCreateParams as UploadParamCreateParams

tests/api_resources/test_datasources.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,50 @@ def test_path_params_delete(self, client: Asktable) -> None:
246246
"",
247247
)
248248

249+
@parametrize
250+
def test_method_create_from_file(self, client: Asktable) -> None:
251+
datasource = client.datasources.create_from_file(
252+
name="name",
253+
file=b"raw file contents",
254+
)
255+
assert_matches_type(DataSource, datasource, path=["response"])
256+
257+
@parametrize
258+
def test_method_create_from_file_with_all_params(self, client: Asktable) -> None:
259+
datasource = client.datasources.create_from_file(
260+
name="name",
261+
file=b"raw file contents",
262+
async_process_meta=True,
263+
skip_process_meta=True,
264+
)
265+
assert_matches_type(DataSource, datasource, path=["response"])
266+
267+
@parametrize
268+
def test_raw_response_create_from_file(self, client: Asktable) -> None:
269+
response = client.datasources.with_raw_response.create_from_file(
270+
name="name",
271+
file=b"raw file contents",
272+
)
273+
274+
assert response.is_closed is True
275+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
276+
datasource = response.parse()
277+
assert_matches_type(DataSource, datasource, path=["response"])
278+
279+
@parametrize
280+
def test_streaming_response_create_from_file(self, client: Asktable) -> None:
281+
with client.datasources.with_streaming_response.create_from_file(
282+
name="name",
283+
file=b"raw file contents",
284+
) as response:
285+
assert not response.is_closed
286+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
287+
288+
datasource = response.parse()
289+
assert_matches_type(DataSource, datasource, path=["response"])
290+
291+
assert cast(Any, response.is_closed) is True
292+
249293

250294
class TestAsyncDatasources:
251295
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
@@ -475,3 +519,47 @@ async def test_path_params_delete(self, async_client: AsyncAsktable) -> None:
475519
await async_client.datasources.with_raw_response.delete(
476520
"",
477521
)
522+
523+
@parametrize
524+
async def test_method_create_from_file(self, async_client: AsyncAsktable) -> None:
525+
datasource = await async_client.datasources.create_from_file(
526+
name="name",
527+
file=b"raw file contents",
528+
)
529+
assert_matches_type(DataSource, datasource, path=["response"])
530+
531+
@parametrize
532+
async def test_method_create_from_file_with_all_params(self, async_client: AsyncAsktable) -> None:
533+
datasource = await async_client.datasources.create_from_file(
534+
name="name",
535+
file=b"raw file contents",
536+
async_process_meta=True,
537+
skip_process_meta=True,
538+
)
539+
assert_matches_type(DataSource, datasource, path=["response"])
540+
541+
@parametrize
542+
async def test_raw_response_create_from_file(self, async_client: AsyncAsktable) -> None:
543+
response = await async_client.datasources.with_raw_response.create_from_file(
544+
name="name",
545+
file=b"raw file contents",
546+
)
547+
548+
assert response.is_closed is True
549+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
550+
datasource = await response.parse()
551+
assert_matches_type(DataSource, datasource, path=["response"])
552+
553+
@parametrize
554+
async def test_streaming_response_create_from_file(self, async_client: AsyncAsktable) -> None:
555+
async with async_client.datasources.with_streaming_response.create_from_file(
556+
name="name",
557+
file=b"raw file contents",
558+
) as response:
559+
assert not response.is_closed
560+
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
561+
562+
datasource = await response.parse()
563+
assert_matches_type(DataSource, datasource, path=["response"])
564+
565+
assert cast(Any, response.is_closed) is True

0 commit comments

Comments
 (0)