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
7 changes: 1 addition & 6 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ Methods:
- <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>
- <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>
- <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>

## File

Methods:

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

## Meta

Expand Down
14 changes: 0 additions & 14 deletions src/asktable/resources/datasources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from .file import (
FileResource,
AsyncFileResource,
FileResourceWithRawResponse,
AsyncFileResourceWithRawResponse,
FileResourceWithStreamingResponse,
AsyncFileResourceWithStreamingResponse,
)
from .meta import (
MetaResource,
AsyncMetaResource,
Expand All @@ -34,12 +26,6 @@
)

__all__ = [
"FileResource",
"AsyncFileResource",
"FileResourceWithRawResponse",
"AsyncFileResourceWithRawResponse",
"FileResourceWithStreamingResponse",
"AsyncFileResourceWithStreamingResponse",
"MetaResource",
"AsyncMetaResource",
"MetaResourceWithRawResponse",
Expand Down
171 changes: 136 additions & 35 deletions src/asktable/resources/datasources/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

from __future__ import annotations

from typing import Optional
from typing import Mapping, Optional, cast
from typing_extensions import Literal

import httpx

from .file import (
FileResource,
AsyncFileResource,
FileResourceWithRawResponse,
AsyncFileResourceWithRawResponse,
FileResourceWithStreamingResponse,
AsyncFileResourceWithStreamingResponse,
)
from .meta import (
MetaResource,
AsyncMetaResource,
Expand All @@ -23,10 +15,17 @@
MetaResourceWithStreamingResponse,
AsyncMetaResourceWithStreamingResponse,
)
from ...types import datasource_list_params, datasource_create_params, datasource_update_params
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ...types import (
datasource_list_params,
datasource_create_params,
datasource_update_params,
datasource_create_from_file_params,
)
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
from ..._utils import (
extract_files,
maybe_transform,
deepcopy_minimal,
async_maybe_transform,
)
from ..._compat import cached_property
Expand All @@ -53,10 +52,6 @@


class DatasourcesResource(SyncAPIResource):
@cached_property
def file(self) -> FileResource:
return FileResource(self._client)

@cached_property
def meta(self) -> MetaResource:
return MetaResource(self._client)
Expand Down Expand Up @@ -331,12 +326,65 @@ def delete(
cast_to=object,
)

def create_from_file(
self,
*,
name: str,
file: FileTypes,
async_process_meta: bool | NotGiven = NOT_GIVEN,
skip_process_meta: bool | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> DataSource:
"""
上传文件并创建数据源

Args:
async_process_meta: 是否异步处理元数据

class AsyncDatasourcesResource(AsyncAPIResource):
@cached_property
def file(self) -> AsyncFileResource:
return AsyncFileResource(self._client)
skip_process_meta: 是否跳过元数据处理

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal({"file": file})
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
"/datasources/file",
body=maybe_transform(body, datasource_create_from_file_params.DatasourceCreateFromFileParams),
files=files,
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"name": name,
"async_process_meta": async_process_meta,
"skip_process_meta": skip_process_meta,
},
datasource_create_from_file_params.DatasourceCreateFromFileParams,
),
),
cast_to=DataSource,
)


class AsyncDatasourcesResource(AsyncAPIResource):
@cached_property
def meta(self) -> AsyncMetaResource:
return AsyncMetaResource(self._client)
Expand Down Expand Up @@ -611,6 +659,63 @@ async def delete(
cast_to=object,
)

async def create_from_file(
self,
*,
name: str,
file: FileTypes,
async_process_meta: bool | NotGiven = NOT_GIVEN,
skip_process_meta: bool | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> DataSource:
"""
上传文件并创建数据源

Args:
async_process_meta: 是否异步处理元数据

skip_process_meta: 是否跳过元数据处理

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
body = deepcopy_minimal({"file": file})
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
# It should be noted that the actual Content-Type header that will be
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
"/datasources/file",
body=await async_maybe_transform(body, datasource_create_from_file_params.DatasourceCreateFromFileParams),
files=files,
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=await async_maybe_transform(
{
"name": name,
"async_process_meta": async_process_meta,
"skip_process_meta": skip_process_meta,
},
datasource_create_from_file_params.DatasourceCreateFromFileParams,
),
),
cast_to=DataSource,
)


class DatasourcesResourceWithRawResponse:
def __init__(self, datasources: DatasourcesResource) -> None:
Expand All @@ -631,10 +736,9 @@ def __init__(self, datasources: DatasourcesResource) -> None:
self.delete = to_raw_response_wrapper(
datasources.delete,
)

@cached_property
def file(self) -> FileResourceWithRawResponse:
return FileResourceWithRawResponse(self._datasources.file)
self.create_from_file = to_raw_response_wrapper(
datasources.create_from_file,
)

@cached_property
def meta(self) -> MetaResourceWithRawResponse:
Expand Down Expand Up @@ -664,10 +768,9 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
self.delete = async_to_raw_response_wrapper(
datasources.delete,
)

