widgets.sdk-dot10140707 0.2.0__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.
Files changed (33) hide show
  1. widgets_sdk_dot10140707/__init__.py +54 -0
  2. widgets_sdk_dot10140707/_default_clients.py +32 -0
  3. widgets_sdk_dot10140707/client.py +282 -0
  4. widgets_sdk_dot10140707/core/__init__.py +127 -0
  5. widgets_sdk_dot10140707/core/api_error.py +23 -0
  6. widgets_sdk_dot10140707/core/client_wrapper.py +133 -0
  7. widgets_sdk_dot10140707/core/datetime_utils.py +70 -0
  8. widgets_sdk_dot10140707/core/file.py +67 -0
  9. widgets_sdk_dot10140707/core/force_multipart.py +18 -0
  10. widgets_sdk_dot10140707/core/http_client.py +940 -0
  11. widgets_sdk_dot10140707/core/http_response.py +63 -0
  12. widgets_sdk_dot10140707/core/http_sse/__init__.py +42 -0
  13. widgets_sdk_dot10140707/core/http_sse/_api.py +455 -0
  14. widgets_sdk_dot10140707/core/http_sse/_decoders.py +74 -0
  15. widgets_sdk_dot10140707/core/http_sse/_exceptions.py +7 -0
  16. widgets_sdk_dot10140707/core/http_sse/_models.py +17 -0
  17. widgets_sdk_dot10140707/core/jsonable_encoder.py +133 -0
  18. widgets_sdk_dot10140707/core/logging.py +107 -0
  19. widgets_sdk_dot10140707/core/parse_error.py +36 -0
  20. widgets_sdk_dot10140707/core/pydantic_utilities.py +508 -0
  21. widgets_sdk_dot10140707/core/query_encoder.py +58 -0
  22. widgets_sdk_dot10140707/core/remove_none_from_dict.py +11 -0
  23. widgets_sdk_dot10140707/core/request_options.py +40 -0
  24. widgets_sdk_dot10140707/core/serialization.py +347 -0
  25. widgets_sdk_dot10140707/environment.py +7 -0
  26. widgets_sdk_dot10140707/py.typed +0 -0
  27. widgets_sdk_dot10140707/raw_client.py +104 -0
  28. widgets_sdk_dot10140707/types/__init__.py +34 -0
  29. widgets_sdk_dot10140707/types/widget.py +20 -0
  30. widgets_sdk_dot10140707/version.py +3 -0
  31. widgets_sdk_dot10140707-0.2.0.dist-info/METADATA +217 -0
  32. widgets_sdk_dot10140707-0.2.0.dist-info/RECORD +33 -0
  33. widgets_sdk_dot10140707-0.2.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,54 @@
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 .types import Widget
10
+ from ._default_clients import DefaultAioHttpClient, DefaultAsyncHttpxClient
11
+ from .client import AsyncWidgetsDemo1014Api, WidgetsDemo1014Api
12
+ from .environment import WidgetsDemo1014ApiEnvironment
13
+ from .version import __version__
14
+ _dynamic_imports: typing.Dict[str, str] = {
15
+ "AsyncWidgetsDemo1014Api": ".client",
16
+ "DefaultAioHttpClient": "._default_clients",
17
+ "DefaultAsyncHttpxClient": "._default_clients",
18
+ "Widget": ".types",
19
+ "WidgetsDemo1014Api": ".client",
20
+ "WidgetsDemo1014ApiEnvironment": ".environment",
21
+ "__version__": ".version",
22
+ }
23
+
24
+
25
+ def __getattr__(attr_name: str) -> typing.Any:
26
+ module_name = _dynamic_imports.get(attr_name)
27
+ if module_name is None:
28
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
29
+ try:
30
+ module = import_module(module_name, __package__)
31
+ if module_name == f".{attr_name}":
32
+ return module
33
+ else:
34
+ return getattr(module, attr_name)
35
+ except ImportError as e:
36
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
37
+ except AttributeError as e:
38
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
39
+
40
+
41
+ def __dir__():
42
+ lazy_attrs = list(_dynamic_imports.keys())
43
+ return sorted(lazy_attrs)
44
+
45
+
46
+ __all__ = [
47
+ "AsyncWidgetsDemo1014Api",
48
+ "DefaultAioHttpClient",
49
+ "DefaultAsyncHttpxClient",
50
+ "Widget",
51
+ "WidgetsDemo1014Api",
52
+ "WidgetsDemo1014ApiEnvironment",
53
+ "__version__",
54
+ ]
@@ -0,0 +1,32 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+
7
+ SDK_DEFAULT_TIMEOUT = 60
8
+
9
+ try:
10
+ import httpx_aiohttp # type: ignore[import-not-found]
11
+ except ImportError:
12
+
13
+ class DefaultAioHttpClient(httpx.AsyncClient): # type: ignore
14
+ def __init__(self, **kwargs: typing.Any) -> None:
15
+ raise RuntimeError(
16
+ "To use the aiohttp client, install the aiohttp extra: pip install widgets.sdk_dot10140707[aiohttp]"
17
+ )
18
+
19
+ else:
20
+
21
+ class DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
22
+ def __init__(self, **kwargs: typing.Any) -> None:
23
+ kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
24
+ kwargs.setdefault("follow_redirects", True)
25
+ super().__init__(**kwargs)
26
+
27
+
28
+ class DefaultAsyncHttpxClient(httpx.AsyncClient):
29
+ def __init__(self, **kwargs: typing.Any) -> None:
30
+ kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
31
+ kwargs.setdefault("follow_redirects", True)
32
+ super().__init__(**kwargs)
@@ -0,0 +1,282 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
7
+ from .core.logging import LogConfig, Logger
8
+ from .core.request_options import RequestOptions
9
+ from .environment import WidgetsDemo1014ApiEnvironment
10
+ from .raw_client import AsyncRawWidgetsDemo1014Api, RawWidgetsDemo1014Api
11
+ from .types.widget import Widget
12
+
13
+
14
+ class WidgetsDemo1014Api:
15
+ """
16
+ 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.
17
+
18
+ Parameters
19
+ ----------
20
+ base_url : typing.Optional[str]
21
+ The base url to use for requests from the client.
22
+
23
+ environment : WidgetsDemo1014ApiEnvironment
24
+ The environment to use for requests from the client. from .environment import WidgetsDemo1014ApiEnvironment
25
+
26
+
27
+
28
+ Defaults to WidgetsDemo1014ApiEnvironment.DEFAULT
29
+
30
+
31
+
32
+ headers : typing.Optional[typing.Dict[str, str]]
33
+ Additional headers to send with every request.
34
+
35
+ timeout : typing.Optional[float]
36
+ 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.
37
+
38
+ max_retries : typing.Optional[int]
39
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
40
+
41
+ stream_reconnection_enabled : typing.Optional[bool]
42
+ Whether to automatically reconnect on stream disconnection for resumable streaming endpoints. Defaults to True. Per-request `stream_reconnection_enabled` in `request_options` takes precedence over this value.
43
+
44
+ max_stream_reconnection_attempts : typing.Optional[int]
45
+ The maximum number of reconnection attempts for resumable streaming endpoints. Defaults to no limit. Per-request `max_stream_reconnection_attempts` in `request_options` takes precedence over this value.
46
+
47
+ follow_redirects : typing.Optional[bool]
48
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
49
+
50
+ httpx_client : typing.Optional[httpx.Client]
51
+ 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.
52
+
53
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
54
+ 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.
55
+
56
+ Examples
57
+ --------
58
+ from widgets_sdk_dot10140707 import WidgetsDemo1014Api
59
+
60
+ client = WidgetsDemo1014Api()
61
+ """
62
+
63
+ def __init__(
64
+ self,
65
+ *,
66
+ base_url: typing.Optional[str] = None,
67
+ environment: WidgetsDemo1014ApiEnvironment = WidgetsDemo1014ApiEnvironment.DEFAULT,
68
+ headers: typing.Optional[typing.Dict[str, str]] = None,
69
+ timeout: typing.Optional[float] = None,
70
+ max_retries: typing.Optional[int] = None,
71
+ stream_reconnection_enabled: typing.Optional[bool] = None,
72
+ max_stream_reconnection_attempts: 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 = timeout if timeout is not None else 60 if httpx_client is None else None
78
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
79
+ self._client_wrapper = SyncClientWrapper(
80
+ base_url=_get_base_url(base_url=base_url, environment=environment),
81
+ headers=headers,
82
+ httpx_client=httpx_client
83
+ if httpx_client is not None
84
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
85
+ if follow_redirects is not None
86
+ else httpx.Client(timeout=_defaulted_timeout),
87
+ timeout=_defaulted_timeout,
88
+ max_retries=_defaulted_max_retries,
89
+ stream_reconnection_enabled=stream_reconnection_enabled,
90
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
91
+ logging=logging,
92
+ )
93
+ self._raw_client = RawWidgetsDemo1014Api(client_wrapper=self._client_wrapper)
94
+
95
+ @property
96
+ def with_raw_response(self) -> RawWidgetsDemo1014Api:
97
+ """
98
+ Retrieves a raw implementation of this client that returns raw responses.
99
+
100
+ Returns
101
+ -------
102
+ RawWidgetsDemo1014Api
103
+ """
104
+ return self._raw_client
105
+
106
+ def get_widget(self, widget_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Widget:
107
+ """
108
+ Parameters
109
+ ----------
110
+ widget_id : str
111
+
112
+ request_options : typing.Optional[RequestOptions]
113
+ Request-specific configuration.
114
+
115
+ Returns
116
+ -------
117
+ Widget
118
+ A widget
119
+
120
+ Examples
121
+ --------
122
+ from widgets_sdk_dot10140707 import WidgetsDemo1014Api
123
+
124
+ client = WidgetsDemo1014Api()
125
+ client.get_widget(
126
+ widget_id="widgetId",
127
+ )
128
+ """
129
+ _response = self._raw_client.get_widget(widget_id, request_options=request_options)
130
+ return _response.data
131
+
132
+
133
+ def _make_default_async_client(
134
+ timeout: typing.Optional[float],
135
+ follow_redirects: typing.Optional[bool],
136
+ ) -> httpx.AsyncClient:
137
+ try:
138
+ import httpx_aiohttp # type: ignore[import-not-found]
139
+ except ImportError:
140
+ pass
141
+ else:
142
+ if follow_redirects is not None:
143
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
144
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)
145
+
146
+ if follow_redirects is not None:
147
+ return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
148
+ return httpx.AsyncClient(timeout=timeout)
149
+
150
+
151
+ class AsyncWidgetsDemo1014Api:
152
+ """
153
+ 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.
154
+
155
+ Parameters
156
+ ----------
157
+ base_url : typing.Optional[str]
158
+ The base url to use for requests from the client.
159
+
160
+ environment : WidgetsDemo1014ApiEnvironment
161
+ The environment to use for requests from the client. from .environment import WidgetsDemo1014ApiEnvironment
162
+
163
+
164
+
165
+ Defaults to WidgetsDemo1014ApiEnvironment.DEFAULT
166
+
167
+
168
+
169
+ headers : typing.Optional[typing.Dict[str, str]]
170
+ Additional headers to send with every request.
171
+
172
+ timeout : typing.Optional[float]
173
+ 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.
174
+
175
+ max_retries : typing.Optional[int]
176
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
177
+
178
+ stream_reconnection_enabled : typing.Optional[bool]
179
+ Whether to automatically reconnect on stream disconnection for resumable streaming endpoints. Defaults to True. Per-request `stream_reconnection_enabled` in `request_options` takes precedence over this value.
180
+
181
+ max_stream_reconnection_attempts : typing.Optional[int]
182
+ The maximum number of reconnection attempts for resumable streaming endpoints. Defaults to no limit. Per-request `max_stream_reconnection_attempts` in `request_options` takes precedence over this value.
183
+
184
+ follow_redirects : typing.Optional[bool]
185
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
186
+
187
+ httpx_client : typing.Optional[httpx.AsyncClient]
188
+ 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.
189
+
190
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
191
+ 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.
192
+
193
+ Examples
194
+ --------
195
+ from widgets_sdk_dot10140707 import AsyncWidgetsDemo1014Api
196
+
197
+ client = AsyncWidgetsDemo1014Api()
198
+ """
199
+
200
+ def __init__(
201
+ self,
202
+ *,
203
+ base_url: typing.Optional[str] = None,
204
+ environment: WidgetsDemo1014ApiEnvironment = WidgetsDemo1014ApiEnvironment.DEFAULT,
205
+ headers: typing.Optional[typing.Dict[str, str]] = None,
206
+ timeout: typing.Optional[float] = None,
207
+ max_retries: typing.Optional[int] = None,
208
+ stream_reconnection_enabled: typing.Optional[bool] = None,
209
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
210
+ follow_redirects: typing.Optional[bool] = True,
211
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
212
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
213
+ ):
214
+ _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
215
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
216
+ self._client_wrapper = AsyncClientWrapper(
217
+ base_url=_get_base_url(base_url=base_url, environment=environment),
218
+ headers=headers,
219
+ httpx_client=httpx_client
220
+ if httpx_client is not None
221
+ else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
222
+ timeout=_defaulted_timeout,
223
+ max_retries=_defaulted_max_retries,
224
+ stream_reconnection_enabled=stream_reconnection_enabled,
225
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
226
+ logging=logging,
227
+ )
228
+ self._raw_client = AsyncRawWidgetsDemo1014Api(client_wrapper=self._client_wrapper)
229
+
230
+ @property
231
+ def with_raw_response(self) -> AsyncRawWidgetsDemo1014Api:
232
+ """
233
+ Retrieves a raw implementation of this client that returns raw responses.
234
+
235
+ Returns
236
+ -------
237
+ AsyncRawWidgetsDemo1014Api
238
+ """
239
+ return self._raw_client
240
+
241
+ async def get_widget(self, widget_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> Widget:
242
+ """
243
+ Parameters
244
+ ----------
245
+ widget_id : str
246
+
247
+ request_options : typing.Optional[RequestOptions]
248
+ Request-specific configuration.
249
+
250
+ Returns
251
+ -------
252
+ Widget
253
+ A widget
254
+
255
+ Examples
256
+ --------
257
+ import asyncio
258
+
259
+ from widgets_sdk_dot10140707 import AsyncWidgetsDemo1014Api
260
+
261
+ client = AsyncWidgetsDemo1014Api()
262
+
263
+
264
+ async def main() -> None:
265
+ await client.get_widget(
266
+ widget_id="widgetId",
267
+ )
268
+
269
+
270
+ asyncio.run(main())
271
+ """
272
+ _response = await self._raw_client.get_widget(widget_id, request_options=request_options)
273
+ return _response.data
274
+
275
+
276
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: WidgetsDemo1014ApiEnvironment) -> str:
277
+ if base_url is not None:
278
+ return base_url
279
+ elif environment is not None:
280
+ return environment.value
281
+ else:
282
+ 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,133 @@
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
+ headers: typing.Optional[typing.Dict[str, str]] = None,
15
+ base_url: str,
16
+ timeout: typing.Optional[float] = None,
17
+ max_retries: int = 2,
18
+ stream_reconnection_enabled: typing.Optional[bool] = None,
19
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
20
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
21
+ ):
22
+ self._headers = headers
23
+ self._base_url = base_url
24
+ self._timeout = timeout
25
+ self._max_retries = max_retries
26
+ self._stream_reconnection_enabled = stream_reconnection_enabled
27
+ self._max_stream_reconnection_attempts = max_stream_reconnection_attempts
28
+ self._logging = logging
29
+
30
+ def get_headers(self) -> typing.Dict[str, str]:
31
+ import platform
32
+
33
+ headers: typing.Dict[str, str] = {
34
+ "X-Fern-Language": "Python",
35
+ "X-Fern-Runtime": f"python/{platform.python_version()}",
36
+ "X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
37
+ "X-Fern-SDK-Name": "widgets.sdk_dot10140707",
38
+ "X-Fern-SDK-Version": "0.2.0",
39
+ **(self.get_custom_headers() or {}),
40
+ }
41
+ return headers
42
+
43
+ def get_custom_headers(self) -> typing.Optional[typing.Dict[str, str]]:
44
+ return self._headers
45
+
46
+ def get_base_url(self) -> str:
47
+ return self._base_url
48
+
49
+ def get_timeout(self) -> typing.Optional[float]:
50
+ return self._timeout
51
+
52
+ def get_max_retries(self) -> int:
53
+ return self._max_retries
54
+
55
+ def get_stream_reconnection_enabled(self) -> bool:
56
+ return self._stream_reconnection_enabled if self._stream_reconnection_enabled is not None else True
57
+
58
+ def get_max_stream_reconnection_attempts(self) -> typing.Optional[int]:
59
+ return self._max_stream_reconnection_attempts
60
+
61
+
62
+ class SyncClientWrapper(BaseClientWrapper):
63
+ def __init__(
64
+ self,
65
+ *,
66
+ headers: typing.Optional[typing.Dict[str, str]] = None,
67
+ base_url: str,
68
+ timeout: typing.Optional[float] = None,
69
+ max_retries: int = 2,
70
+ stream_reconnection_enabled: typing.Optional[bool] = None,
71
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
72
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
73
+ httpx_client: httpx.Client,
74
+ ):
75
+ super().__init__(
76
+ headers=headers,
77
+ base_url=base_url,
78
+ timeout=timeout,
79
+ max_retries=max_retries,
80
+ stream_reconnection_enabled=stream_reconnection_enabled,
81
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
82
+ logging=logging,
83
+ )
84
+ self.httpx_client = HttpClient(
85
+ httpx_client=httpx_client,
86
+ base_headers=self.get_headers,
87
+ base_timeout=self.get_timeout,
88
+ base_url=self.get_base_url,
89
+ base_max_retries=self.get_max_retries(),
90
+ logging_config=self._logging,
91
+ )
92
+
93
+
94
+ class AsyncClientWrapper(BaseClientWrapper):
95
+ def __init__(
96
+ self,
97
+ *,
98
+ headers: typing.Optional[typing.Dict[str, str]] = None,
99
+ base_url: str,
100
+ timeout: typing.Optional[float] = None,
101
+ max_retries: int = 2,
102
+ stream_reconnection_enabled: typing.Optional[bool] = None,
103
+ max_stream_reconnection_attempts: typing.Optional[int] = None,
104
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
105
+ async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
106
+ httpx_client: httpx.AsyncClient,
107
+ ):
108
+ super().__init__(
109
+ headers=headers,
110
+ base_url=base_url,
111
+ timeout=timeout,
112
+ max_retries=max_retries,
113
+ stream_reconnection_enabled=stream_reconnection_enabled,
114
+ max_stream_reconnection_attempts=max_stream_reconnection_attempts,
115
+ logging=logging,
116
+ )
117
+ self._async_token = async_token
118
+ self.httpx_client = AsyncHttpClient(
119
+ httpx_client=httpx_client,
120
+ base_headers=self.get_headers,
121
+ base_timeout=self.get_timeout,
122
+ base_url=self.get_base_url,
123
+ base_max_retries=self.get_max_retries(),
124
+ async_base_headers=self.async_get_headers,
125
+ logging_config=self._logging,
126
+ )
127
+
128
+ async def async_get_headers(self) -> typing.Dict[str, str]:
129
+ headers = self.get_headers()
130
+ if self._async_token is not None:
131
+ token = await self._async_token()
132
+ headers["Authorization"] = f"Bearer {token}"
133
+ return headers