lambdadb 0.1.2__py3-none-any.whl
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.
Potentially problematic release.
This version of lambdadb might be problematic. Click here for more details.
- lambdadb/__init__.py +17 -0
- lambdadb/_hooks/__init__.py +5 -0
- lambdadb/_hooks/registration.py +13 -0
- lambdadb/_hooks/sdkhooks.py +76 -0
- lambdadb/_hooks/types.py +106 -0
- lambdadb/_version.py +15 -0
- lambdadb/basesdk.py +358 -0
- lambdadb/collections.py +1630 -0
- lambdadb/docs.py +1328 -0
- lambdadb/errors/__init__.py +74 -0
- lambdadb/errors/apierror.py +22 -0
- lambdadb/errors/badrequest_error.py +20 -0
- lambdadb/errors/internalservererror.py +20 -0
- lambdadb/errors/resourcealreadyexists_error.py +20 -0
- lambdadb/errors/resourcenotfound_error.py +20 -0
- lambdadb/errors/toomanyrequests_error.py +20 -0
- lambdadb/errors/unauthenticated_error.py +20 -0
- lambdadb/httpclient.py +126 -0
- lambdadb/models/__init__.py +420 -0
- lambdadb/models/bulkupsertdocsop.py +59 -0
- lambdadb/models/collectionresponse.py +64 -0
- lambdadb/models/createcollectionop.py +64 -0
- lambdadb/models/createprojectop.py +39 -0
- lambdadb/models/deletecollectionop.py +43 -0
- lambdadb/models/deletedocsop.py +88 -0
- lambdadb/models/deleteprojectop.py +52 -0
- lambdadb/models/fetchdocsop.py +102 -0
- lambdadb/models/getbulkupsertdocsop.py +82 -0
- lambdadb/models/getcollectionop.py +30 -0
- lambdadb/models/getprojectop.py +39 -0
- lambdadb/models/indexconfigs_union.py +95 -0
- lambdadb/models/listcollectionsop.py +35 -0
- lambdadb/models/listprojectsop.py +38 -0
- lambdadb/models/projectresponse.py +38 -0
- lambdadb/models/querycollectionop.py +152 -0
- lambdadb/models/security.py +25 -0
- lambdadb/models/status.py +12 -0
- lambdadb/models/updatecollectionop.py +48 -0
- lambdadb/models/updateprojectop.py +58 -0
- lambdadb/models/upsertdocsop.py +67 -0
- lambdadb/projects.py +1228 -0
- lambdadb/py.typed +1 -0
- lambdadb/sdk.py +170 -0
- lambdadb/sdkconfiguration.py +56 -0
- lambdadb/types/__init__.py +21 -0
- lambdadb/types/basemodel.py +39 -0
- lambdadb/utils/__init__.py +187 -0
- lambdadb/utils/annotations.py +55 -0
- lambdadb/utils/datetimes.py +23 -0
- lambdadb/utils/enums.py +74 -0
- lambdadb/utils/eventstreaming.py +238 -0
- lambdadb/utils/forms.py +202 -0
- lambdadb/utils/headers.py +136 -0
- lambdadb/utils/logger.py +27 -0
- lambdadb/utils/metadata.py +118 -0
- lambdadb/utils/queryparams.py +205 -0
- lambdadb/utils/requestbodies.py +66 -0
- lambdadb/utils/retries.py +217 -0
- lambdadb/utils/security.py +192 -0
- lambdadb/utils/serializers.py +248 -0
- lambdadb/utils/url.py +155 -0
- lambdadb/utils/values.py +137 -0
- lambdadb-0.1.2.dist-info/LICENSE +201 -0
- lambdadb-0.1.2.dist-info/METADATA +514 -0
- lambdadb-0.1.2.dist-info/RECORD +66 -0
- lambdadb-0.1.2.dist-info/WHEEL +4 -0
lambdadb/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from ._version import (
|
|
4
|
+
__title__,
|
|
5
|
+
__version__,
|
|
6
|
+
__openapi_doc_version__,
|
|
7
|
+
__gen_version__,
|
|
8
|
+
__user_agent__,
|
|
9
|
+
)
|
|
10
|
+
from .sdk import *
|
|
11
|
+
from .sdkconfiguration import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
VERSION: str = __version__
|
|
15
|
+
OPENAPI_DOC_VERSION = __openapi_doc_version__
|
|
16
|
+
SPEAKEASY_GENERATOR_VERSION = __gen_version__
|
|
17
|
+
USER_AGENT = __user_agent__
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .types import Hooks
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# This file is only ever generated once on the first generation and then is free to be modified.
|
|
5
|
+
# Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
|
|
6
|
+
# in this file or in separate files in the hooks folder.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def init_hooks(hooks: Hooks):
|
|
10
|
+
# pylint: disable=unused-argument
|
|
11
|
+
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
|
|
12
|
+
with an instance of a hook that implements that specific Hook interface
|
|
13
|
+
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from .types import (
|
|
5
|
+
SDKInitHook,
|
|
6
|
+
BeforeRequestContext,
|
|
7
|
+
BeforeRequestHook,
|
|
8
|
+
AfterSuccessContext,
|
|
9
|
+
AfterSuccessHook,
|
|
10
|
+
AfterErrorContext,
|
|
11
|
+
AfterErrorHook,
|
|
12
|
+
Hooks,
|
|
13
|
+
)
|
|
14
|
+
from .registration import init_hooks
|
|
15
|
+
from typing import List, Optional, Tuple
|
|
16
|
+
from lambdadb.httpclient import HttpClient
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SDKHooks(Hooks):
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
self.sdk_init_hooks: List[SDKInitHook] = []
|
|
22
|
+
self.before_request_hooks: List[BeforeRequestHook] = []
|
|
23
|
+
self.after_success_hooks: List[AfterSuccessHook] = []
|
|
24
|
+
self.after_error_hooks: List[AfterErrorHook] = []
|
|
25
|
+
init_hooks(self)
|
|
26
|
+
|
|
27
|
+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
|
|
28
|
+
self.sdk_init_hooks.append(hook)
|
|
29
|
+
|
|
30
|
+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
|
|
31
|
+
self.before_request_hooks.append(hook)
|
|
32
|
+
|
|
33
|
+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
|
|
34
|
+
self.after_success_hooks.append(hook)
|
|
35
|
+
|
|
36
|
+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
|
|
37
|
+
self.after_error_hooks.append(hook)
|
|
38
|
+
|
|
39
|
+
def sdk_init(self, base_url: str, client: HttpClient) -> Tuple[str, HttpClient]:
|
|
40
|
+
for hook in self.sdk_init_hooks:
|
|
41
|
+
base_url, client = hook.sdk_init(base_url, client)
|
|
42
|
+
return base_url, client
|
|
43
|
+
|
|
44
|
+
def before_request(
|
|
45
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
46
|
+
) -> httpx.Request:
|
|
47
|
+
for hook in self.before_request_hooks:
|
|
48
|
+
out = hook.before_request(hook_ctx, request)
|
|
49
|
+
if isinstance(out, Exception):
|
|
50
|
+
raise out
|
|
51
|
+
request = out
|
|
52
|
+
|
|
53
|
+
return request
|
|
54
|
+
|
|
55
|
+
def after_success(
|
|
56
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
57
|
+
) -> httpx.Response:
|
|
58
|
+
for hook in self.after_success_hooks:
|
|
59
|
+
out = hook.after_success(hook_ctx, response)
|
|
60
|
+
if isinstance(out, Exception):
|
|
61
|
+
raise out
|
|
62
|
+
response = out
|
|
63
|
+
return response
|
|
64
|
+
|
|
65
|
+
def after_error(
|
|
66
|
+
self,
|
|
67
|
+
hook_ctx: AfterErrorContext,
|
|
68
|
+
response: Optional[httpx.Response],
|
|
69
|
+
error: Optional[Exception],
|
|
70
|
+
) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
|
71
|
+
for hook in self.after_error_hooks:
|
|
72
|
+
result = hook.after_error(hook_ctx, response, error)
|
|
73
|
+
if isinstance(result, Exception):
|
|
74
|
+
raise result
|
|
75
|
+
response, error = result
|
|
76
|
+
return response, error
|
lambdadb/_hooks/types.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
import httpx
|
|
5
|
+
from lambdadb.httpclient import HttpClient
|
|
6
|
+
from typing import Any, Callable, List, Optional, Tuple, Union
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HookContext:
|
|
10
|
+
base_url: str
|
|
11
|
+
operation_id: str
|
|
12
|
+
oauth2_scopes: Optional[List[str]] = None
|
|
13
|
+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
base_url: str,
|
|
18
|
+
operation_id: str,
|
|
19
|
+
oauth2_scopes: Optional[List[str]],
|
|
20
|
+
security_source: Optional[Union[Any, Callable[[], Any]]],
|
|
21
|
+
):
|
|
22
|
+
self.base_url = base_url
|
|
23
|
+
self.operation_id = operation_id
|
|
24
|
+
self.oauth2_scopes = oauth2_scopes
|
|
25
|
+
self.security_source = security_source
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BeforeRequestContext(HookContext):
|
|
29
|
+
def __init__(self, hook_ctx: HookContext):
|
|
30
|
+
super().__init__(
|
|
31
|
+
hook_ctx.base_url,
|
|
32
|
+
hook_ctx.operation_id,
|
|
33
|
+
hook_ctx.oauth2_scopes,
|
|
34
|
+
hook_ctx.security_source,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class AfterSuccessContext(HookContext):
|
|
39
|
+
def __init__(self, hook_ctx: HookContext):
|
|
40
|
+
super().__init__(
|
|
41
|
+
hook_ctx.base_url,
|
|
42
|
+
hook_ctx.operation_id,
|
|
43
|
+
hook_ctx.oauth2_scopes,
|
|
44
|
+
hook_ctx.security_source,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AfterErrorContext(HookContext):
|
|
49
|
+
def __init__(self, hook_ctx: HookContext):
|
|
50
|
+
super().__init__(
|
|
51
|
+
hook_ctx.base_url,
|
|
52
|
+
hook_ctx.operation_id,
|
|
53
|
+
hook_ctx.oauth2_scopes,
|
|
54
|
+
hook_ctx.security_source,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class SDKInitHook(ABC):
|
|
59
|
+
@abstractmethod
|
|
60
|
+
def sdk_init(self, base_url: str, client: HttpClient) -> Tuple[str, HttpClient]:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class BeforeRequestHook(ABC):
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def before_request(
|
|
67
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
68
|
+
) -> Union[httpx.Request, Exception]:
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class AfterSuccessHook(ABC):
|
|
73
|
+
@abstractmethod
|
|
74
|
+
def after_success(
|
|
75
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
76
|
+
) -> Union[httpx.Response, Exception]:
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class AfterErrorHook(ABC):
|
|
81
|
+
@abstractmethod
|
|
82
|
+
def after_error(
|
|
83
|
+
self,
|
|
84
|
+
hook_ctx: AfterErrorContext,
|
|
85
|
+
response: Optional[httpx.Response],
|
|
86
|
+
error: Optional[Exception],
|
|
87
|
+
) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class Hooks(ABC):
|
|
92
|
+
@abstractmethod
|
|
93
|
+
def register_sdk_init_hook(self, hook: SDKInitHook):
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
@abstractmethod
|
|
97
|
+
def register_before_request_hook(self, hook: BeforeRequestHook):
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
@abstractmethod
|
|
101
|
+
def register_after_success_hook(self, hook: AfterSuccessHook):
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def register_after_error_hook(self, hook: AfterErrorHook):
|
|
106
|
+
pass
|
lambdadb/_version.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
|
|
5
|
+
__title__: str = "lambdadb"
|
|
6
|
+
__version__: str = "0.1.2"
|
|
7
|
+
__openapi_doc_version__: str = "1.0.0"
|
|
8
|
+
__gen_version__: str = "2.610.0"
|
|
9
|
+
__user_agent__: str = "speakeasy-sdk/python 0.1.2 2.610.0 1.0.0 lambdadb"
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
if __package__ is not None:
|
|
13
|
+
__version__ = importlib.metadata.version(__package__)
|
|
14
|
+
except importlib.metadata.PackageNotFoundError:
|
|
15
|
+
pass
|
lambdadb/basesdk.py
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .sdkconfiguration import SDKConfiguration
|
|
4
|
+
import httpx
|
|
5
|
+
from lambdadb import errors, models, utils
|
|
6
|
+
from lambdadb._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext
|
|
7
|
+
from lambdadb.utils import RetryConfig, SerializedRequestBody, get_body_content
|
|
8
|
+
from typing import Callable, List, Mapping, Optional, Tuple
|
|
9
|
+
from urllib.parse import parse_qs, urlparse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BaseSDK:
|
|
13
|
+
sdk_configuration: SDKConfiguration
|
|
14
|
+
|
|
15
|
+
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
|
16
|
+
self.sdk_configuration = sdk_config
|
|
17
|
+
|
|
18
|
+
def _get_url(self, base_url, url_variables):
|
|
19
|
+
sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
|
|
20
|
+
|
|
21
|
+
if base_url is None:
|
|
22
|
+
base_url = sdk_url
|
|
23
|
+
|
|
24
|
+
if url_variables is None:
|
|
25
|
+
url_variables = sdk_variables
|
|
26
|
+
|
|
27
|
+
return utils.template_url(base_url, url_variables)
|
|
28
|
+
|
|
29
|
+
def _build_request_async(
|
|
30
|
+
self,
|
|
31
|
+
method,
|
|
32
|
+
path,
|
|
33
|
+
base_url,
|
|
34
|
+
url_variables,
|
|
35
|
+
request,
|
|
36
|
+
request_body_required,
|
|
37
|
+
request_has_path_params,
|
|
38
|
+
request_has_query_params,
|
|
39
|
+
user_agent_header,
|
|
40
|
+
accept_header_value,
|
|
41
|
+
_globals=None,
|
|
42
|
+
security=None,
|
|
43
|
+
timeout_ms: Optional[int] = None,
|
|
44
|
+
get_serialized_body: Optional[
|
|
45
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
46
|
+
] = None,
|
|
47
|
+
url_override: Optional[str] = None,
|
|
48
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
49
|
+
) -> httpx.Request:
|
|
50
|
+
client = self.sdk_configuration.async_client
|
|
51
|
+
return self._build_request_with_client(
|
|
52
|
+
client,
|
|
53
|
+
method,
|
|
54
|
+
path,
|
|
55
|
+
base_url,
|
|
56
|
+
url_variables,
|
|
57
|
+
request,
|
|
58
|
+
request_body_required,
|
|
59
|
+
request_has_path_params,
|
|
60
|
+
request_has_query_params,
|
|
61
|
+
user_agent_header,
|
|
62
|
+
accept_header_value,
|
|
63
|
+
_globals,
|
|
64
|
+
security,
|
|
65
|
+
timeout_ms,
|
|
66
|
+
get_serialized_body,
|
|
67
|
+
url_override,
|
|
68
|
+
http_headers,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def _build_request(
|
|
72
|
+
self,
|
|
73
|
+
method,
|
|
74
|
+
path,
|
|
75
|
+
base_url,
|
|
76
|
+
url_variables,
|
|
77
|
+
request,
|
|
78
|
+
request_body_required,
|
|
79
|
+
request_has_path_params,
|
|
80
|
+
request_has_query_params,
|
|
81
|
+
user_agent_header,
|
|
82
|
+
accept_header_value,
|
|
83
|
+
_globals=None,
|
|
84
|
+
security=None,
|
|
85
|
+
timeout_ms: Optional[int] = None,
|
|
86
|
+
get_serialized_body: Optional[
|
|
87
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
88
|
+
] = None,
|
|
89
|
+
url_override: Optional[str] = None,
|
|
90
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
91
|
+
) -> httpx.Request:
|
|
92
|
+
client = self.sdk_configuration.client
|
|
93
|
+
return self._build_request_with_client(
|
|
94
|
+
client,
|
|
95
|
+
method,
|
|
96
|
+
path,
|
|
97
|
+
base_url,
|
|
98
|
+
url_variables,
|
|
99
|
+
request,
|
|
100
|
+
request_body_required,
|
|
101
|
+
request_has_path_params,
|
|
102
|
+
request_has_query_params,
|
|
103
|
+
user_agent_header,
|
|
104
|
+
accept_header_value,
|
|
105
|
+
_globals,
|
|
106
|
+
security,
|
|
107
|
+
timeout_ms,
|
|
108
|
+
get_serialized_body,
|
|
109
|
+
url_override,
|
|
110
|
+
http_headers,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def _build_request_with_client(
|
|
114
|
+
self,
|
|
115
|
+
client,
|
|
116
|
+
method,
|
|
117
|
+
path,
|
|
118
|
+
base_url,
|
|
119
|
+
url_variables,
|
|
120
|
+
request,
|
|
121
|
+
request_body_required,
|
|
122
|
+
request_has_path_params,
|
|
123
|
+
request_has_query_params,
|
|
124
|
+
user_agent_header,
|
|
125
|
+
accept_header_value,
|
|
126
|
+
_globals=None,
|
|
127
|
+
security=None,
|
|
128
|
+
timeout_ms: Optional[int] = None,
|
|
129
|
+
get_serialized_body: Optional[
|
|
130
|
+
Callable[[], Optional[SerializedRequestBody]]
|
|
131
|
+
] = None,
|
|
132
|
+
url_override: Optional[str] = None,
|
|
133
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
134
|
+
) -> httpx.Request:
|
|
135
|
+
query_params = {}
|
|
136
|
+
|
|
137
|
+
url = url_override
|
|
138
|
+
if url is None:
|
|
139
|
+
url = utils.generate_url(
|
|
140
|
+
self._get_url(base_url, url_variables),
|
|
141
|
+
path,
|
|
142
|
+
request if request_has_path_params else None,
|
|
143
|
+
_globals if request_has_path_params else None,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
query_params = utils.get_query_params(
|
|
147
|
+
request if request_has_query_params else None,
|
|
148
|
+
_globals if request_has_query_params else None,
|
|
149
|
+
)
|
|
150
|
+
else:
|
|
151
|
+
# Pick up the query parameter from the override so they can be
|
|
152
|
+
# preserved when building the request later on (necessary as of
|
|
153
|
+
# httpx 0.28).
|
|
154
|
+
parsed_override = urlparse(str(url_override))
|
|
155
|
+
query_params = parse_qs(parsed_override.query, keep_blank_values=True)
|
|
156
|
+
|
|
157
|
+
headers = utils.get_headers(request, _globals)
|
|
158
|
+
headers["Accept"] = accept_header_value
|
|
159
|
+
headers[user_agent_header] = self.sdk_configuration.user_agent
|
|
160
|
+
|
|
161
|
+
if security is not None:
|
|
162
|
+
if callable(security):
|
|
163
|
+
security = security()
|
|
164
|
+
security = utils.get_security_from_env(security, models.Security)
|
|
165
|
+
if security is not None:
|
|
166
|
+
security_headers, security_query_params = utils.get_security(security)
|
|
167
|
+
headers = {**headers, **security_headers}
|
|
168
|
+
query_params = {**query_params, **security_query_params}
|
|
169
|
+
|
|
170
|
+
serialized_request_body = SerializedRequestBody()
|
|
171
|
+
if get_serialized_body is not None:
|
|
172
|
+
rb = get_serialized_body()
|
|
173
|
+
if request_body_required and rb is None:
|
|
174
|
+
raise ValueError("request body is required")
|
|
175
|
+
|
|
176
|
+
if rb is not None:
|
|
177
|
+
serialized_request_body = rb
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
serialized_request_body.media_type is not None
|
|
181
|
+
and serialized_request_body.media_type
|
|
182
|
+
not in (
|
|
183
|
+
"multipart/form-data",
|
|
184
|
+
"multipart/mixed",
|
|
185
|
+
)
|
|
186
|
+
):
|
|
187
|
+
headers["content-type"] = serialized_request_body.media_type
|
|
188
|
+
|
|
189
|
+
if http_headers is not None:
|
|
190
|
+
for header, value in http_headers.items():
|
|
191
|
+
headers[header] = value
|
|
192
|
+
|
|
193
|
+
timeout = timeout_ms / 1000 if timeout_ms is not None else None
|
|
194
|
+
|
|
195
|
+
return client.build_request(
|
|
196
|
+
method,
|
|
197
|
+
url,
|
|
198
|
+
params=query_params,
|
|
199
|
+
content=serialized_request_body.content,
|
|
200
|
+
data=serialized_request_body.data,
|
|
201
|
+
files=serialized_request_body.files,
|
|
202
|
+
headers=headers,
|
|
203
|
+
timeout=timeout,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
def do_request(
|
|
207
|
+
self,
|
|
208
|
+
hook_ctx,
|
|
209
|
+
request,
|
|
210
|
+
error_status_codes,
|
|
211
|
+
stream=False,
|
|
212
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
|
213
|
+
) -> httpx.Response:
|
|
214
|
+
client = self.sdk_configuration.client
|
|
215
|
+
logger = self.sdk_configuration.debug_logger
|
|
216
|
+
|
|
217
|
+
def do():
|
|
218
|
+
http_res = None
|
|
219
|
+
try:
|
|
220
|
+
req = self.sdk_configuration.get_hooks().before_request(
|
|
221
|
+
BeforeRequestContext(hook_ctx), request
|
|
222
|
+
)
|
|
223
|
+
logger.debug(
|
|
224
|
+
"Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
225
|
+
req.method,
|
|
226
|
+
req.url,
|
|
227
|
+
req.headers,
|
|
228
|
+
get_body_content(req),
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
if client is None:
|
|
232
|
+
raise ValueError("client is required")
|
|
233
|
+
|
|
234
|
+
http_res = client.send(req, stream=stream)
|
|
235
|
+
except Exception as e:
|
|
236
|
+
_, e = self.sdk_configuration.get_hooks().after_error(
|
|
237
|
+
AfterErrorContext(hook_ctx), None, e
|
|
238
|
+
)
|
|
239
|
+
if e is not None:
|
|
240
|
+
logger.debug("Request Exception", exc_info=True)
|
|
241
|
+
raise e
|
|
242
|
+
|
|
243
|
+
if http_res is None:
|
|
244
|
+
logger.debug("Raising no response SDK error")
|
|
245
|
+
raise errors.APIError("No response received")
|
|
246
|
+
|
|
247
|
+
logger.debug(
|
|
248
|
+
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
249
|
+
http_res.status_code,
|
|
250
|
+
http_res.url,
|
|
251
|
+
http_res.headers,
|
|
252
|
+
"<streaming response>" if stream else http_res.text,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
if utils.match_status_codes(error_status_codes, http_res.status_code):
|
|
256
|
+
result, err = self.sdk_configuration.get_hooks().after_error(
|
|
257
|
+
AfterErrorContext(hook_ctx), http_res, None
|
|
258
|
+
)
|
|
259
|
+
if err is not None:
|
|
260
|
+
logger.debug("Request Exception", exc_info=True)
|
|
261
|
+
raise err
|
|
262
|
+
if result is not None:
|
|
263
|
+
http_res = result
|
|
264
|
+
else:
|
|
265
|
+
logger.debug("Raising unexpected SDK error")
|
|
266
|
+
raise errors.APIError("Unexpected error occurred")
|
|
267
|
+
|
|
268
|
+
return http_res
|
|
269
|
+
|
|
270
|
+
if retry_config is not None:
|
|
271
|
+
http_res = utils.retry(do, utils.Retries(retry_config[0], retry_config[1]))
|
|
272
|
+
else:
|
|
273
|
+
http_res = do()
|
|
274
|
+
|
|
275
|
+
if not utils.match_status_codes(error_status_codes, http_res.status_code):
|
|
276
|
+
http_res = self.sdk_configuration.get_hooks().after_success(
|
|
277
|
+
AfterSuccessContext(hook_ctx), http_res
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
return http_res
|
|
281
|
+
|
|
282
|
+
async def do_request_async(
|
|
283
|
+
self,
|
|
284
|
+
hook_ctx,
|
|
285
|
+
request,
|
|
286
|
+
error_status_codes,
|
|
287
|
+
stream=False,
|
|
288
|
+
retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
|
|
289
|
+
) -> httpx.Response:
|
|
290
|
+
client = self.sdk_configuration.async_client
|
|
291
|
+
logger = self.sdk_configuration.debug_logger
|
|
292
|
+
|
|
293
|
+
async def do():
|
|
294
|
+
http_res = None
|
|
295
|
+
try:
|
|
296
|
+
req = self.sdk_configuration.get_hooks().before_request(
|
|
297
|
+
BeforeRequestContext(hook_ctx), request
|
|
298
|
+
)
|
|
299
|
+
logger.debug(
|
|
300
|
+
"Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
301
|
+
req.method,
|
|
302
|
+
req.url,
|
|
303
|
+
req.headers,
|
|
304
|
+
get_body_content(req),
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
if client is None:
|
|
308
|
+
raise ValueError("client is required")
|
|
309
|
+
|
|
310
|
+
http_res = await client.send(req, stream=stream)
|
|
311
|
+
except Exception as e:
|
|
312
|
+
_, e = self.sdk_configuration.get_hooks().after_error(
|
|
313
|
+
AfterErrorContext(hook_ctx), None, e
|
|
314
|
+
)
|
|
315
|
+
if e is not None:
|
|
316
|
+
logger.debug("Request Exception", exc_info=True)
|
|
317
|
+
raise e
|
|
318
|
+
|
|
319
|
+
if http_res is None:
|
|
320
|
+
logger.debug("Raising no response SDK error")
|
|
321
|
+
raise errors.APIError("No response received")
|
|
322
|
+
|
|
323
|
+
logger.debug(
|
|
324
|
+
"Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
|
|
325
|
+
http_res.status_code,
|
|
326
|
+
http_res.url,
|
|
327
|
+
http_res.headers,
|
|
328
|
+
"<streaming response>" if stream else http_res.text,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
if utils.match_status_codes(error_status_codes, http_res.status_code):
|
|
332
|
+
result, err = self.sdk_configuration.get_hooks().after_error(
|
|
333
|
+
AfterErrorContext(hook_ctx), http_res, None
|
|
334
|
+
)
|
|
335
|
+
if err is not None:
|
|
336
|
+
logger.debug("Request Exception", exc_info=True)
|
|
337
|
+
raise err
|
|
338
|
+
if result is not None:
|
|
339
|
+
http_res = result
|
|
340
|
+
else:
|
|
341
|
+
logger.debug("Raising unexpected SDK error")
|
|
342
|
+
raise errors.APIError("Unexpected error occurred")
|
|
343
|
+
|
|
344
|
+
return http_res
|
|
345
|
+
|
|
346
|
+
if retry_config is not None:
|
|
347
|
+
http_res = await utils.retry_async(
|
|
348
|
+
do, utils.Retries(retry_config[0], retry_config[1])
|
|
349
|
+
)
|
|
350
|
+
else:
|
|
351
|
+
http_res = await do()
|
|
352
|
+
|
|
353
|
+
if not utils.match_status_codes(error_status_codes, http_res.status_code):
|
|
354
|
+
http_res = self.sdk_configuration.get_hooks().after_success(
|
|
355
|
+
AfterSuccessContext(hook_ctx), http_res
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
return http_res
|