@planqk/planqk-service-sdk 1.9.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/devcontainer.json +32 -0
- package/.devcontainer/post-create.sh +7 -0
- package/.env.template +4 -0
- package/.gitlab-ci.yml +103 -0
- package/.python-version +1 -0
- package/.releaserc.json +45 -0
- package/LICENSE +201 -0
- package/README-node.md +41 -0
- package/README-python.md +52 -0
- package/README.md +42 -21
- package/dist/auth.js +12 -19
- package/dist/client.d.ts +2 -12
- package/dist/client.js +5 -76
- package/dist/sdk/Client.d.ts +4 -3
- package/dist/sdk/Client.js +4 -8
- package/dist/sdk/api/errors/BadRequestError.d.ts +1 -1
- package/dist/sdk/api/errors/BadRequestError.js +18 -8
- package/dist/sdk/api/errors/ForbiddenError.d.ts +1 -1
- package/dist/sdk/api/errors/ForbiddenError.js +18 -8
- package/dist/sdk/api/errors/InternalServerError.d.ts +1 -1
- package/dist/sdk/api/errors/InternalServerError.js +18 -8
- package/dist/sdk/api/errors/NotFoundError.d.ts +1 -1
- package/dist/sdk/api/errors/NotFoundError.js +18 -8
- package/dist/sdk/api/errors/UnauthorizedError.d.ts +1 -1
- package/dist/sdk/api/errors/UnauthorizedError.js +18 -8
- package/dist/sdk/api/resources/index.d.ts +0 -3
- package/dist/sdk/api/resources/index.js +18 -11
- package/dist/sdk/api/resources/serviceApi/client/Client.d.ts +65 -12
- package/dist/sdk/api/resources/serviceApi/client/Client.js +405 -261
- package/dist/sdk/api/resources/serviceApi/client/index.d.ts +1 -1
- package/dist/sdk/api/resources/serviceApi/client/index.js +0 -15
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponse.d.ts +4 -1
- package/dist/sdk/api/resources/serviceApi/types/{GetInterimResultsResponse.d.ts → GetResultResponseEmbedded.d.ts} +3 -1
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponseLinks.d.ts +7 -0
- package/dist/sdk/api/resources/{statusApi → serviceApi}/types/HealthCheckResponse.d.ts +1 -0
- package/dist/sdk/api/resources/serviceApi/types/index.d.ts +3 -1
- package/dist/sdk/api/resources/serviceApi/types/index.js +3 -1
- package/dist/sdk/api/types/HalLink.d.ts +21 -0
- package/dist/sdk/api/types/InputData.d.ts +1 -1
- package/dist/sdk/api/types/{InputRef.d.ts → InputDataRef.d.ts} +1 -1
- package/dist/sdk/api/types/InputParams.d.ts +1 -1
- package/dist/sdk/api/types/{Job.d.ts → ServiceExecution.d.ts} +2 -2
- package/dist/sdk/api/types/{JobStatus.d.ts → ServiceExecutionStatus.d.ts} +2 -2
- package/dist/sdk/api/types/{JobStatus.js → ServiceExecutionStatus.js} +2 -2
- package/dist/sdk/api/types/index.d.ts +4 -8
- package/dist/sdk/api/types/index.js +4 -8
- package/dist/sdk/core/fetcher/APIResponse.d.ts +1 -0
- package/dist/sdk/core/fetcher/Fetcher.d.ts +6 -5
- package/dist/sdk/core/fetcher/Fetcher.js +68 -112
- package/dist/sdk/core/fetcher/Supplier.js +2 -11
- package/dist/sdk/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/sdk/core/fetcher/createRequestUrl.js +12 -0
- package/dist/sdk/core/fetcher/getFetchFn.d.ts +4 -0
- package/dist/sdk/core/fetcher/getFetchFn.js +57 -0
- package/dist/sdk/core/fetcher/getHeader.d.ts +1 -0
- package/dist/sdk/core/fetcher/getHeader.js +11 -0
- package/dist/sdk/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/sdk/core/fetcher/getRequestBody.js +11 -0
- package/dist/sdk/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/sdk/core/fetcher/getResponseBody.js +40 -0
- package/dist/sdk/core/fetcher/index.d.ts +1 -0
- package/dist/sdk/core/fetcher/index.js +3 -1
- package/dist/sdk/core/fetcher/makeRequest.d.ts +1 -0
- package/dist/sdk/core/fetcher/makeRequest.js +33 -0
- package/dist/sdk/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/sdk/core/fetcher/requestWithRetries.js +20 -0
- package/dist/sdk/core/fetcher/signals.d.ts +11 -0
- package/dist/sdk/core/fetcher/signals.js +36 -0
- package/dist/sdk/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +30 -0
- package/dist/sdk/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +232 -0
- package/dist/sdk/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +21 -0
- package/dist/sdk/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +91 -0
- package/dist/sdk/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +31 -0
- package/dist/sdk/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +214 -0
- package/dist/sdk/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +18 -0
- package/dist/sdk/core/fetcher/stream-wrappers/chooseStreamWrapper.js +48 -0
- package/dist/sdk/core/index.d.ts +1 -0
- package/dist/sdk/core/index.js +1 -0
- package/dist/sdk/core/runtime/index.d.ts +1 -0
- package/dist/sdk/core/runtime/index.js +5 -0
- package/dist/sdk/core/runtime/runtime.d.ts +9 -0
- package/dist/sdk/core/runtime/runtime.js +92 -0
- package/dist/sdk/errors/PlanqkServiceApiError.js +2 -0
- package/dist/sdk/index.js +17 -7
- package/eslint.config.mjs +11 -0
- package/fern/fern.config.json +4 -0
- package/fern/generators.yml +25 -0
- package/fern/openapi/openapi.yml +342 -0
- package/notebooks/python-sdk.ipynb +280 -0
- package/package.json +27 -28
- package/planqk/__init__.py +0 -0
- package/planqk/service/__init__.py +1 -0
- package/planqk/service/_version.py +1 -0
- package/planqk/service/auth.py +30 -0
- package/planqk/service/client.py +151 -0
- package/planqk/service/sdk/__init__.py +48 -0
- package/planqk/service/sdk/client.py +152 -0
- package/planqk/service/sdk/core/__init__.py +47 -0
- package/planqk/service/sdk/core/api_error.py +17 -0
- package/planqk/service/sdk/core/client_wrapper.py +74 -0
- package/planqk/service/sdk/core/datetime_utils.py +30 -0
- package/planqk/service/sdk/core/file.py +70 -0
- package/planqk/service/sdk/core/http_client.py +575 -0
- package/planqk/service/sdk/core/jsonable_encoder.py +103 -0
- package/planqk/service/sdk/core/pydantic_utilities.py +323 -0
- package/planqk/service/sdk/core/query_encoder.py +60 -0
- package/planqk/service/sdk/core/remove_none_from_dict.py +11 -0
- package/planqk/service/sdk/core/request_options.py +35 -0
- package/planqk/service/sdk/core/serialization.py +276 -0
- package/planqk/service/sdk/environment.py +7 -0
- package/planqk/service/sdk/errors/__init__.py +15 -0
- package/planqk/service/sdk/errors/bad_request_error.py +9 -0
- package/planqk/service/sdk/errors/forbidden_error.py +9 -0
- package/planqk/service/sdk/errors/internal_server_error.py +9 -0
- package/planqk/service/sdk/errors/not_found_error.py +9 -0
- package/planqk/service/sdk/errors/unauthorized_error.py +9 -0
- package/planqk/service/sdk/service_api/__init__.py +15 -0
- package/planqk/service/sdk/service_api/client.py +1257 -0
- package/planqk/service/sdk/service_api/types/__init__.py +13 -0
- package/planqk/service/sdk/service_api/types/get_result_response.py +30 -0
- package/planqk/service/sdk/service_api/types/get_result_response_embedded.py +22 -0
- package/planqk/service/sdk/service_api/types/get_result_response_links.py +22 -0
- package/planqk/service/sdk/service_api/types/health_check_response.py +24 -0
- package/planqk/service/sdk/types/__init__.py +17 -0
- package/planqk/service/sdk/types/hal_link.py +59 -0
- package/planqk/service/sdk/types/input_data.py +5 -0
- package/planqk/service/sdk/types/input_data_ref.py +27 -0
- package/planqk/service/sdk/types/input_params.py +5 -0
- package/planqk/service/sdk/types/service_execution.py +34 -0
- package/planqk/service/sdk/types/service_execution_status.py +8 -0
- package/pyproject.toml +51 -0
- package/scripts/update-version.sh +6 -0
- package/src/client.ts +4 -78
- package/src/index.test.ts +43 -0
- package/src/sdk/Client.ts +4 -7
- package/src/sdk/api/errors/BadRequestError.ts +1 -1
- package/src/sdk/api/errors/ForbiddenError.ts +1 -1
- package/src/sdk/api/errors/InternalServerError.ts +1 -1
- package/src/sdk/api/errors/NotFoundError.ts +1 -1
- package/src/sdk/api/errors/UnauthorizedError.ts +1 -1
- package/src/sdk/api/resources/index.ts +0 -3
- package/src/sdk/api/resources/serviceApi/client/Client.ts +205 -32
- package/src/sdk/api/resources/serviceApi/client/index.ts +1 -1
- package/src/sdk/api/resources/serviceApi/types/GetResultResponse.ts +4 -5
- package/src/sdk/api/resources/serviceApi/types/GetResultResponseEmbedded.ts +9 -0
- package/src/sdk/api/resources/serviceApi/types/GetResultResponseLinks.ts +9 -0
- package/src/sdk/api/resources/{statusApi → serviceApi}/types/HealthCheckResponse.ts +1 -0
- package/src/sdk/api/resources/serviceApi/types/index.ts +3 -1
- package/src/sdk/api/types/HalLink.ts +22 -0
- package/src/sdk/api/types/InputData.ts +1 -1
- package/src/sdk/api/types/{InputRef.ts → InputDataRef.ts} +1 -1
- package/src/sdk/api/types/InputParams.ts +1 -1
- package/src/sdk/api/types/{Job.ts → ServiceExecution.ts} +2 -2
- package/src/sdk/api/types/{JobStatus.ts → ServiceExecutionStatus.ts} +2 -2
- package/src/sdk/api/types/index.ts +4 -8
- package/src/sdk/core/fetcher/APIResponse.ts +1 -0
- package/src/sdk/core/fetcher/Fetcher.ts +55 -72
- package/src/sdk/core/fetcher/createRequestUrl.ts +10 -0
- package/src/sdk/core/fetcher/getFetchFn.ts +25 -0
- package/src/sdk/core/fetcher/getHeader.ts +8 -0
- package/src/sdk/core/fetcher/getRequestBody.ts +14 -0
- package/src/sdk/core/fetcher/getResponseBody.ts +32 -0
- package/src/sdk/core/fetcher/index.ts +1 -0
- package/src/sdk/core/fetcher/makeRequest.ts +44 -0
- package/src/sdk/core/fetcher/requestWithRetries.ts +21 -0
- package/src/sdk/core/fetcher/signals.ts +38 -0
- package/src/sdk/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts +252 -0
- package/src/sdk/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts +106 -0
- package/src/sdk/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts +239 -0
- package/src/sdk/core/fetcher/stream-wrappers/chooseStreamWrapper.ts +33 -0
- package/src/sdk/core/index.ts +1 -0
- package/src/sdk/core/runtime/index.ts +1 -0
- package/src/sdk/core/runtime/runtime.ts +126 -0
- package/tsconfig.json +15 -107
- package/uv.lock +1109 -0
- package/.eslintignore +0 -3
- package/.eslintrc +0 -7
- package/dist/sdk/api/resources/serviceApi/client/requests/GetInterimResultsRequest.d.ts +0 -9
- package/dist/sdk/api/resources/serviceApi/client/requests/StartExecutionRequest.d.ts +0 -13
- package/dist/sdk/api/resources/serviceApi/client/requests/index.d.ts +0 -2
- package/dist/sdk/api/resources/serviceApi/client/requests/index.js +0 -2
- package/dist/sdk/api/resources/statusApi/client/Client.d.ts +0 -28
- package/dist/sdk/api/resources/statusApi/client/Client.js +0 -97
- package/dist/sdk/api/resources/statusApi/client/index.d.ts +0 -1
- package/dist/sdk/api/resources/statusApi/client/index.js +0 -2
- package/dist/sdk/api/resources/statusApi/index.d.ts +0 -2
- package/dist/sdk/api/resources/statusApi/index.js +0 -18
- package/dist/sdk/api/resources/statusApi/types/index.d.ts +0 -1
- package/dist/sdk/api/resources/statusApi/types/index.js +0 -17
- package/dist/sdk/api/types/ArrayResponse.d.ts +0 -4
- package/dist/sdk/api/types/InterimResultResponse.d.ts +0 -4
- package/dist/sdk/api/types/InterimResultResponse.js +0 -5
- package/dist/sdk/api/types/Job.js +0 -5
- package/dist/sdk/api/types/NumberResponse.d.ts +0 -4
- package/dist/sdk/api/types/NumberResponse.js +0 -5
- package/dist/sdk/api/types/ObjectResponse.d.ts +0 -4
- package/dist/sdk/api/types/ObjectResponse.js +0 -5
- package/dist/sdk/api/types/StringResponse.d.ts +0 -4
- package/dist/sdk/api/types/StringResponse.js +0 -5
- package/jest.config.js +0 -12
- package/src/sdk/api/resources/serviceApi/client/requests/GetInterimResultsRequest.ts +0 -10
- package/src/sdk/api/resources/serviceApi/client/requests/StartExecutionRequest.ts +0 -15
- package/src/sdk/api/resources/serviceApi/client/requests/index.ts +0 -2
- package/src/sdk/api/resources/serviceApi/types/GetInterimResultsResponse.ts +0 -9
- package/src/sdk/api/resources/statusApi/client/Client.ts +0 -75
- package/src/sdk/api/resources/statusApi/client/index.ts +0 -1
- package/src/sdk/api/resources/statusApi/index.ts +0 -2
- package/src/sdk/api/resources/statusApi/types/index.ts +0 -1
- package/src/sdk/api/types/ArrayResponse.ts +0 -5
- package/src/sdk/api/types/InterimResultResponse.ts +0 -5
- package/src/sdk/api/types/NumberResponse.ts +0 -5
- package/src/sdk/api/types/ObjectResponse.ts +0 -5
- package/src/sdk/api/types/StringResponse.ts +0 -5
- package/tests/fixtures/complex-input.ts +0 -477
- package/tests/integration.test.ts +0 -92
- /package/dist/sdk/api/resources/serviceApi/{client/requests/GetInterimResultsRequest.js → types/GetResultResponseEmbedded.js} +0 -0
- /package/dist/sdk/api/resources/serviceApi/{client/requests/StartExecutionRequest.js → types/GetResultResponseLinks.js} +0 -0
- /package/dist/sdk/api/resources/{statusApi → serviceApi}/types/HealthCheckResponse.js +0 -0
- /package/dist/sdk/api/{resources/serviceApi/types/GetInterimResultsResponse.js → types/HalLink.js} +0 -0
- /package/dist/sdk/api/types/{ArrayResponse.js → InputDataRef.js} +0 -0
- /package/dist/sdk/api/types/{InputRef.js → ServiceExecution.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.1.0"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from authlib.integrations.httpx_client import OAuth2Client
|
|
4
|
+
|
|
5
|
+
DEFAULT_TOKEN_ENDPOINT = "https://gateway.platform.planqk.de/token"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PlanqkServiceAuth:
|
|
9
|
+
def __init__(self, consumer_key: str, consumer_secret: str, token_endpoint: str = DEFAULT_TOKEN_ENDPOINT):
|
|
10
|
+
self._consumer_key = consumer_key
|
|
11
|
+
self._consumer_secret = consumer_secret
|
|
12
|
+
self._token_endpoint = token_endpoint
|
|
13
|
+
self._token = None
|
|
14
|
+
self._last_token_fetch = None
|
|
15
|
+
|
|
16
|
+
def get_token(self) -> str:
|
|
17
|
+
if self._token is None or self._last_token_fetch is None:
|
|
18
|
+
self._refresh_token()
|
|
19
|
+
|
|
20
|
+
if time.time() - self._last_token_fetch > self._token["expires_in"]:
|
|
21
|
+
self._refresh_token()
|
|
22
|
+
|
|
23
|
+
return self._token["access_token"]
|
|
24
|
+
|
|
25
|
+
def _refresh_token(self):
|
|
26
|
+
with OAuth2Client(self._consumer_key, self._consumer_secret) as client:
|
|
27
|
+
token = client.fetch_token(self._token_endpoint, grant_type='client_credentials')
|
|
28
|
+
|
|
29
|
+
self._token = token
|
|
30
|
+
self._last_token_fetch = time.time()
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import random
|
|
3
|
+
import string
|
|
4
|
+
import time
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
from planqk.service.auth import DEFAULT_TOKEN_ENDPOINT, PlanqkServiceAuth
|
|
8
|
+
from planqk.service.sdk import PlanqkServiceApi, HealthCheckResponse, ServiceExecution, GetResultResponse, NotFoundError
|
|
9
|
+
from planqk.service.sdk.service_api.client import ServiceApiClient
|
|
10
|
+
from planqk.service.sdk.types.service_execution_status import ServiceExecutionStatus
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PlanqkServiceExecution:
|
|
14
|
+
def __init__(self, client: "PlanqkServiceClient", service_execution: ServiceExecution):
|
|
15
|
+
self._client = client
|
|
16
|
+
self._service_execution = service_execution
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def id(self) -> str:
|
|
20
|
+
return self._service_execution.id
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def status(self) -> ServiceExecutionStatus:
|
|
24
|
+
return self._service_execution.status
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def created_at(self) -> str:
|
|
28
|
+
return self._service_execution.created_at
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def started_at(self) -> typing.Optional[str]:
|
|
32
|
+
return self._service_execution.started_at
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def ended_at(self) -> typing.Optional[str]:
|
|
36
|
+
return self._service_execution.ended_at
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def has_finished(self) -> bool:
|
|
40
|
+
self.refresh()
|
|
41
|
+
return self.status in ["SUCCEEDED", "FAILED", "CANCELLED"]
|
|
42
|
+
|
|
43
|
+
def wait_for_final_state(self, timeout: typing.Optional[float] = None, wait: float = 5) -> None:
|
|
44
|
+
"""
|
|
45
|
+
Poll the status until it progresses to a final state.
|
|
46
|
+
|
|
47
|
+
Parameters:
|
|
48
|
+
- timeout: Seconds to wait for the job. If ``None``, wait indefinitely.
|
|
49
|
+
- wait: Seconds between queries.
|
|
50
|
+
|
|
51
|
+
Raises:
|
|
52
|
+
Exception: If the service execution does not reach a final state before the specified timeout.
|
|
53
|
+
"""
|
|
54
|
+
start_time = time.time()
|
|
55
|
+
while not self.has_finished:
|
|
56
|
+
elapsed_time = time.time() - start_time
|
|
57
|
+
if timeout is not None and elapsed_time >= timeout:
|
|
58
|
+
raise TimeoutError(f"Timeout while waiting for service execution '{self.id}'.")
|
|
59
|
+
time.sleep(wait)
|
|
60
|
+
|
|
61
|
+
def refresh(self):
|
|
62
|
+
self._service_execution = self._client.api.get_status(id=self.id)
|
|
63
|
+
|
|
64
|
+
def result(self) -> GetResultResponse:
|
|
65
|
+
self.wait_for_final_state()
|
|
66
|
+
delay = 1 # Start with a small delay
|
|
67
|
+
max_delay = 16 # Maximum delay
|
|
68
|
+
while True:
|
|
69
|
+
try:
|
|
70
|
+
result = self._client.api.get_result(id=self.id)
|
|
71
|
+
break # If the operation succeeds, break out of the loop
|
|
72
|
+
except NotFoundError as e:
|
|
73
|
+
time.sleep(delay) # If the operation fails, wait
|
|
74
|
+
delay *= 2 # Double the delay
|
|
75
|
+
if delay >= max_delay:
|
|
76
|
+
raise e # If the delay is too long, raise the exception
|
|
77
|
+
return result
|
|
78
|
+
|
|
79
|
+
def result_files(self) -> typing.List[str]:
|
|
80
|
+
file_names = []
|
|
81
|
+
links = self.result().links
|
|
82
|
+
for link in links:
|
|
83
|
+
file_name = link[0]
|
|
84
|
+
if file_name in ["status", "self"]:
|
|
85
|
+
continue
|
|
86
|
+
file_names.append(file_name)
|
|
87
|
+
return file_names
|
|
88
|
+
|
|
89
|
+
def result_file_stream(self, file_name: str) -> typing.Iterator[bytes]:
|
|
90
|
+
return self._client.api.get_result_file(id=self.id, file=file_name)
|
|
91
|
+
|
|
92
|
+
def download_result_file(self, file_name: str, target_path: str) -> None:
|
|
93
|
+
# check if target path exists and is a directory
|
|
94
|
+
if not os.path.isdir(target_path):
|
|
95
|
+
raise ValueError(f"Target path '{target_path}' does not exist or is not a directory.")
|
|
96
|
+
|
|
97
|
+
abs_target_path = os.path.abspath(target_path)
|
|
98
|
+
file_path = os.path.join(abs_target_path, file_name)
|
|
99
|
+
|
|
100
|
+
iterator = self.result_file_stream(file_name)
|
|
101
|
+
with open(file_path, "wb") as f:
|
|
102
|
+
for chunk in iterator:
|
|
103
|
+
f.write(chunk)
|
|
104
|
+
|
|
105
|
+
def cancel(self) -> None:
|
|
106
|
+
self._client.api.cancel(id=self.id)
|
|
107
|
+
|
|
108
|
+
def logs(self) -> typing.List[str]:
|
|
109
|
+
return self._client.api.get_logs(id=self.id)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class PlanqkServiceClient:
|
|
113
|
+
def __init__(
|
|
114
|
+
self,
|
|
115
|
+
service_endpoint: str,
|
|
116
|
+
consumer_key: typing.Union[str, None],
|
|
117
|
+
consumer_secret: typing.Union[str, None],
|
|
118
|
+
token_endpoint: str = DEFAULT_TOKEN_ENDPOINT,
|
|
119
|
+
):
|
|
120
|
+
self._service_endpoint = service_endpoint
|
|
121
|
+
self._consumer_key = consumer_key
|
|
122
|
+
self._consumer_secret = consumer_secret
|
|
123
|
+
self._token_endpoint = token_endpoint
|
|
124
|
+
|
|
125
|
+
if (self._consumer_key is not None) or (self._consumer_secret is not None):
|
|
126
|
+
self._auth = PlanqkServiceAuth(
|
|
127
|
+
consumer_key=self._consumer_key,
|
|
128
|
+
consumer_secret=self._consumer_secret,
|
|
129
|
+
token_endpoint=self._token_endpoint,
|
|
130
|
+
)
|
|
131
|
+
self._api = PlanqkServiceApi(base_url=self._service_endpoint, token=self._auth.get_token)
|
|
132
|
+
else:
|
|
133
|
+
random_token = "".join(
|
|
134
|
+
random.choices(string.ascii_letters + string.digits, k=21)
|
|
135
|
+
)
|
|
136
|
+
self._api = PlanqkServiceApi(base_url=self._service_endpoint, token=random_token)
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def api(self) -> ServiceApiClient:
|
|
140
|
+
return self._api.service_api
|
|
141
|
+
|
|
142
|
+
def health_check(self) -> HealthCheckResponse:
|
|
143
|
+
return self.api.health_check()
|
|
144
|
+
|
|
145
|
+
def run(self, request: typing.Dict[str, typing.Dict[str, typing.Optional[typing.Any]]]) -> PlanqkServiceExecution:
|
|
146
|
+
service_execution = self.api.execute(request=request)
|
|
147
|
+
return PlanqkServiceExecution(client=self, service_execution=service_execution)
|
|
148
|
+
|
|
149
|
+
def get_service_execution(self, service_execution_id: str) -> PlanqkServiceExecution:
|
|
150
|
+
service_execution = self.api.get_status(id=service_execution_id)
|
|
151
|
+
return PlanqkServiceExecution(client=self, service_execution=service_execution)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from .types import (
|
|
4
|
+
HalLink,
|
|
5
|
+
InputData,
|
|
6
|
+
InputDataRef,
|
|
7
|
+
InputParams,
|
|
8
|
+
ServiceExecution,
|
|
9
|
+
ServiceExecutionStatus,
|
|
10
|
+
)
|
|
11
|
+
from .errors import (
|
|
12
|
+
BadRequestError,
|
|
13
|
+
ForbiddenError,
|
|
14
|
+
InternalServerError,
|
|
15
|
+
NotFoundError,
|
|
16
|
+
UnauthorizedError,
|
|
17
|
+
)
|
|
18
|
+
from . import service_api
|
|
19
|
+
from .client import AsyncPlanqkServiceApi, PlanqkServiceApi
|
|
20
|
+
from .environment import PlanqkServiceApiEnvironment
|
|
21
|
+
from .service_api import (
|
|
22
|
+
GetResultResponse,
|
|
23
|
+
GetResultResponseEmbedded,
|
|
24
|
+
GetResultResponseLinks,
|
|
25
|
+
HealthCheckResponse,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"AsyncPlanqkServiceApi",
|
|
30
|
+
"BadRequestError",
|
|
31
|
+
"ForbiddenError",
|
|
32
|
+
"GetResultResponse",
|
|
33
|
+
"GetResultResponseEmbedded",
|
|
34
|
+
"GetResultResponseLinks",
|
|
35
|
+
"HalLink",
|
|
36
|
+
"HealthCheckResponse",
|
|
37
|
+
"InputData",
|
|
38
|
+
"InputDataRef",
|
|
39
|
+
"InputParams",
|
|
40
|
+
"InternalServerError",
|
|
41
|
+
"NotFoundError",
|
|
42
|
+
"PlanqkServiceApi",
|
|
43
|
+
"PlanqkServiceApiEnvironment",
|
|
44
|
+
"ServiceExecution",
|
|
45
|
+
"ServiceExecutionStatus",
|
|
46
|
+
"UnauthorizedError",
|
|
47
|
+
"service_api",
|
|
48
|
+
]
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from .environment import PlanqkServiceApiEnvironment
|
|
5
|
+
import httpx
|
|
6
|
+
from .core.client_wrapper import SyncClientWrapper
|
|
7
|
+
from .service_api.client import ServiceApiClient
|
|
8
|
+
from .core.client_wrapper import AsyncClientWrapper
|
|
9
|
+
from .service_api.client import AsyncServiceApiClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PlanqkServiceApi:
|
|
13
|
+
"""
|
|
14
|
+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
base_url : typing.Optional[str]
|
|
19
|
+
The base url to use for requests from the client.
|
|
20
|
+
|
|
21
|
+
environment : PlanqkServiceApiEnvironment
|
|
22
|
+
The environment to use for requests from the client. from .environment import PlanqkServiceApiEnvironment
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Defaults to PlanqkServiceApiEnvironment.DEFAULT
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
token : typing.Union[str, typing.Callable[[], str]]
|
|
31
|
+
timeout : typing.Optional[float]
|
|
32
|
+
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
33
|
+
|
|
34
|
+
follow_redirects : typing.Optional[bool]
|
|
35
|
+
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
36
|
+
|
|
37
|
+
httpx_client : typing.Optional[httpx.Client]
|
|
38
|
+
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
|
|
39
|
+
|
|
40
|
+
Examples
|
|
41
|
+
--------
|
|
42
|
+
from planqk_service import PlanqkServiceApi
|
|
43
|
+
|
|
44
|
+
client = PlanqkServiceApi(
|
|
45
|
+
token="YOUR_TOKEN",
|
|
46
|
+
)
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
*,
|
|
52
|
+
base_url: typing.Optional[str] = None,
|
|
53
|
+
environment: PlanqkServiceApiEnvironment = PlanqkServiceApiEnvironment.DEFAULT,
|
|
54
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
55
|
+
timeout: typing.Optional[float] = None,
|
|
56
|
+
follow_redirects: typing.Optional[bool] = True,
|
|
57
|
+
httpx_client: typing.Optional[httpx.Client] = None,
|
|
58
|
+
):
|
|
59
|
+
_defaulted_timeout = (
|
|
60
|
+
timeout if timeout is not None else 60 if httpx_client is None else None
|
|
61
|
+
)
|
|
62
|
+
self._client_wrapper = SyncClientWrapper(
|
|
63
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
64
|
+
token=token,
|
|
65
|
+
httpx_client=httpx_client
|
|
66
|
+
if httpx_client is not None
|
|
67
|
+
else httpx.Client(
|
|
68
|
+
timeout=_defaulted_timeout, follow_redirects=follow_redirects
|
|
69
|
+
)
|
|
70
|
+
if follow_redirects is not None
|
|
71
|
+
else httpx.Client(timeout=_defaulted_timeout),
|
|
72
|
+
timeout=_defaulted_timeout,
|
|
73
|
+
)
|
|
74
|
+
self.service_api = ServiceApiClient(client_wrapper=self._client_wrapper)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class AsyncPlanqkServiceApi:
|
|
78
|
+
"""
|
|
79
|
+
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
base_url : typing.Optional[str]
|
|
84
|
+
The base url to use for requests from the client.
|
|
85
|
+
|
|
86
|
+
environment : PlanqkServiceApiEnvironment
|
|
87
|
+
The environment to use for requests from the client. from .environment import PlanqkServiceApiEnvironment
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
Defaults to PlanqkServiceApiEnvironment.DEFAULT
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
token : typing.Union[str, typing.Callable[[], str]]
|
|
96
|
+
timeout : typing.Optional[float]
|
|
97
|
+
The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
|
|
98
|
+
|
|
99
|
+
follow_redirects : typing.Optional[bool]
|
|
100
|
+
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
101
|
+
|
|
102
|
+
httpx_client : typing.Optional[httpx.AsyncClient]
|
|
103
|
+
The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
|
|
104
|
+
|
|
105
|
+
Examples
|
|
106
|
+
--------
|
|
107
|
+
from planqk_service import AsyncPlanqkServiceApi
|
|
108
|
+
|
|
109
|
+
client = AsyncPlanqkServiceApi(
|
|
110
|
+
token="YOUR_TOKEN",
|
|
111
|
+
)
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
def __init__(
|
|
115
|
+
self,
|
|
116
|
+
*,
|
|
117
|
+
base_url: typing.Optional[str] = None,
|
|
118
|
+
environment: PlanqkServiceApiEnvironment = PlanqkServiceApiEnvironment.DEFAULT,
|
|
119
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
120
|
+
timeout: typing.Optional[float] = None,
|
|
121
|
+
follow_redirects: typing.Optional[bool] = True,
|
|
122
|
+
httpx_client: typing.Optional[httpx.AsyncClient] = None,
|
|
123
|
+
):
|
|
124
|
+
_defaulted_timeout = (
|
|
125
|
+
timeout if timeout is not None else 60 if httpx_client is None else None
|
|
126
|
+
)
|
|
127
|
+
self._client_wrapper = AsyncClientWrapper(
|
|
128
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
129
|
+
token=token,
|
|
130
|
+
httpx_client=httpx_client
|
|
131
|
+
if httpx_client is not None
|
|
132
|
+
else httpx.AsyncClient(
|
|
133
|
+
timeout=_defaulted_timeout, follow_redirects=follow_redirects
|
|
134
|
+
)
|
|
135
|
+
if follow_redirects is not None
|
|
136
|
+
else httpx.AsyncClient(timeout=_defaulted_timeout),
|
|
137
|
+
timeout=_defaulted_timeout,
|
|
138
|
+
)
|
|
139
|
+
self.service_api = AsyncServiceApiClient(client_wrapper=self._client_wrapper)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _get_base_url(
|
|
143
|
+
*, base_url: typing.Optional[str] = None, environment: PlanqkServiceApiEnvironment
|
|
144
|
+
) -> str:
|
|
145
|
+
if base_url is not None:
|
|
146
|
+
return base_url
|
|
147
|
+
elif environment is not None:
|
|
148
|
+
return environment.value
|
|
149
|
+
else:
|
|
150
|
+
raise Exception(
|
|
151
|
+
"Please pass in either base_url or environment to construct the client"
|
|
152
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from .api_error import ApiError
|
|
4
|
+
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
|
|
5
|
+
from .datetime_utils import serialize_datetime
|
|
6
|
+
from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
|
|
7
|
+
from .http_client import AsyncHttpClient, HttpClient
|
|
8
|
+
from .jsonable_encoder import jsonable_encoder
|
|
9
|
+
from .pydantic_utilities import (
|
|
10
|
+
IS_PYDANTIC_V2,
|
|
11
|
+
UniversalBaseModel,
|
|
12
|
+
UniversalRootModel,
|
|
13
|
+
parse_obj_as,
|
|
14
|
+
universal_field_validator,
|
|
15
|
+
universal_root_validator,
|
|
16
|
+
update_forward_refs,
|
|
17
|
+
)
|
|
18
|
+
from .query_encoder import encode_query
|
|
19
|
+
from .remove_none_from_dict import remove_none_from_dict
|
|
20
|
+
from .request_options import RequestOptions
|
|
21
|
+
from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"ApiError",
|
|
25
|
+
"AsyncClientWrapper",
|
|
26
|
+
"AsyncHttpClient",
|
|
27
|
+
"BaseClientWrapper",
|
|
28
|
+
"FieldMetadata",
|
|
29
|
+
"File",
|
|
30
|
+
"HttpClient",
|
|
31
|
+
"IS_PYDANTIC_V2",
|
|
32
|
+
"RequestOptions",
|
|
33
|
+
"SyncClientWrapper",
|
|
34
|
+
"UniversalBaseModel",
|
|
35
|
+
"UniversalRootModel",
|
|
36
|
+
"convert_and_respect_annotation_metadata",
|
|
37
|
+
"convert_file_dict_to_httpx_tuples",
|
|
38
|
+
"encode_query",
|
|
39
|
+
"jsonable_encoder",
|
|
40
|
+
"parse_obj_as",
|
|
41
|
+
"remove_none_from_dict",
|
|
42
|
+
"serialize_datetime",
|
|
43
|
+
"universal_field_validator",
|
|
44
|
+
"universal_root_validator",
|
|
45
|
+
"update_forward_refs",
|
|
46
|
+
"with_content_type",
|
|
47
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ApiError(Exception):
|
|
7
|
+
status_code: typing.Optional[int]
|
|
8
|
+
body: typing.Any
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self, *, status_code: typing.Optional[int] = None, body: typing.Any = None
|
|
12
|
+
):
|
|
13
|
+
self.status_code = status_code
|
|
14
|
+
self.body = body
|
|
15
|
+
|
|
16
|
+
def __str__(self) -> str:
|
|
17
|
+
return f"status_code: {self.status_code}, body: {self.body}"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
import httpx
|
|
5
|
+
from .http_client import HttpClient
|
|
6
|
+
from .http_client import AsyncHttpClient
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BaseClientWrapper:
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
*,
|
|
13
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
14
|
+
base_url: str,
|
|
15
|
+
timeout: typing.Optional[float] = None,
|
|
16
|
+
):
|
|
17
|
+
self._token = token
|
|
18
|
+
self._base_url = base_url
|
|
19
|
+
self._timeout = timeout
|
|
20
|
+
|
|
21
|
+
def get_headers(self) -> typing.Dict[str, str]:
|
|
22
|
+
headers: typing.Dict[str, str] = {
|
|
23
|
+
"X-Fern-Language": "Python",
|
|
24
|
+
}
|
|
25
|
+
headers["Authorization"] = f"Bearer {self._get_token()}"
|
|
26
|
+
return headers
|
|
27
|
+
|
|
28
|
+
def _get_token(self) -> str:
|
|
29
|
+
if isinstance(self._token, str):
|
|
30
|
+
return self._token
|
|
31
|
+
else:
|
|
32
|
+
return self._token()
|
|
33
|
+
|
|
34
|
+
def get_base_url(self) -> str:
|
|
35
|
+
return self._base_url
|
|
36
|
+
|
|
37
|
+
def get_timeout(self) -> typing.Optional[float]:
|
|
38
|
+
return self._timeout
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class SyncClientWrapper(BaseClientWrapper):
|
|
42
|
+
def __init__(
|
|
43
|
+
self,
|
|
44
|
+
*,
|
|
45
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
46
|
+
base_url: str,
|
|
47
|
+
timeout: typing.Optional[float] = None,
|
|
48
|
+
httpx_client: httpx.Client,
|
|
49
|
+
):
|
|
50
|
+
super().__init__(token=token, base_url=base_url, timeout=timeout)
|
|
51
|
+
self.httpx_client = HttpClient(
|
|
52
|
+
httpx_client=httpx_client,
|
|
53
|
+
base_headers=self.get_headers,
|
|
54
|
+
base_timeout=self.get_timeout,
|
|
55
|
+
base_url=self.get_base_url,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class AsyncClientWrapper(BaseClientWrapper):
|
|
60
|
+
def __init__(
|
|
61
|
+
self,
|
|
62
|
+
*,
|
|
63
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
64
|
+
base_url: str,
|
|
65
|
+
timeout: typing.Optional[float] = None,
|
|
66
|
+
httpx_client: httpx.AsyncClient,
|
|
67
|
+
):
|
|
68
|
+
super().__init__(token=token, base_url=base_url, timeout=timeout)
|
|
69
|
+
self.httpx_client = AsyncHttpClient(
|
|
70
|
+
httpx_client=httpx_client,
|
|
71
|
+
base_headers=self.get_headers,
|
|
72
|
+
base_timeout=self.get_timeout,
|
|
73
|
+
base_url=self.get_base_url,
|
|
74
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import datetime as dt
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def serialize_datetime(v: dt.datetime) -> str:
|
|
7
|
+
"""
|
|
8
|
+
Serialize a datetime including timezone info.
|
|
9
|
+
|
|
10
|
+
Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
|
|
11
|
+
|
|
12
|
+
UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def _serialize_zoned_datetime(v: dt.datetime) -> str:
|
|
16
|
+
if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(
|
|
17
|
+
None
|
|
18
|
+
):
|
|
19
|
+
# UTC is a special case where we use "Z" at the end instead of "+00:00"
|
|
20
|
+
return v.isoformat().replace("+00:00", "Z")
|
|
21
|
+
else:
|
|
22
|
+
# Delegate to the typical +/- offset format
|
|
23
|
+
return v.isoformat()
|
|
24
|
+
|
|
25
|
+
if v.tzinfo is not None:
|
|
26
|
+
return _serialize_zoned_datetime(v)
|
|
27
|
+
else:
|
|
28
|
+
local_tz = dt.datetime.now().astimezone().tzinfo
|
|
29
|
+
localized_dt = v.replace(tzinfo=local_tz)
|
|
30
|
+
return _serialize_zoned_datetime(localized_dt)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from typing import IO, Dict, List, Mapping, Optional, Tuple, Union, cast
|
|
4
|
+
|
|
5
|
+
# File typing inspired by the flexibility of types within the httpx library
|
|
6
|
+
# https://github.com/encode/httpx/blob/master/httpx/_types.py
|
|
7
|
+
FileContent = Union[IO[bytes], bytes, str]
|
|
8
|
+
File = Union[
|
|
9
|
+
# file (or bytes)
|
|
10
|
+
FileContent,
|
|
11
|
+
# (filename, file (or bytes))
|
|
12
|
+
Tuple[Optional[str], FileContent],
|
|
13
|
+
# (filename, file (or bytes), content_type)
|
|
14
|
+
Tuple[Optional[str], FileContent, Optional[str]],
|
|
15
|
+
# (filename, file (or bytes), content_type, headers)
|
|
16
|
+
Tuple[
|
|
17
|
+
Optional[str],
|
|
18
|
+
FileContent,
|
|
19
|
+
Optional[str],
|
|
20
|
+
Mapping[str, str],
|
|
21
|
+
],
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def convert_file_dict_to_httpx_tuples(
|
|
26
|
+
d: Dict[str, Union[File, List[File]]],
|
|
27
|
+
) -> List[Tuple[str, File]]:
|
|
28
|
+
"""
|
|
29
|
+
The format we use is a list of tuples, where the first element is the
|
|
30
|
+
name of the file and the second is the file object. Typically HTTPX wants
|
|
31
|
+
a dict, but to be able to send lists of files, you have to use the list
|
|
32
|
+
approach (which also works for non-lists)
|
|
33
|
+
https://github.com/encode/httpx/pull/1032
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
httpx_tuples = []
|
|
37
|
+
for key, file_like in d.items():
|
|
38
|
+
if isinstance(file_like, list):
|
|
39
|
+
for file_like_item in file_like:
|
|
40
|
+
httpx_tuples.append((key, file_like_item))
|
|
41
|
+
else:
|
|
42
|
+
httpx_tuples.append((key, file_like))
|
|
43
|
+
return httpx_tuples
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def with_content_type(*, file: File, default_content_type: str) -> File:
|
|
47
|
+
"""
|
|
48
|
+
This function resolves to the file's content type, if provided, and defaults
|
|
49
|
+
to the default_content_type value if not.
|
|
50
|
+
"""
|
|
51
|
+
if isinstance(file, tuple):
|
|
52
|
+
if len(file) == 2:
|
|
53
|
+
filename, content = cast(Tuple[Optional[str], FileContent], file) # type: ignore
|
|
54
|
+
return (filename, content, default_content_type)
|
|
55
|
+
elif len(file) == 3:
|
|
56
|
+
filename, content, file_content_type = cast(
|
|
57
|
+
Tuple[Optional[str], FileContent, Optional[str]], file
|
|
58
|
+
) # type: ignore
|
|
59
|
+
out_content_type = file_content_type or default_content_type
|
|
60
|
+
return (filename, content, out_content_type)
|
|
61
|
+
elif len(file) == 4:
|
|
62
|
+
filename, content, file_content_type, headers = cast( # type: ignore
|
|
63
|
+
Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]],
|
|
64
|
+
file,
|
|
65
|
+
)
|
|
66
|
+
out_content_type = file_content_type or default_content_type
|
|
67
|
+
return (filename, content, out_content_type, headers)
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError(f"Unexpected tuple length: {len(file)}")
|
|
70
|
+
return (None, file, default_content_type)
|