motor-python-sdk 0.0.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.
- motor_python_sdk-0.0.2.dist-info/METADATA +230 -0
- motor_python_sdk-0.0.2.dist-info/RECORD +60 -0
- motor_python_sdk-0.0.2.dist-info/WHEEL +4 -0
- yasminaai/__init__.py +113 -0
- yasminaai/_default_clients.py +32 -0
- yasminaai/client.py +255 -0
- yasminaai/core/__init__.py +127 -0
- yasminaai/core/api_error.py +23 -0
- yasminaai/core/client_wrapper.py +119 -0
- yasminaai/core/datetime_utils.py +70 -0
- yasminaai/core/file.py +67 -0
- yasminaai/core/force_multipart.py +18 -0
- yasminaai/core/http_client.py +839 -0
- yasminaai/core/http_response.py +59 -0
- yasminaai/core/http_sse/__init__.py +42 -0
- yasminaai/core/http_sse/_api.py +170 -0
- yasminaai/core/http_sse/_decoders.py +61 -0
- yasminaai/core/http_sse/_exceptions.py +7 -0
- yasminaai/core/http_sse/_models.py +17 -0
- yasminaai/core/jsonable_encoder.py +120 -0
- yasminaai/core/logging.py +107 -0
- yasminaai/core/parse_error.py +36 -0
- yasminaai/core/pydantic_utilities.py +508 -0
- yasminaai/core/query_encoder.py +58 -0
- yasminaai/core/remove_none_from_dict.py +11 -0
- yasminaai/core/request_options.py +35 -0
- yasminaai/core/serialization.py +347 -0
- yasminaai/environment.py +7 -0
- yasminaai/errors/__init__.py +42 -0
- yasminaai/errors/bad_request_error.py +10 -0
- yasminaai/errors/not_found_error.py +10 -0
- yasminaai/errors/unauthorized_error.py +10 -0
- yasminaai/errors/unprocessable_entity_error.py +10 -0
- yasminaai/ot_ps/__init__.py +4 -0
- yasminaai/ot_ps/client.py +278 -0
- yasminaai/ot_ps/raw_client.py +355 -0
- yasminaai/policies/__init__.py +4 -0
- yasminaai/policies/client.py +393 -0
- yasminaai/policies/raw_client.py +493 -0
- yasminaai/py.typed +0 -0
- yasminaai/quotes/__init__.py +49 -0
- yasminaai/quotes/client.py +438 -0
- yasminaai/quotes/raw_client.py +548 -0
- yasminaai/quotes/types/__init__.py +47 -0
- yasminaai/quotes/types/delete_quote_requests_id_response.py +19 -0
- yasminaai/quotes/types/get_quote_requests_response.py +37 -0
- yasminaai/quotes/types/get_quote_requests_response_links_item.py +21 -0
- yasminaai/quotes/types/post_quote_requests_request_drivers_item.py +33 -0
- yasminaai/types/__init__.py +65 -0
- yasminaai/types/bad_request_error_body.py +20 -0
- yasminaai/types/benefit.py +24 -0
- yasminaai/types/company_quote.py +23 -0
- yasminaai/types/error.py +20 -0
- yasminaai/types/policy.py +33 -0
- yasminaai/types/quote_price.py +24 -0
- yasminaai/types/quote_response.py +90 -0
- yasminaai/types/quote_response_drivers_item.py +33 -0
- yasminaai/types/quote_response_quotes_item.py +30 -0
- yasminaai/types/unauthorized_error_body.py +20 -0
- yasminaai/version.py +3 -0
yasminaai/client.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
9
|
+
from .core.logging import LogConfig, Logger
|
|
10
|
+
from .environment import YasminaaiApiEnvironment
|
|
11
|
+
|
|
12
|
+
if typing.TYPE_CHECKING:
|
|
13
|
+
from .ot_ps.client import AsyncOtPsClient, OtPsClient
|
|
14
|
+
from .policies.client import AsyncPoliciesClient, PoliciesClient
|
|
15
|
+
from .quotes.client import AsyncQuotesClient, QuotesClient
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class YasminaaiApi:
|
|
19
|
+
"""
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
base_url : typing.Optional[str]
|
|
25
|
+
The base url to use for requests from the client.
|
|
26
|
+
|
|
27
|
+
environment : YasminaaiApiEnvironment
|
|
28
|
+
The environment to use for requests from the client. from .environment import YasminaaiApiEnvironment
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Defaults to YasminaaiApiEnvironment.DEFAULT
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
token : typing.Union[str, typing.Callable[[], str]]
|
|
37
|
+
headers : typing.Optional[typing.Dict[str, str]]
|
|
38
|
+
Additional headers to send with every request.
|
|
39
|
+
|
|
40
|
+
timeout : typing.Optional[float]
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
max_retries : typing.Optional[int]
|
|
44
|
+
The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
|
|
45
|
+
|
|
46
|
+
follow_redirects : typing.Optional[bool]
|
|
47
|
+
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
48
|
+
|
|
49
|
+
httpx_client : typing.Optional[httpx.Client]
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
logging : typing.Optional[typing.Union[LogConfig, Logger]]
|
|
53
|
+
Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.
|
|
54
|
+
|
|
55
|
+
Examples
|
|
56
|
+
--------
|
|
57
|
+
from yasminaai import YasminaaiApi
|
|
58
|
+
|
|
59
|
+
client = YasminaaiApi(
|
|
60
|
+
token="YOUR_TOKEN",
|
|
61
|
+
)
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
*,
|
|
67
|
+
base_url: typing.Optional[str] = None,
|
|
68
|
+
environment: YasminaaiApiEnvironment = YasminaaiApiEnvironment.DEFAULT,
|
|
69
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
70
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
71
|
+
timeout: typing.Optional[float] = None,
|
|
72
|
+
max_retries: typing.Optional[int] = None,
|
|
73
|
+
follow_redirects: typing.Optional[bool] = True,
|
|
74
|
+
httpx_client: typing.Optional[httpx.Client] = None,
|
|
75
|
+
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
|
|
76
|
+
):
|
|
77
|
+
_defaulted_timeout = (
|
|
78
|
+
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
|
|
79
|
+
)
|
|
80
|
+
_defaulted_max_retries = max_retries if max_retries is not None else 2
|
|
81
|
+
self._client_wrapper = SyncClientWrapper(
|
|
82
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
83
|
+
token=token,
|
|
84
|
+
headers=headers,
|
|
85
|
+
httpx_client=httpx_client
|
|
86
|
+
if httpx_client is not None
|
|
87
|
+
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
|
|
88
|
+
if follow_redirects is not None
|
|
89
|
+
else httpx.Client(timeout=_defaulted_timeout),
|
|
90
|
+
timeout=_defaulted_timeout,
|
|
91
|
+
max_retries=_defaulted_max_retries,
|
|
92
|
+
logging=logging,
|
|
93
|
+
)
|
|
94
|
+
self._quotes: typing.Optional[QuotesClient] = None
|
|
95
|
+
self._policies: typing.Optional[PoliciesClient] = None
|
|
96
|
+
self._ot_ps: typing.Optional[OtPsClient] = None
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def quotes(self):
|
|
100
|
+
if self._quotes is None:
|
|
101
|
+
from .quotes.client import QuotesClient # noqa: E402
|
|
102
|
+
|
|
103
|
+
self._quotes = QuotesClient(client_wrapper=self._client_wrapper)
|
|
104
|
+
return self._quotes
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def policies(self):
|
|
108
|
+
if self._policies is None:
|
|
109
|
+
from .policies.client import PoliciesClient # noqa: E402
|
|
110
|
+
|
|
111
|
+
self._policies = PoliciesClient(client_wrapper=self._client_wrapper)
|
|
112
|
+
return self._policies
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def ot_ps(self):
|
|
116
|
+
if self._ot_ps is None:
|
|
117
|
+
from .ot_ps.client import OtPsClient # noqa: E402
|
|
118
|
+
|
|
119
|
+
self._ot_ps = OtPsClient(client_wrapper=self._client_wrapper)
|
|
120
|
+
return self._ot_ps
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _make_default_async_client(
|
|
124
|
+
timeout: typing.Optional[float],
|
|
125
|
+
follow_redirects: typing.Optional[bool],
|
|
126
|
+
) -> httpx.AsyncClient:
|
|
127
|
+
try:
|
|
128
|
+
import httpx_aiohttp # type: ignore[import-not-found]
|
|
129
|
+
except ImportError:
|
|
130
|
+
pass
|
|
131
|
+
else:
|
|
132
|
+
if follow_redirects is not None:
|
|
133
|
+
return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
|
|
134
|
+
return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)
|
|
135
|
+
|
|
136
|
+
if follow_redirects is not None:
|
|
137
|
+
return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
|
|
138
|
+
return httpx.AsyncClient(timeout=timeout)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class AsyncYasminaaiApi:
|
|
142
|
+
"""
|
|
143
|
+
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.
|
|
144
|
+
|
|
145
|
+
Parameters
|
|
146
|
+
----------
|
|
147
|
+
base_url : typing.Optional[str]
|
|
148
|
+
The base url to use for requests from the client.
|
|
149
|
+
|
|
150
|
+
environment : YasminaaiApiEnvironment
|
|
151
|
+
The environment to use for requests from the client. from .environment import YasminaaiApiEnvironment
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
Defaults to YasminaaiApiEnvironment.DEFAULT
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
token : typing.Union[str, typing.Callable[[], str]]
|
|
160
|
+
headers : typing.Optional[typing.Dict[str, str]]
|
|
161
|
+
Additional headers to send with every request.
|
|
162
|
+
|
|
163
|
+
async_token : typing.Optional[typing.Callable[[], typing.Awaitable[str]]]
|
|
164
|
+
An async callable that returns a bearer token. Use this when token acquisition involves async I/O (e.g., refreshing tokens via an async HTTP client). When provided, this is used instead of the synchronous token for async requests.
|
|
165
|
+
|
|
166
|
+
timeout : typing.Optional[float]
|
|
167
|
+
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.
|
|
168
|
+
|
|
169
|
+
max_retries : typing.Optional[int]
|
|
170
|
+
The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
|
|
171
|
+
|
|
172
|
+
follow_redirects : typing.Optional[bool]
|
|
173
|
+
Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
|
|
174
|
+
|
|
175
|
+
httpx_client : typing.Optional[httpx.AsyncClient]
|
|
176
|
+
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.
|
|
177
|
+
|
|
178
|
+
logging : typing.Optional[typing.Union[LogConfig, Logger]]
|
|
179
|
+
Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.
|
|
180
|
+
|
|
181
|
+
Examples
|
|
182
|
+
--------
|
|
183
|
+
from yasminaai import AsyncYasminaaiApi
|
|
184
|
+
|
|
185
|
+
client = AsyncYasminaaiApi(
|
|
186
|
+
token="YOUR_TOKEN",
|
|
187
|
+
)
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
def __init__(
|
|
191
|
+
self,
|
|
192
|
+
*,
|
|
193
|
+
base_url: typing.Optional[str] = None,
|
|
194
|
+
environment: YasminaaiApiEnvironment = YasminaaiApiEnvironment.DEFAULT,
|
|
195
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
196
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
197
|
+
async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
|
|
198
|
+
timeout: typing.Optional[float] = None,
|
|
199
|
+
max_retries: typing.Optional[int] = None,
|
|
200
|
+
follow_redirects: typing.Optional[bool] = True,
|
|
201
|
+
httpx_client: typing.Optional[httpx.AsyncClient] = None,
|
|
202
|
+
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
|
|
203
|
+
):
|
|
204
|
+
_defaulted_timeout = (
|
|
205
|
+
timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
|
|
206
|
+
)
|
|
207
|
+
_defaulted_max_retries = max_retries if max_retries is not None else 2
|
|
208
|
+
self._client_wrapper = AsyncClientWrapper(
|
|
209
|
+
base_url=_get_base_url(base_url=base_url, environment=environment),
|
|
210
|
+
token=token,
|
|
211
|
+
headers=headers,
|
|
212
|
+
async_token=async_token,
|
|
213
|
+
httpx_client=httpx_client
|
|
214
|
+
if httpx_client is not None
|
|
215
|
+
else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
|
|
216
|
+
timeout=_defaulted_timeout,
|
|
217
|
+
max_retries=_defaulted_max_retries,
|
|
218
|
+
logging=logging,
|
|
219
|
+
)
|
|
220
|
+
self._quotes: typing.Optional[AsyncQuotesClient] = None
|
|
221
|
+
self._policies: typing.Optional[AsyncPoliciesClient] = None
|
|
222
|
+
self._ot_ps: typing.Optional[AsyncOtPsClient] = None
|
|
223
|
+
|
|
224
|
+
@property
|
|
225
|
+
def quotes(self):
|
|
226
|
+
if self._quotes is None:
|
|
227
|
+
from .quotes.client import AsyncQuotesClient # noqa: E402
|
|
228
|
+
|
|
229
|
+
self._quotes = AsyncQuotesClient(client_wrapper=self._client_wrapper)
|
|
230
|
+
return self._quotes
|
|
231
|
+
|
|
232
|
+
@property
|
|
233
|
+
def policies(self):
|
|
234
|
+
if self._policies is None:
|
|
235
|
+
from .policies.client import AsyncPoliciesClient # noqa: E402
|
|
236
|
+
|
|
237
|
+
self._policies = AsyncPoliciesClient(client_wrapper=self._client_wrapper)
|
|
238
|
+
return self._policies
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def ot_ps(self):
|
|
242
|
+
if self._ot_ps is None:
|
|
243
|
+
from .ot_ps.client import AsyncOtPsClient # noqa: E402
|
|
244
|
+
|
|
245
|
+
self._ot_ps = AsyncOtPsClient(client_wrapper=self._client_wrapper)
|
|
246
|
+
return self._ot_ps
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _get_base_url(*, base_url: typing.Optional[str] = None, environment: YasminaaiApiEnvironment) -> str:
|
|
250
|
+
if base_url is not None:
|
|
251
|
+
return base_url
|
|
252
|
+
elif environment is not None:
|
|
253
|
+
return environment.value
|
|
254
|
+
else:
|
|
255
|
+
raise Exception("Please pass in either base_url or environment to construct the client")
|
|
@@ -0,0 +1,127 @@
|
|
|
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_error import ApiError
|
|
10
|
+
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
|
|
11
|
+
from .datetime_utils import Rfc2822DateTime, parse_rfc2822_datetime, 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 encode_path_param, jsonable_encoder
|
|
16
|
+
from .logging import ConsoleLogger, ILogger, LogConfig, LogLevel, Logger, create_logger
|
|
17
|
+
from .parse_error import ParsingError
|
|
18
|
+
from .pydantic_utilities import (
|
|
19
|
+
IS_PYDANTIC_V2,
|
|
20
|
+
UniversalBaseModel,
|
|
21
|
+
UniversalRootModel,
|
|
22
|
+
parse_obj_as,
|
|
23
|
+
universal_field_validator,
|
|
24
|
+
universal_root_validator,
|
|
25
|
+
update_forward_refs,
|
|
26
|
+
)
|
|
27
|
+
from .query_encoder import encode_query
|
|
28
|
+
from .remove_none_from_dict import remove_none_from_dict
|
|
29
|
+
from .request_options import RequestOptions
|
|
30
|
+
from .serialization import FieldMetadata, convert_and_respect_annotation_metadata
|
|
31
|
+
_dynamic_imports: typing.Dict[str, str] = {
|
|
32
|
+
"ApiError": ".api_error",
|
|
33
|
+
"AsyncClientWrapper": ".client_wrapper",
|
|
34
|
+
"AsyncHttpClient": ".http_client",
|
|
35
|
+
"AsyncHttpResponse": ".http_response",
|
|
36
|
+
"BaseClientWrapper": ".client_wrapper",
|
|
37
|
+
"ConsoleLogger": ".logging",
|
|
38
|
+
"FieldMetadata": ".serialization",
|
|
39
|
+
"File": ".file",
|
|
40
|
+
"HttpClient": ".http_client",
|
|
41
|
+
"HttpResponse": ".http_response",
|
|
42
|
+
"ILogger": ".logging",
|
|
43
|
+
"IS_PYDANTIC_V2": ".pydantic_utilities",
|
|
44
|
+
"LogConfig": ".logging",
|
|
45
|
+
"LogLevel": ".logging",
|
|
46
|
+
"Logger": ".logging",
|
|
47
|
+
"ParsingError": ".parse_error",
|
|
48
|
+
"RequestOptions": ".request_options",
|
|
49
|
+
"Rfc2822DateTime": ".datetime_utils",
|
|
50
|
+
"SyncClientWrapper": ".client_wrapper",
|
|
51
|
+
"UniversalBaseModel": ".pydantic_utilities",
|
|
52
|
+
"UniversalRootModel": ".pydantic_utilities",
|
|
53
|
+
"convert_and_respect_annotation_metadata": ".serialization",
|
|
54
|
+
"convert_file_dict_to_httpx_tuples": ".file",
|
|
55
|
+
"create_logger": ".logging",
|
|
56
|
+
"encode_path_param": ".jsonable_encoder",
|
|
57
|
+
"encode_query": ".query_encoder",
|
|
58
|
+
"jsonable_encoder": ".jsonable_encoder",
|
|
59
|
+
"parse_obj_as": ".pydantic_utilities",
|
|
60
|
+
"parse_rfc2822_datetime": ".datetime_utils",
|
|
61
|
+
"remove_none_from_dict": ".remove_none_from_dict",
|
|
62
|
+
"serialize_datetime": ".datetime_utils",
|
|
63
|
+
"universal_field_validator": ".pydantic_utilities",
|
|
64
|
+
"universal_root_validator": ".pydantic_utilities",
|
|
65
|
+
"update_forward_refs": ".pydantic_utilities",
|
|
66
|
+
"with_content_type": ".file",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def __getattr__(attr_name: str) -> typing.Any:
|
|
71
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
72
|
+
if module_name is None:
|
|
73
|
+
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
|
|
74
|
+
try:
|
|
75
|
+
module = import_module(module_name, __package__)
|
|
76
|
+
if module_name == f".{attr_name}":
|
|
77
|
+
return module
|
|
78
|
+
else:
|
|
79
|
+
return getattr(module, attr_name)
|
|
80
|
+
except ImportError as e:
|
|
81
|
+
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
|
|
82
|
+
except AttributeError as e:
|
|
83
|
+
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def __dir__():
|
|
87
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
88
|
+
return sorted(lazy_attrs)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
__all__ = [
|
|
92
|
+
"ApiError",
|
|
93
|
+
"AsyncClientWrapper",
|
|
94
|
+
"AsyncHttpClient",
|
|
95
|
+
"AsyncHttpResponse",
|
|
96
|
+
"BaseClientWrapper",
|
|
97
|
+
"ConsoleLogger",
|
|
98
|
+
"FieldMetadata",
|
|
99
|
+
"File",
|
|
100
|
+
"HttpClient",
|
|
101
|
+
"HttpResponse",
|
|
102
|
+
"ILogger",
|
|
103
|
+
"IS_PYDANTIC_V2",
|
|
104
|
+
"LogConfig",
|
|
105
|
+
"LogLevel",
|
|
106
|
+
"Logger",
|
|
107
|
+
"ParsingError",
|
|
108
|
+
"RequestOptions",
|
|
109
|
+
"Rfc2822DateTime",
|
|
110
|
+
"SyncClientWrapper",
|
|
111
|
+
"UniversalBaseModel",
|
|
112
|
+
"UniversalRootModel",
|
|
113
|
+
"convert_and_respect_annotation_metadata",
|
|
114
|
+
"convert_file_dict_to_httpx_tuples",
|
|
115
|
+
"create_logger",
|
|
116
|
+
"encode_path_param",
|
|
117
|
+
"encode_query",
|
|
118
|
+
"jsonable_encoder",
|
|
119
|
+
"parse_obj_as",
|
|
120
|
+
"parse_rfc2822_datetime",
|
|
121
|
+
"remove_none_from_dict",
|
|
122
|
+
"serialize_datetime",
|
|
123
|
+
"universal_field_validator",
|
|
124
|
+
"universal_root_validator",
|
|
125
|
+
"update_forward_refs",
|
|
126
|
+
"with_content_type",
|
|
127
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ApiError(Exception):
|
|
7
|
+
headers: Optional[Dict[str, str]]
|
|
8
|
+
status_code: Optional[int]
|
|
9
|
+
body: Any
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
*,
|
|
14
|
+
headers: Optional[Dict[str, str]] = None,
|
|
15
|
+
status_code: Optional[int] = None,
|
|
16
|
+
body: Any = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
self.headers = headers
|
|
19
|
+
self.status_code = status_code
|
|
20
|
+
self.body = body
|
|
21
|
+
|
|
22
|
+
def __str__(self) -> str:
|
|
23
|
+
return f"headers: {self.headers}, status_code: {self.status_code}, body: {self.body}"
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from .http_client import AsyncHttpClient, HttpClient
|
|
7
|
+
from .logging import LogConfig, Logger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BaseClientWrapper:
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
*,
|
|
14
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
15
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
16
|
+
base_url: str,
|
|
17
|
+
timeout: typing.Optional[float] = None,
|
|
18
|
+
max_retries: int = 2,
|
|
19
|
+
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
|
|
20
|
+
):
|
|
21
|
+
self._token = token
|
|
22
|
+
self._headers = headers
|
|
23
|
+
self._base_url = base_url
|
|
24
|
+
self._timeout = timeout
|
|
25
|
+
self._max_retries = max_retries
|
|
26
|
+
self._logging = logging
|
|
27
|
+
|
|
28
|
+
def get_headers(self) -> typing.Dict[str, str]:
|
|
29
|
+
import platform
|
|
30
|
+
|
|
31
|
+
headers: typing.Dict[str, str] = {
|
|
32
|
+
"User-Agent": "motor-python-sdk/0.0.2",
|
|
33
|
+
"X-Fern-Language": "Python",
|
|
34
|
+
"X-Fern-Runtime": f"python/{platform.python_version()}",
|
|
35
|
+
"X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
|
|
36
|
+
"X-Fern-SDK-Name": "motor-python-sdk",
|
|
37
|
+
"X-Fern-SDK-Version": "0.0.2",
|
|
38
|
+
**(self.get_custom_headers() or {}),
|
|
39
|
+
}
|
|
40
|
+
headers["Authorization"] = f"Bearer {self._get_token()}"
|
|
41
|
+
return headers
|
|
42
|
+
|
|
43
|
+
def _get_token(self) -> str:
|
|
44
|
+
if isinstance(self._token, str):
|
|
45
|
+
return self._token
|
|
46
|
+
else:
|
|
47
|
+
return self._token()
|
|
48
|
+
|
|
49
|
+
def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
|
|
50
|
+
return self._headers
|
|
51
|
+
|
|
52
|
+
def get_base_url(self) -> str:
|
|
53
|
+
return self._base_url
|
|
54
|
+
|
|
55
|
+
def get_timeout(self) -> typing.Optional[float]:
|
|
56
|
+
return self._timeout
|
|
57
|
+
|
|
58
|
+
def get_max_retries(self) -> int:
|
|
59
|
+
return self._max_retries
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class SyncClientWrapper(BaseClientWrapper):
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
*,
|
|
66
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
67
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
68
|
+
base_url: str,
|
|
69
|
+
timeout: typing.Optional[float] = None,
|
|
70
|
+
max_retries: int = 2,
|
|
71
|
+
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
|
|
72
|
+
httpx_client: httpx.Client,
|
|
73
|
+
):
|
|
74
|
+
super().__init__(
|
|
75
|
+
token=token, headers=headers, base_url=base_url, timeout=timeout, max_retries=max_retries, logging=logging
|
|
76
|
+
)
|
|
77
|
+
self.httpx_client = HttpClient(
|
|
78
|
+
httpx_client=httpx_client,
|
|
79
|
+
base_headers=self.get_headers,
|
|
80
|
+
base_timeout=self.get_timeout,
|
|
81
|
+
base_url=self.get_base_url,
|
|
82
|
+
base_max_retries=self.get_max_retries(),
|
|
83
|
+
logging_config=self._logging,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class AsyncClientWrapper(BaseClientWrapper):
|
|
88
|
+
def __init__(
|
|
89
|
+
self,
|
|
90
|
+
*,
|
|
91
|
+
token: typing.Union[str, typing.Callable[[], str]],
|
|
92
|
+
headers: typing.Optional[typing.Dict[str, str]] = None,
|
|
93
|
+
base_url: str,
|
|
94
|
+
timeout: typing.Optional[float] = None,
|
|
95
|
+
max_retries: int = 2,
|
|
96
|
+
logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
|
|
97
|
+
async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
|
|
98
|
+
httpx_client: httpx.AsyncClient,
|
|
99
|
+
):
|
|
100
|
+
super().__init__(
|
|
101
|
+
token=token, headers=headers, base_url=base_url, timeout=timeout, max_retries=max_retries, logging=logging
|
|
102
|
+
)
|
|
103
|
+
self._async_token = async_token
|
|
104
|
+
self.httpx_client = AsyncHttpClient(
|
|
105
|
+
httpx_client=httpx_client,
|
|
106
|
+
base_headers=self.get_headers,
|
|
107
|
+
base_timeout=self.get_timeout,
|
|
108
|
+
base_url=self.get_base_url,
|
|
109
|
+
base_max_retries=self.get_max_retries(),
|
|
110
|
+
async_base_headers=self.async_get_headers,
|
|
111
|
+
logging_config=self._logging,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
async def async_get_headers(self) -> typing.Dict[str, str]:
|
|
115
|
+
headers = self.get_headers()
|
|
116
|
+
if self._async_token is not None:
|
|
117
|
+
token = await self._async_token()
|
|
118
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
119
|
+
return headers
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import datetime as dt
|
|
4
|
+
from email.utils import parsedate_to_datetime
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import pydantic
|
|
8
|
+
|
|
9
|
+
IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_rfc2822_datetime(v: Any) -> dt.datetime:
|
|
13
|
+
"""
|
|
14
|
+
Parse an RFC 2822 datetime string (e.g., "Wed, 02 Oct 2002 13:00:00 GMT")
|
|
15
|
+
into a datetime object. If the value is already a datetime, return it as-is.
|
|
16
|
+
Falls back to ISO 8601 parsing if RFC 2822 parsing fails.
|
|
17
|
+
"""
|
|
18
|
+
if isinstance(v, dt.datetime):
|
|
19
|
+
return v
|
|
20
|
+
if isinstance(v, str):
|
|
21
|
+
try:
|
|
22
|
+
return parsedate_to_datetime(v)
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
25
|
+
# Fallback to ISO 8601 parsing
|
|
26
|
+
return dt.datetime.fromisoformat(v.replace("Z", "+00:00"))
|
|
27
|
+
raise ValueError(f"Expected str or datetime, got {type(v)}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Rfc2822DateTime(dt.datetime):
|
|
31
|
+
"""A datetime subclass that parses RFC 2822 date strings.
|
|
32
|
+
|
|
33
|
+
On Pydantic V1, uses __get_validators__ for pre-validation.
|
|
34
|
+
On Pydantic V2, uses __get_pydantic_core_schema__ for BeforeValidator-style parsing.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def __get_validators__(cls): # type: ignore[no-untyped-def]
|
|
39
|
+
yield parse_rfc2822_datetime
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> Any: # type: ignore[override]
|
|
43
|
+
from pydantic_core import core_schema
|
|
44
|
+
|
|
45
|
+
return core_schema.no_info_before_validator_function(parse_rfc2822_datetime, core_schema.datetime_schema())
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def serialize_datetime(v: dt.datetime) -> str:
|
|
49
|
+
"""
|
|
50
|
+
Serialize a datetime including timezone info.
|
|
51
|
+
|
|
52
|
+
Uses the timezone info provided if present, otherwise uses the current runtime's timezone info.
|
|
53
|
+
|
|
54
|
+
UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def _serialize_zoned_datetime(v: dt.datetime) -> str:
|
|
58
|
+
if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None):
|
|
59
|
+
# UTC is a special case where we use "Z" at the end instead of "+00:00"
|
|
60
|
+
return v.isoformat().replace("+00:00", "Z")
|
|
61
|
+
else:
|
|
62
|
+
# Delegate to the typical +/- offset format
|
|
63
|
+
return v.isoformat()
|
|
64
|
+
|
|
65
|
+
if v.tzinfo is not None:
|
|
66
|
+
return _serialize_zoned_datetime(v)
|
|
67
|
+
else:
|
|
68
|
+
local_tz = dt.datetime.now().astimezone().tzinfo
|
|
69
|
+
localized_dt = v.replace(tzinfo=local_tz)
|
|
70
|
+
return _serialize_zoned_datetime(localized_dt)
|
yasminaai/core/file.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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(Tuple[Optional[str], FileContent, Optional[str]], file) # type: ignore
|
|
57
|
+
out_content_type = file_content_type or default_content_type
|
|
58
|
+
return (filename, content, out_content_type)
|
|
59
|
+
elif len(file) == 4:
|
|
60
|
+
filename, content, file_content_type, headers = cast( # type: ignore
|
|
61
|
+
Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]], file
|
|
62
|
+
)
|
|
63
|
+
out_content_type = file_content_type or default_content_type
|
|
64
|
+
return (filename, content, out_content_type, headers)
|
|
65
|
+
else:
|
|
66
|
+
raise ValueError(f"Unexpected tuple length: {len(file)}")
|
|
67
|
+
return (None, file, default_content_type)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ForceMultipartDict(Dict[str, Any]):
|
|
7
|
+
"""
|
|
8
|
+
A dictionary subclass that always evaluates to True in boolean contexts.
|
|
9
|
+
|
|
10
|
+
This is used to force multipart/form-data encoding in HTTP requests even when
|
|
11
|
+
the dictionary is empty, which would normally evaluate to False.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __bool__(self) -> bool:
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
FORCE_MULTIPART = ForceMultipartDict()
|