@cached_property
def file(self) -> AsyncFileResourceWithRawResponse:
return AsyncFileResourceWithRawResponse(self._datasources.file)
self.create_from_file = async_to_raw_response_wrapper(
datasources.create_from_file,
)

@cached_property
def meta(self) -> AsyncMetaResourceWithRawResponse:
Expand Down Expand Up @@ -697,10 +800,9 @@ def __init__(self, datasources: DatasourcesResource) -> None:
self.delete = to_streamed_response_wrapper(
datasources.delete,
)

@cached_property
def file(self) -> FileResourceWithStreamingResponse:
return FileResourceWithStreamingResponse(self._datasources.file)
self.create_from_file = to_streamed_response_wrapper(
datasources.create_from_file,
)

@cached_property
def meta(self) -> MetaResourceWithStreamingResponse:
Expand Down Expand Up @@ -730,10 +832,9 @@ def __init__(self, datasources: AsyncDatasourcesResource) -> None:
self.delete = async_to_streamed_response_wrapper(
datasources.delete,
)

@cached_property
def file(self) -> AsyncFileResourceWithStreamingResponse:
return AsyncFileResourceWithStreamingResponse(self._datasources.file)
self.create_from_file = async_to_streamed_response_wrapper(
datasources.create_from_file,
)

@cached_property
def meta(self) -> AsyncMetaResourceWithStreamingResponse:
Expand Down
1 change: 1 addition & 0 deletions src/asktable/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
from .securetunnel_list_response import SecuretunnelListResponse as SecuretunnelListResponse
from .securetunnel_update_params import SecuretunnelUpdateParams as SecuretunnelUpdateParams
from .integration_excel_csv_ask_params import IntegrationExcelCsvAskParams as IntegrationExcelCsvAskParams
from .datasource_create_from_file_params import DatasourceCreateFromFileParams as DatasourceCreateFromFileParams
1 change: 0 additions & 1 deletion src/asktable/types/datasources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

from .meta import Meta as Meta
from .file_create_params import FileCreateParams as FileCreateParams
from .meta_update_params import MetaUpdateParams as MetaUpdateParams
from .meta_retrieve_params import MetaRetrieveParams as MetaRetrieveParams
from .upload_param_create_params import UploadParamCreateParams as UploadParamCreateParams
88 changes: 88 additions & 0 deletions tests/api_resources/test_datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,50 @@ def test_path_params_delete(self, client: Asktable) -> None:
"",
)

@parametrize
def test_method_create_from_file(self, client: Asktable) -> None:
datasource = client.datasources.create_from_file(
name="name",
file=b"raw file contents",
)
assert_matches_type(DataSource, datasource, path=["response"])

@parametrize
def test_method_create_from_file_with_all_params(self, client: Asktable) -> None:
datasource = client.datasources.create_from_file(
name="name",
file=b"raw file contents",
async_process_meta=True,
skip_process_meta=True,
)
assert_matches_type(DataSource, datasource, path=["response"])

@parametrize
def test_raw_response_create_from_file(self, client: Asktable) -> None:
response = client.datasources.with_raw_response.create_from_file(
name="name",
file=b"raw file contents",
)

assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
datasource = response.parse()
assert_matches_type(DataSource, datasource, path=["response"])

@parametrize
def test_streaming_response_create_from_file(self, client: Asktable) -> None:
with client.datasources.with_streaming_response.create_from_file(
name="name",
file=b"raw file contents",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

datasource = response.parse()
assert_matches_type(DataSource, datasource, path=["response"])

assert cast(Any, response.is_closed) is True


class TestAsyncDatasources:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
Expand Down Expand Up @@ -475,3 +519,47 @@ async def test_path_params_delete(self, async_client: AsyncAsktable) -> None:
await async_client.datasources.with_raw_response.delete(
"",
)

@parametrize
async def test_method_create_from_file(self, async_client: AsyncAsktable) -> None:
datasource = await async_client.datasources.create_from_file(
name="name",
file=b"raw file contents",
)
assert_matches_type(DataSource, datasource, path=["response"])

@parametrize
async def test_method_create_from_file_with_all_params(self, async_client: AsyncAsktable) -> None:
datasource = await async_client.datasources.create_from_file(
name="name",
file=b"raw file contents",
async_process_meta=True,
skip_process_meta=True,
)
assert_matches_type(DataSource, datasource, path=["response"])

@parametrize
async def test_raw_response_create_from_file(self, async_client: AsyncAsktable) -> None:
response = await async_client.datasources.with_raw_response.create_from_file(
name="name",
file=b"raw file contents",
)

assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
datasource = await response.parse()
assert_matches_type(DataSource, datasource, path=["response"])

@parametrize
async def test_streaming_response_create_from_file(self, async_client: AsyncAsktable) -> None:
async with async_client.datasources.with_streaming_response.create_from_file(
name="name",
file=b"raw file contents",
) as response:
assert not response.is_closed
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

datasource = await response.parse()
assert_matches_type(DataSource, datasource, path=["response"])

assert cast(Any, response.is_closed) is True