@planqk/planqk-service-sdk 2.6.2 → 2.8.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/dist/sdk/BaseClient.d.ts +26 -0
- package/dist/sdk/{api/resources/serviceApi/types/GetResultResponse.js → BaseClient.js} +1 -3
- package/dist/sdk/Client.d.ts +4 -22
- package/dist/sdk/Client.js +2 -4
- package/dist/sdk/api/index.d.ts +1 -1
- package/dist/sdk/api/index.js +1 -1
- package/dist/sdk/api/resources/index.d.ts +0 -1
- package/dist/sdk/api/resources/index.js +0 -4
- package/dist/sdk/api/resources/serviceApi/client/Client.d.ts +9 -26
- package/dist/sdk/api/resources/serviceApi/client/Client.js +43 -27
- package/dist/sdk/api/resources/serviceApi/index.d.ts +0 -1
- package/dist/sdk/api/resources/serviceApi/index.js +0 -1
- package/dist/sdk/api/types/HalLink.d.ts +0 -3
- package/dist/sdk/api/types/HalLink.js +1 -3
- package/dist/sdk/api/types/LogEntry.d.ts +19 -0
- package/dist/sdk/api/types/LogEntry.js +15 -0
- package/dist/sdk/api/types/RequestBody.d.ts +1 -0
- package/dist/sdk/api/types/RequestBody.js +3 -0
- package/dist/sdk/api/types/ResultResponse.d.ts +15 -0
- package/dist/sdk/api/types/ResultResponse.js +3 -0
- package/dist/sdk/api/types/ServiceExecution.d.ts +1 -4
- package/dist/sdk/api/types/ServiceExecution.js +1 -3
- package/dist/sdk/api/types/index.d.ts +3 -0
- package/dist/sdk/api/types/index.js +3 -0
- package/dist/sdk/core/auth/AuthProvider.d.ts +4 -0
- package/dist/sdk/core/auth/AuthProvider.js +2 -0
- package/dist/sdk/core/auth/AuthRequest.d.ts +9 -0
- package/dist/sdk/core/auth/AuthRequest.js +2 -0
- package/dist/sdk/core/auth/BasicAuth.js +2 -1
- package/dist/sdk/core/auth/index.d.ts +2 -0
- package/dist/sdk/core/fetcher/APIResponse.d.ts +1 -1
- package/dist/sdk/core/fetcher/BinaryResponse.d.ts +1 -1
- package/dist/sdk/core/fetcher/EndpointMetadata.d.ts +13 -0
- package/dist/sdk/core/fetcher/EndpointMetadata.js +2 -0
- package/dist/sdk/core/fetcher/EndpointSupplier.d.ts +12 -0
- package/dist/sdk/core/fetcher/EndpointSupplier.js +13 -0
- package/dist/sdk/core/fetcher/Fetcher.d.ts +6 -4
- package/dist/sdk/core/fetcher/Fetcher.js +3 -3
- package/dist/sdk/core/fetcher/HttpResponsePromise.d.ts +1 -1
- package/dist/sdk/core/fetcher/index.d.ts +7 -5
- package/dist/sdk/core/fetcher/index.js +7 -5
- package/dist/sdk/core/fetcher/requestWithRetries.js +44 -8
- package/dist/sdk/core/headers.d.ts +2 -3
- package/dist/sdk/core/url/join.js +23 -3
- package/dist/sdk/environments.d.ts +0 -3
- package/dist/sdk/environments.js +1 -3
- package/dist/sdk/errors/PlanqkServiceApiError.d.ts +0 -3
- package/dist/sdk/errors/PlanqkServiceApiError.js +1 -3
- package/dist/sdk/errors/PlanqkServiceApiTimeoutError.d.ts +0 -3
- package/dist/sdk/errors/PlanqkServiceApiTimeoutError.js +1 -3
- package/dist/sdk/index.d.ts +1 -0
- package/fern/fern.config.json +1 -1
- package/fern/generators.yml +6 -4
- package/fern/openapi/openapi.yml +115 -80
- package/package.json +1 -1
- package/planqk/service/_version.py +1 -1
- package/planqk/service/client.py +3 -3
- package/planqk/service/sdk/__init__.py +61 -8
- package/planqk/service/sdk/client.py +27 -7
- package/planqk/service/sdk/core/__init__.py +80 -20
- package/planqk/service/sdk/core/client_wrapper.py +8 -6
- package/planqk/service/sdk/core/force_multipart.py +4 -2
- package/planqk/service/sdk/core/http_response.py +1 -1
- package/planqk/service/sdk/core/http_sse/__init__.py +42 -0
- package/planqk/service/sdk/core/http_sse/_api.py +112 -0
- package/planqk/service/sdk/core/http_sse/_decoders.py +61 -0
- package/planqk/service/sdk/core/http_sse/_exceptions.py +7 -0
- package/planqk/service/sdk/core/http_sse/_models.py +17 -0
- package/planqk/service/sdk/core/pydantic_utilities.py +5 -2
- package/planqk/service/sdk/core/unchecked_base_model.py +341 -0
- package/planqk/service/sdk/service_api/__init__.py +0 -3
- package/planqk/service/sdk/service_api/client.py +17 -21
- package/planqk/service/sdk/service_api/raw_client.py +36 -40
- package/planqk/service/sdk/types/__init__.py +57 -4
- package/planqk/service/sdk/types/hal_link.py +3 -2
- package/planqk/service/sdk/types/log_entry.py +35 -0
- package/planqk/service/sdk/types/log_entry_severity.py +5 -0
- package/planqk/service/sdk/types/request_body.py +5 -0
- package/planqk/service/sdk/types/result_response.py +27 -0
- package/planqk/service/sdk/{service_api/types/get_result_response_embedded.py → types/result_response_embedded.py} +4 -3
- package/planqk/service/sdk/{service_api/types/get_result_response_links.py → types/result_response_links.py} +4 -3
- package/planqk/service/sdk/types/service_execution.py +3 -2
- package/pyproject.toml +1 -1
- package/requirements-dev.txt +59 -43
- package/requirements.txt +6 -6
- package/src/index.test.ts +10 -0
- package/src/sdk/BaseClient.ts +30 -0
- package/src/sdk/Client.ts +6 -23
- package/src/sdk/api/index.ts +1 -1
- package/src/sdk/api/resources/index.ts +0 -1
- package/src/sdk/api/resources/serviceApi/client/Client.ts +87 -82
- package/src/sdk/api/resources/serviceApi/index.ts +0 -1
- package/src/sdk/api/types/HalLink.ts +1 -3
- package/src/sdk/api/types/LogEntry.ts +22 -0
- package/src/sdk/api/types/RequestBody.ts +3 -0
- package/src/sdk/api/types/ResultResponse.ts +20 -0
- package/src/sdk/api/types/ServiceExecution.ts +2 -4
- package/src/sdk/api/types/index.ts +3 -0
- package/src/sdk/core/auth/AuthProvider.ts +5 -0
- package/src/sdk/core/auth/AuthRequest.ts +9 -0
- package/src/sdk/core/auth/BasicAuth.ts +2 -1
- package/src/sdk/core/auth/index.ts +2 -0
- package/src/sdk/core/fetcher/APIResponse.ts +1 -1
- package/src/sdk/core/fetcher/BinaryResponse.ts +1 -1
- package/src/sdk/core/fetcher/EndpointMetadata.ts +13 -0
- package/src/sdk/core/fetcher/EndpointSupplier.ts +14 -0
- package/src/sdk/core/fetcher/Fetcher.ts +8 -6
- package/src/sdk/core/fetcher/HttpResponsePromise.ts +1 -1
- package/src/sdk/core/fetcher/index.ts +7 -5
- package/src/sdk/core/fetcher/requestWithRetries.ts +49 -9
- package/src/sdk/core/headers.ts +8 -10
- package/src/sdk/core/url/join.ts +28 -3
- package/src/sdk/environments.ts +1 -3
- package/src/sdk/errors/PlanqkServiceApiError.ts +1 -3
- package/src/sdk/errors/PlanqkServiceApiTimeoutError.ts +1 -3
- package/src/sdk/index.ts +1 -0
- package/uv.lock +77 -47
- package/dist/sdk/api/resources/serviceApi/types/GetResultResponse.d.ts +0 -18
- package/dist/sdk/api/resources/serviceApi/types/index.d.ts +0 -1
- package/dist/sdk/api/resources/serviceApi/types/index.js +0 -17
- package/planqk/service/sdk/service_api/types/__init__.py +0 -9
- package/planqk/service/sdk/service_api/types/get_result_response.py +0 -26
- package/src/sdk/api/resources/serviceApi/types/GetResultResponse.ts +0 -22
- package/src/sdk/api/resources/serviceApi/types/index.ts +0 -1
|
@@ -2,20 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
# isort: skip_file
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from .
|
|
5
|
+
import typing
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from .types import (
|
|
10
|
+
HalLink,
|
|
11
|
+
LogEntry,
|
|
12
|
+
LogEntrySeverity,
|
|
13
|
+
RequestBody,
|
|
14
|
+
ResultResponse,
|
|
15
|
+
ResultResponseEmbedded,
|
|
16
|
+
ResultResponseLinks,
|
|
17
|
+
ServiceExecution,
|
|
18
|
+
ServiceExecutionStatus,
|
|
19
|
+
)
|
|
20
|
+
from . import service_api
|
|
21
|
+
from .client import AsyncPlanqkServiceApi, PlanqkServiceApi
|
|
22
|
+
from .environment import PlanqkServiceApiEnvironment
|
|
23
|
+
_dynamic_imports: typing.Dict[str, str] = {
|
|
24
|
+
"AsyncPlanqkServiceApi": ".client",
|
|
25
|
+
"HalLink": ".types",
|
|
26
|
+
"LogEntry": ".types",
|
|
27
|
+
"LogEntrySeverity": ".types",
|
|
28
|
+
"PlanqkServiceApi": ".client",
|
|
29
|
+
"PlanqkServiceApiEnvironment": ".environment",
|
|
30
|
+
"RequestBody": ".types",
|
|
31
|
+
"ResultResponse": ".types",
|
|
32
|
+
"ResultResponseEmbedded": ".types",
|
|
33
|
+
"ResultResponseLinks": ".types",
|
|
34
|
+
"ServiceExecution": ".types",
|
|
35
|
+
"ServiceExecutionStatus": ".types",
|
|
36
|
+
"service_api": ".service_api",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def __getattr__(attr_name: str) -> typing.Any:
|
|
41
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
42
|
+
if module_name is None:
|
|
43
|
+
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
|
|
44
|
+
try:
|
|
45
|
+
module = import_module(module_name, __package__)
|
|
46
|
+
if module_name == f".{attr_name}":
|
|
47
|
+
return module
|
|
48
|
+
else:
|
|
49
|
+
return getattr(module, attr_name)
|
|
50
|
+
except ImportError as e:
|
|
51
|
+
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
|
|
52
|
+
except AttributeError as e:
|
|
53
|
+
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def __dir__():
|
|
57
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
58
|
+
return sorted(lazy_attrs)
|
|
59
|
+
|
|
10
60
|
|
|
11
61
|
__all__ = [
|
|
12
62
|
"AsyncPlanqkServiceApi",
|
|
13
|
-
"GetResultResponse",
|
|
14
|
-
"GetResultResponseEmbedded",
|
|
15
|
-
"GetResultResponseLinks",
|
|
16
63
|
"HalLink",
|
|
64
|
+
"LogEntry",
|
|
65
|
+
"LogEntrySeverity",
|
|
17
66
|
"PlanqkServiceApi",
|
|
18
67
|
"PlanqkServiceApiEnvironment",
|
|
68
|
+
"RequestBody",
|
|
69
|
+
"ResultResponse",
|
|
70
|
+
"ResultResponseEmbedded",
|
|
71
|
+
"ResultResponseLinks",
|
|
19
72
|
"ServiceExecution",
|
|
20
73
|
"ServiceExecutionStatus",
|
|
21
74
|
"service_api",
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
3
5
|
import typing
|
|
4
6
|
|
|
5
7
|
import httpx
|
|
6
8
|
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
7
9
|
from .environment import PlanqkServiceApiEnvironment
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
if typing.TYPE_CHECKING:
|
|
12
|
+
from .service_api.client import AsyncServiceApiClient, ServiceApiClient
|
|
9
13
|
|
|
10
14
|
|
|
11
15
|
class PlanqkServiceApi:
|
|
@@ -26,7 +30,7 @@ class PlanqkServiceApi:
|
|
|
26
30
|
|
|
27
31
|
|
|
28
32
|
|
|
29
|
-
token : typing.Union[str, typing.Callable[[], str]]
|
|
33
|
+
token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
|
|
30
34
|
headers : typing.Optional[typing.Dict[str, str]]
|
|
31
35
|
Additional headers to send with every request.
|
|
32
36
|
|
|
@@ -53,7 +57,7 @@ class PlanqkServiceApi:
|
|
|
53
57
|
*,
|
|
54
58
|
base_url: typing.Optional[str] = None,
|
|
55
59
|
environment: PlanqkServiceApiEnvironment = PlanqkServiceApiEnvironment.DEFAULT,
|
|
56
|
-
token: typing.Union[str, typing.Callable[[], str]],
|
|
60
|
+
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
|
|
57
61
|
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
58
62
|
timeout: typing.Optional[float] = None,
|
|
59
63
|
follow_redirects: typing.Optional[bool] = True,
|
|
@@ -73,7 +77,15 @@ class PlanqkServiceApi:
|
|
|
73
77
|
else httpx.Client(timeout=_defaulted_timeout),
|
|
74
78
|
timeout=_defaulted_timeout,
|
|
75
79
|
)
|
|
76
|
-
self.
|
|
80
|
+
self._service_api: typing.Optional[ServiceApiClient] = None
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def service_api(self):
|
|
84
|
+
if self._service_api is None:
|
|
85
|
+
from .service_api.client import ServiceApiClient # noqa: E402
|
|
86
|
+
|
|
87
|
+
self._service_api = ServiceApiClient(client_wrapper=self._client_wrapper)
|
|
88
|
+
return self._service_api
|
|
77
89
|
|
|
78
90
|
|
|
79
91
|
class AsyncPlanqkServiceApi:
|
|
@@ -94,7 +106,7 @@ class AsyncPlanqkServiceApi:
|
|
|
94
106
|
|
|
95
107
|
|
|
96
108
|
|
|
97
|
-
token : typing.Union[str, typing.Callable[[], str]]
|
|
109
|
+
token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
|
|
98
110
|
headers : typing.Optional[typing.Dict[str, str]]
|
|
99
111
|
Additional headers to send with every request.
|
|
100
112
|
|
|
@@ -121,7 +133,7 @@ class AsyncPlanqkServiceApi:
|
|
|
121
133
|
*,
|
|
122
134
|
base_url: typing.Optional[str] = None,
|
|
123
135
|
environment: PlanqkServiceApiEnvironment = PlanqkServiceApiEnvironment.DEFAULT,
|
|
124
|
-
token: typing.Union[str, typing.Callable[[], str]],
|
|
136
|
+
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
|
|
125
137
|
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
126
138
|
timeout: typing.Optional[float] = None,
|
|
127
139
|
follow_redirects: typing.Optional[bool] = True,
|
|
@@ -141,7 +153,15 @@ class AsyncPlanqkServiceApi:
|
|
|
141
153
|
else httpx.AsyncClient(timeout=_defaulted_timeout),
|
|
142
154
|
timeout=_defaulted_timeout,
|
|
143
155
|
)
|
|
144
|
-
self.
|
|
156
|
+
self._service_api: typing.Optional[AsyncServiceApiClient] = None
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def service_api(self):
|
|
160
|
+
if self._service_api is None:
|
|
161
|
+
from .service_api.client import AsyncServiceApiClient # noqa: E402
|
|
162
|
+
|
|
163
|
+
self._service_api = AsyncServiceApiClient(client_wrapper=self._client_wrapper)
|
|
164
|
+
return self._service_api
|
|
145
165
|
|
|
146
166
|
|
|
147
167
|
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: PlanqkServiceApiEnvironment) -> str:
|
|
@@ -2,26 +2,83 @@
|
|
|
2
2
|
|
|
3
3
|
# isort: skip_file
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from .
|
|
10
|
-
from .
|
|
11
|
-
from .
|
|
12
|
-
from .
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
import typing
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from .api_error import ApiError
|
|
10
|
+
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
|
|
11
|
+
from .datetime_utils import serialize_datetime
|
|
12
|
+
from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
|
|
13
|
+
from .http_client import AsyncHttpClient, HttpClient
|
|
14
|
+
from .http_response import AsyncHttpResponse, HttpResponse
|
|
15
|
+
from .jsonable_encoder import jsonable_encoder
|
|
16
|
+
from .pydantic_utilities import (
|
|
17
|
+
IS_PYDANTIC_V2,
|
|
18
|
+
UniversalBaseModel,
|
|
19
|
+
UniversalRootModel,
|
|
20
|
+
parse_obj_as,
|
|
21
|
+
universal_field_validator,
|
|
22
|
+
universal_root_validator,
|
|
23
|
+
update_forward_refs,
|
|
24
|
+
)
|
|
25
|
+
from .query_encoder import encode_query
|
|
26
|
+
from .remove_none_from_dict import remove_none_from_dict
|
|
27
|
+
from .request_options import RequestOptions
|
|
28
|
+
from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
|
|
29
|
+
from .unchecked_base_model import UncheckedBaseModel, UnionMetadata, construct_type
|
|
30
|
+
_dynamic_imports: typing.Dict[str, str] = {
|
|
31
|
+
"ApiError": ".api_error",
|
|
32
|
+
"AsyncClientWrapper": ".client_wrapper",
|
|
33
|
+
"AsyncHttpClient": ".http_client",
|
|
34
|
+
"AsyncHttpResponse": ".http_response",
|
|
35
|
+
"BaseClientWrapper": ".client_wrapper",
|
|
36
|
+
"FieldMetadata": ".serialization",
|
|
37
|
+
"File": ".file",
|
|
38
|
+
"HttpClient": ".http_client",
|
|
39
|
+
"HttpResponse": ".http_response",
|
|
40
|
+
"IS_PYDANTIC_V2": ".pydantic_utilities",
|
|
41
|
+
"RequestOptions": ".request_options",
|
|
42
|
+
"SyncClientWrapper": ".client_wrapper",
|
|
43
|
+
"UncheckedBaseModel": ".unchecked_base_model",
|
|
44
|
+
"UnionMetadata": ".unchecked_base_model",
|
|
45
|
+
"UniversalBaseModel": ".pydantic_utilities",
|
|
46
|
+
"UniversalRootModel": ".pydantic_utilities",
|
|
47
|
+
"construct_type": ".unchecked_base_model",
|
|
48
|
+
"convert_and_respect_annotation_metadata": ".serialization",
|
|
49
|
+
"convert_file_dict_to_httpx_tuples": ".file",
|
|
50
|
+
"encode_query": ".query_encoder",
|
|
51
|
+
"jsonable_encoder": ".jsonable_encoder",
|
|
52
|
+
"parse_obj_as": ".pydantic_utilities",
|
|
53
|
+
"remove_none_from_dict": ".remove_none_from_dict",
|
|
54
|
+
"serialize_datetime": ".datetime_utils",
|
|
55
|
+
"universal_field_validator": ".pydantic_utilities",
|
|
56
|
+
"universal_root_validator": ".pydantic_utilities",
|
|
57
|
+
"update_forward_refs": ".pydantic_utilities",
|
|
58
|
+
"with_content_type": ".file",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def __getattr__(attr_name: str) -> typing.Any:
|
|
63
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
64
|
+
if module_name is None:
|
|
65
|
+
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
|
|
66
|
+
try:
|
|
67
|
+
module = import_module(module_name, __package__)
|
|
68
|
+
if module_name == f".{attr_name}":
|
|
69
|
+
return module
|
|
70
|
+
else:
|
|
71
|
+
return getattr(module, attr_name)
|
|
72
|
+
except ImportError as e:
|
|
73
|
+
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
|
|
74
|
+
except AttributeError as e:
|
|
75
|
+
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def __dir__():
|
|
79
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
80
|
+
return sorted(lazy_attrs)
|
|
81
|
+
|
|
25
82
|
|
|
26
83
|
__all__ = [
|
|
27
84
|
"ApiError",
|
|
@@ -36,8 +93,11 @@ __all__ = [
|
|
|
36
93
|
"IS_PYDANTIC_V2",
|
|
37
94
|
"RequestOptions",
|
|
38
95
|
"SyncClientWrapper",
|
|
96
|
+
"UncheckedBaseModel",
|
|
97
|
+
"UnionMetadata",
|
|
39
98
|
"UniversalBaseModel",
|
|
40
99
|
"UniversalRootModel",
|
|
100
|
+
"construct_type",
|
|
41
101
|
"convert_and_respect_annotation_metadata",
|
|
42
102
|
"convert_file_dict_to_httpx_tuples",
|
|
43
103
|
"encode_query",
|
|
@@ -10,7 +10,7 @@ class BaseClientWrapper:
|
|
|
10
10
|
def __init__(
|
|
11
11
|
self,
|
|
12
12
|
*,
|
|
13
|
-
token: typing.Union[str, typing.Callable[[], str]],
|
|
13
|
+
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
|
|
14
14
|
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
15
15
|
base_url: str,
|
|
16
16
|
timeout: typing.Optional[float] = None,
|
|
@@ -25,11 +25,13 @@ class BaseClientWrapper:
|
|
|
25
25
|
"X-Fern-Language": "Python",
|
|
26
26
|
**(self.get_custom_headers() or {}),
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
token = self._get_token()
|
|
29
|
+
if token is not None:
|
|
30
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
29
31
|
return headers
|
|
30
32
|
|
|
31
|
-
def _get_token(self) -> str:
|
|
32
|
-
if isinstance(self._token, str):
|
|
33
|
+
def _get_token(self) -> typing.Optional[str]:
|
|
34
|
+
if isinstance(self._token, str) or self._token is None:
|
|
33
35
|
return self._token
|
|
34
36
|
else:
|
|
35
37
|
return self._token()
|
|
@@ -48,7 +50,7 @@ class SyncClientWrapper(BaseClientWrapper):
|
|
|
48
50
|
def __init__(
|
|
49
51
|
self,
|
|
50
52
|
*,
|
|
51
|
-
token: typing.Union[str, typing.Callable[[], str]],
|
|
53
|
+
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
|
|
52
54
|
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
53
55
|
base_url: str,
|
|
54
56
|
timeout: typing.Optional[float] = None,
|
|
@@ -67,7 +69,7 @@ class AsyncClientWrapper(BaseClientWrapper):
|
|
|
67
69
|
def __init__(
|
|
68
70
|
self,
|
|
69
71
|
*,
|
|
70
|
-
token: typing.Union[str, typing.Callable[[], str]],
|
|
72
|
+
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
|
|
71
73
|
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
72
74
|
base_url: str,
|
|
73
75
|
timeout: typing.Optional[float] = None,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# This file was auto-generated by Fern from our API Definition.
|
|
2
2
|
|
|
3
|
+
from typing import Any, Dict
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
class ForceMultipartDict(Dict[str, Any]):
|
|
5
7
|
"""
|
|
6
8
|
A dictionary subclass that always evaluates to True in boolean contexts.
|
|
7
9
|
|
|
@@ -9,7 +11,7 @@ class ForceMultipartDict(dict):
|
|
|
9
11
|
the dictionary is empty, which would normally evaluate to False.
|
|
10
12
|
"""
|
|
11
13
|
|
|
12
|
-
def __bool__(self):
|
|
14
|
+
def __bool__(self) -> bool:
|
|
13
15
|
return True
|
|
14
16
|
|
|
15
17
|
|
|
@@ -4,8 +4,8 @@ from typing import Dict, Generic, TypeVar
|
|
|
4
4
|
|
|
5
5
|
import httpx
|
|
6
6
|
|
|
7
|
+
# Generic to represent the underlying type of the data wrapped by the HTTP response.
|
|
7
8
|
T = TypeVar("T")
|
|
8
|
-
"""Generic to represent the underlying type of the data wrapped by the HTTP response."""
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class BaseHttpResponse:
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
5
|
+
import typing
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from ._api import EventSource, aconnect_sse, connect_sse
|
|
10
|
+
from ._exceptions import SSEError
|
|
11
|
+
from ._models import ServerSentEvent
|
|
12
|
+
_dynamic_imports: typing.Dict[str, str] = {
|
|
13
|
+
"EventSource": "._api",
|
|
14
|
+
"SSEError": "._exceptions",
|
|
15
|
+
"ServerSentEvent": "._models",
|
|
16
|
+
"aconnect_sse": "._api",
|
|
17
|
+
"connect_sse": "._api",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def __getattr__(attr_name: str) -> typing.Any:
|
|
22
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
23
|
+
if module_name is None:
|
|
24
|
+
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
|
|
25
|
+
try:
|
|
26
|
+
module = import_module(module_name, __package__)
|
|
27
|
+
if module_name == f".{attr_name}":
|
|
28
|
+
return module
|
|
29
|
+
else:
|
|
30
|
+
return getattr(module, attr_name)
|
|
31
|
+
except ImportError as e:
|
|
32
|
+
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
|
|
33
|
+
except AttributeError as e:
|
|
34
|
+
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def __dir__():
|
|
38
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
39
|
+
return sorted(lazy_attrs)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__all__ = ["EventSource", "SSEError", "ServerSentEvent", "aconnect_sse", "connect_sse"]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from contextlib import asynccontextmanager, contextmanager
|
|
5
|
+
from typing import Any, AsyncGenerator, AsyncIterator, Iterator, cast
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from ._decoders import SSEDecoder
|
|
9
|
+
from ._exceptions import SSEError
|
|
10
|
+
from ._models import ServerSentEvent
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EventSource:
|
|
14
|
+
def __init__(self, response: httpx.Response) -> None:
|
|
15
|
+
self._response = response
|
|
16
|
+
|
|
17
|
+
def _check_content_type(self) -> None:
|
|
18
|
+
content_type = self._response.headers.get("content-type", "").partition(";")[0]
|
|
19
|
+
if "text/event-stream" not in content_type:
|
|
20
|
+
raise SSEError(
|
|
21
|
+
f"Expected response header Content-Type to contain 'text/event-stream', got {content_type!r}"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def _get_charset(self) -> str:
|
|
25
|
+
"""Extract charset from Content-Type header, fallback to UTF-8."""
|
|
26
|
+
content_type = self._response.headers.get("content-type", "")
|
|
27
|
+
|
|
28
|
+
# Parse charset parameter using regex
|
|
29
|
+
charset_match = re.search(r"charset=([^;\s]+)", content_type, re.IGNORECASE)
|
|
30
|
+
if charset_match:
|
|
31
|
+
charset = charset_match.group(1).strip("\"'")
|
|
32
|
+
# Validate that it's a known encoding
|
|
33
|
+
try:
|
|
34
|
+
# Test if the charset is valid by trying to encode/decode
|
|
35
|
+
"test".encode(charset).decode(charset)
|
|
36
|
+
return charset
|
|
37
|
+
except (LookupError, UnicodeError):
|
|
38
|
+
# If charset is invalid, fall back to UTF-8
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
# Default to UTF-8 if no charset specified or invalid charset
|
|
42
|
+
return "utf-8"
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def response(self) -> httpx.Response:
|
|
46
|
+
return self._response
|
|
47
|
+
|
|
48
|
+
def iter_sse(self) -> Iterator[ServerSentEvent]:
|
|
49
|
+
self._check_content_type()
|
|
50
|
+
decoder = SSEDecoder()
|
|
51
|
+
charset = self._get_charset()
|
|
52
|
+
|
|
53
|
+
buffer = ""
|
|
54
|
+
for chunk in self._response.iter_bytes():
|
|
55
|
+
# Decode chunk using detected charset
|
|
56
|
+
text_chunk = chunk.decode(charset, errors="replace")
|
|
57
|
+
buffer += text_chunk
|
|
58
|
+
|
|
59
|
+
# Process complete lines
|
|
60
|
+
while "\n" in buffer:
|
|
61
|
+
line, buffer = buffer.split("\n", 1)
|
|
62
|
+
line = line.rstrip("\r")
|
|
63
|
+
sse = decoder.decode(line)
|
|
64
|
+
# when we reach a "\n\n" => line = ''
|
|
65
|
+
# => decoder will attempt to return an SSE Event
|
|
66
|
+
if sse is not None:
|
|
67
|
+
yield sse
|
|
68
|
+
|
|
69
|
+
# Process any remaining data in buffer
|
|
70
|
+
if buffer.strip():
|
|
71
|
+
line = buffer.rstrip("\r")
|
|
72
|
+
sse = decoder.decode(line)
|
|
73
|
+
if sse is not None:
|
|
74
|
+
yield sse
|
|
75
|
+
|
|
76
|
+
async def aiter_sse(self) -> AsyncGenerator[ServerSentEvent, None]:
|
|
77
|
+
self._check_content_type()
|
|
78
|
+
decoder = SSEDecoder()
|
|
79
|
+
lines = cast(AsyncGenerator[str, None], self._response.aiter_lines())
|
|
80
|
+
try:
|
|
81
|
+
async for line in lines:
|
|
82
|
+
line = line.rstrip("\n")
|
|
83
|
+
sse = decoder.decode(line)
|
|
84
|
+
if sse is not None:
|
|
85
|
+
yield sse
|
|
86
|
+
finally:
|
|
87
|
+
await lines.aclose()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@contextmanager
|
|
91
|
+
def connect_sse(client: httpx.Client, method: str, url: str, **kwargs: Any) -> Iterator[EventSource]:
|
|
92
|
+
headers = kwargs.pop("headers", {})
|
|
93
|
+
headers["Accept"] = "text/event-stream"
|
|
94
|
+
headers["Cache-Control"] = "no-store"
|
|
95
|
+
|
|
96
|
+
with client.stream(method, url, headers=headers, **kwargs) as response:
|
|
97
|
+
yield EventSource(response)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@asynccontextmanager
|
|
101
|
+
async def aconnect_sse(
|
|
102
|
+
client: httpx.AsyncClient,
|
|
103
|
+
method: str,
|
|
104
|
+
url: str,
|
|
105
|
+
**kwargs: Any,
|
|
106
|
+
) -> AsyncIterator[EventSource]:
|
|
107
|
+
headers = kwargs.pop("headers", {})
|
|
108
|
+
headers["Accept"] = "text/event-stream"
|
|
109
|
+
headers["Cache-Control"] = "no-store"
|
|
110
|
+
|
|
111
|
+
async with client.stream(method, url, headers=headers, **kwargs) as response:
|
|
112
|
+
yield EventSource(response)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
from ._models import ServerSentEvent
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SSEDecoder:
|
|
9
|
+
def __init__(self) -> None:
|
|
10
|
+
self._event = ""
|
|
11
|
+
self._data: List[str] = []
|
|
12
|
+
self._last_event_id = ""
|
|
13
|
+
self._retry: Optional[int] = None
|
|
14
|
+
|
|
15
|
+
def decode(self, line: str) -> Optional[ServerSentEvent]:
|
|
16
|
+
# See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501
|
|
17
|
+
|
|
18
|
+
if not line:
|
|
19
|
+
if not self._event and not self._data and not self._last_event_id and self._retry is None:
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
sse = ServerSentEvent(
|
|
23
|
+
event=self._event,
|
|
24
|
+
data="\n".join(self._data),
|
|
25
|
+
id=self._last_event_id,
|
|
26
|
+
retry=self._retry,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# NOTE: as per the SSE spec, do not reset last_event_id.
|
|
30
|
+
self._event = ""
|
|
31
|
+
self._data = []
|
|
32
|
+
self._retry = None
|
|
33
|
+
|
|
34
|
+
return sse
|
|
35
|
+
|
|
36
|
+
if line.startswith(":"):
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
fieldname, _, value = line.partition(":")
|
|
40
|
+
|
|
41
|
+
if value.startswith(" "):
|
|
42
|
+
value = value[1:]
|
|
43
|
+
|
|
44
|
+
if fieldname == "event":
|
|
45
|
+
self._event = value
|
|
46
|
+
elif fieldname == "data":
|
|
47
|
+
self._data.append(value)
|
|
48
|
+
elif fieldname == "id":
|
|
49
|
+
if "\0" in value:
|
|
50
|
+
pass
|
|
51
|
+
else:
|
|
52
|
+
self._last_event_id = value
|
|
53
|
+
elif fieldname == "retry":
|
|
54
|
+
try:
|
|
55
|
+
self._retry = int(value)
|
|
56
|
+
except (TypeError, ValueError):
|
|
57
|
+
pass
|
|
58
|
+
else:
|
|
59
|
+
pass # Field is ignored.
|
|
60
|
+
|
|
61
|
+
return None
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class ServerSentEvent:
|
|
10
|
+
event: str = "message"
|
|
11
|
+
data: str = ""
|
|
12
|
+
id: str = ""
|
|
13
|
+
retry: Optional[int] = None
|
|
14
|
+
|
|
15
|
+
def json(self) -> Any:
|
|
16
|
+
"""Parse the data field as JSON."""
|
|
17
|
+
return json.loads(self.data)
|
|
@@ -61,7 +61,7 @@ class UniversalBaseModel(pydantic.BaseModel):
|
|
|
61
61
|
|
|
62
62
|
@pydantic.model_serializer(mode="plain", when_used="json") # type: ignore[attr-defined]
|
|
63
63
|
def serialize_model(self) -> Any: # type: ignore[name-defined]
|
|
64
|
-
serialized = self.
|
|
64
|
+
serialized = self.dict() # type: ignore[attr-defined]
|
|
65
65
|
data = {k: serialize_datetime(v) if isinstance(v, dt.datetime) else v for k, v in serialized.items()}
|
|
66
66
|
return data
|
|
67
67
|
|
|
@@ -147,7 +147,10 @@ class UniversalBaseModel(pydantic.BaseModel):
|
|
|
147
147
|
|
|
148
148
|
dict_dump = super().dict(**kwargs_with_defaults_exclude_unset_include_fields)
|
|
149
149
|
|
|
150
|
-
return
|
|
150
|
+
return cast(
|
|
151
|
+
Dict[str, Any],
|
|
152
|
+
convert_and_respect_annotation_metadata(object_=dict_dump, annotation=self.__class__, direction="write"),
|
|
153
|
+
)
|
|
151
154
|
|
|
152
155
|
|
|
153
156
|
def _union_list_of_pydantic_dicts(source: List[Any], destination: List[Any]) -> List[Any]:
|