|
| 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 Mapping, cast |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes |
| 10 | +from ..._utils import ( |
| 11 | + extract_files, |
| 12 | + maybe_transform, |
| 13 | + deepcopy_minimal, |
| 14 | + async_maybe_transform, |
| 15 | +) |
| 16 | +from ..._compat import cached_property |
| 17 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 18 | +from ..._response import ( |
| 19 | + to_raw_response_wrapper, |
| 20 | + to_streamed_response_wrapper, |
| 21 | + async_to_raw_response_wrapper, |
| 22 | + async_to_streamed_response_wrapper, |
| 23 | +) |
| 24 | +from ..._base_client import make_request_options |
| 25 | +from ...types.data_source import DataSource |
| 26 | +from ...types.datasources import file_create_params |
| 27 | + |
| 28 | +__all__ = ["FileResource", "AsyncFileResource"] |
| 29 | + |
| 30 | + |
| 31 | +class FileResource(SyncAPIResource): |
| 32 | + @cached_property |
| 33 | + def with_raw_response(self) -> FileResourceWithRawResponse: |
| 34 | + """ |
| 35 | + This property can be used as a prefix for any HTTP method call to return the |
| 36 | + the raw response object instead of the parsed content. |
| 37 | +
|
| 38 | + For more information, see https://www.github.com/DataMini/asktable-python#accessing-raw-response-data-eg-headers |
| 39 | + """ |
| 40 | + return FileResourceWithRawResponse(self) |
| 41 | + |
| 42 | + @cached_property |
| 43 | + def with_streaming_response(self) -> FileResourceWithStreamingResponse: |
| 44 | + """ |
| 45 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 46 | +
|
| 47 | + For more information, see https://www.github.com/DataMini/asktable-python#with_streaming_response |
| 48 | + """ |
| 49 | + return FileResourceWithStreamingResponse(self) |
| 50 | + |
| 51 | + def create( |
| 52 | + self, |
| 53 | + *, |
| 54 | + name: str, |
| 55 | + file: FileTypes, |
| 56 | + async_process_meta: bool | NotGiven = NOT_GIVEN, |
| 57 | + skip_process_meta: bool | NotGiven = NOT_GIVEN, |
| 58 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 59 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 60 | + extra_headers: Headers | None = None, |
| 61 | + extra_query: Query | None = None, |
| 62 | + extra_body: Body | None = None, |
| 63 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 64 | + ) -> DataSource: |
| 65 | + """ |
| 66 | + 上传文件并创建数据源 |
| 67 | +
|
| 68 | + Args: |
| 69 | + async_process_meta: 是否异步处理元数据 |
| 70 | +
|
| 71 | + skip_process_meta: 是否跳过元数据处理 |
| 72 | +
|
| 73 | + extra_headers: Send extra headers |
| 74 | +
|
| 75 | + extra_query: Add additional query parameters to the request |
| 76 | +
|
| 77 | + extra_body: Add additional JSON properties to the request |
| 78 | +
|
| 79 | + timeout: Override the client-level default timeout for this request, in seconds |
| 80 | + """ |
| 81 | + body = deepcopy_minimal({"file": file}) |
| 82 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
| 83 | + # It should be noted that the actual Content-Type header that will be |
| 84 | + # sent to the server will contain a `boundary` parameter, e.g. |
| 85 | + # multipart/form-data; boundary=---abc-- |
| 86 | + extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
| 87 | + return self._post( |
| 88 | + "/datasources/file", |
| 89 | + body=maybe_transform(body, file_create_params.FileCreateParams), |
| 90 | + files=files, |
| 91 | + options=make_request_options( |
| 92 | + extra_headers=extra_headers, |
| 93 | + extra_query=extra_query, |
| 94 | + extra_body=extra_body, |
| 95 | + timeout=timeout, |
| 96 | + query=maybe_transform( |
| 97 | + { |
| 98 | + "name": name, |
| 99 | + "async_process_meta": async_process_meta, |
| 100 | + "skip_process_meta": skip_process_meta, |
| 101 | + }, |
| 102 | + file_create_params.FileCreateParams, |
| 103 | + ), |
| 104 | + ), |
| 105 | + cast_to=DataSource, |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +class AsyncFileResource(AsyncAPIResource): |
| 110 | + @cached_property |
| 111 | + def with_raw_response(self) -> AsyncFileResourceWithRawResponse: |
| 112 | + """ |
| 113 | + This property can be used as a prefix for any HTTP method call to return the |
| 114 | + the raw response object instead of the parsed content. |
| 115 | +
|
| 116 | + For more information, see https://www.github.com/DataMini/asktable-python#accessing-raw-response-data-eg-headers |
| 117 | + """ |
| 118 | + return AsyncFileResourceWithRawResponse(self) |
| 119 | + |
| 120 | + @cached_property |
| 121 | + def with_streaming_response(self) -> AsyncFileResourceWithStreamingResponse: |
| 122 | + """ |
| 123 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 124 | +
|
| 125 | + For more information, see https://www.github.com/DataMini/asktable-python#with_streaming_response |
| 126 | + """ |
| 127 | + return AsyncFileResourceWithStreamingResponse(self) |
| 128 | + |
| 129 | + async def create( |
| 130 | + self, |
| 131 | + *, |
| 132 | + name: str, |
| 133 | + file: FileTypes, |
| 134 | + async_process_meta: bool | NotGiven = NOT_GIVEN, |
| 135 | + skip_process_meta: bool | NotGiven = NOT_GIVEN, |
| 136 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 137 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 138 | + extra_headers: Headers | None = None, |
| 139 | + extra_query: Query | None = None, |
| 140 | + extra_body: Body | None = None, |
| 141 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 142 | + ) -> DataSource: |
| 143 | + """ |
| 144 | + 上传文件并创建数据源 |
| 145 | +
|
| 146 | + Args: |
| 147 | + async_process_meta: 是否异步处理元数据 |
| 148 | +
|
| 149 | + skip_process_meta: 是否跳过元数据处理 |
| 150 | +
|
| 151 | + extra_headers: Send extra headers |
| 152 | +
|
| 153 | + extra_query: Add additional query parameters to the request |
| 154 | +
|
| 155 | + extra_body: Add additional JSON properties to the request |
| 156 | +
|
| 157 | + timeout: Override the client-level default timeout for this request, in seconds |
| 158 | + """ |
| 159 | + body = deepcopy_minimal({"file": file}) |
| 160 | + files = extract_files(cast(Mapping[str, object], body), paths=[["file"]]) |
| 161 | + # It should be noted that the actual Content-Type header that will be |
| 162 | + # sent to the server will contain a `boundary` parameter, e.g. |
| 163 | + # multipart/form-data; boundary=---abc-- |
| 164 | + extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})} |
| 165 | + return await self._post( |
| 166 | + "/datasources/file", |
| 167 | + body=await async_maybe_transform(body, file_create_params.FileCreateParams), |
| 168 | + files=files, |
| 169 | + options=make_request_options( |
| 170 | + extra_headers=extra_headers, |
| 171 | + extra_query=extra_query, |
| 172 | + extra_body=extra_body, |
| 173 | + timeout=timeout, |
| 174 | + query=await async_maybe_transform( |
| 175 | + { |
| 176 | + "name": name, |
| 177 | + "async_process_meta": async_process_meta, |
| 178 | + "skip_process_meta": skip_process_meta, |
| 179 | + }, |
| 180 | + file_create_params.FileCreateParams, |
| 181 | + ), |
| 182 | + ), |
| 183 | + cast_to=DataSource, |
| 184 | + ) |
| 185 | + |
| 186 | + |
| 187 | +class FileResourceWithRawResponse: |
| 188 | + def __init__(self, file: FileResource) -> None: |
| 189 | + self._file = file |
| 190 | + |
| 191 | + self.create = to_raw_response_wrapper( |
| 192 | + file.create, |
| 193 | + ) |
| 194 | + |
| 195 | + |
| 196 | +class AsyncFileResourceWithRawResponse: |
| 197 | + def __init__(self, file: AsyncFileResource) -> None: |
| 198 | + self._file = file |
| 199 | + |
| 200 | + self.create = async_to_raw_response_wrapper( |
| 201 | + file.create, |
| 202 | + ) |
| 203 | + |
| 204 | + |
| 205 | +class FileResourceWithStreamingResponse: |
| 206 | + def __init__(self, file: FileResource) -> None: |
| 207 | + self._file = file |
| 208 | + |
| 209 | + self.create = to_streamed_response_wrapper( |
| 210 | + file.create, |
| 211 | + ) |
| 212 | + |
| 213 | + |
| 214 | +class AsyncFileResourceWithStreamingResponse: |
| 215 | + def __init__(self, file: AsyncFileResource) -> None: |
| 216 | + self._file = file |
| 217 | + |
| 218 | + self.create = async_to_streamed_response_wrapper( |
| 219 | + file.create, |
| 220 | + ) |
0 commit comments