contextbase-base-client 0.5.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 (79) hide show
  1. base_client/.fern/metadata.json +13 -0
  2. base_client/CONTRIBUTING.md +125 -0
  3. base_client/README.md +176 -0
  4. base_client/__init__.py +159 -0
  5. base_client/_default_clients.py +30 -0
  6. base_client/bases/__init__.py +34 -0
  7. base_client/bases/client.py +256 -0
  8. base_client/bases/raw_client.py +365 -0
  9. base_client/bases/types/__init__.py +34 -0
  10. base_client/bases/types/list_bases_response.py +20 -0
  11. base_client/binding_plan/__init__.py +4 -0
  12. base_client/binding_plan/client.py +108 -0
  13. base_client/binding_plan/raw_client.py +128 -0
  14. base_client/bindings/__init__.py +34 -0
  15. base_client/bindings/client.py +242 -0
  16. base_client/bindings/raw_client.py +326 -0
  17. base_client/bindings/types/__init__.py +34 -0
  18. base_client/bindings/types/list_bindings_response.py +20 -0
  19. base_client/client.py +252 -0
  20. base_client/core/__init__.py +127 -0
  21. base_client/core/api_error.py +23 -0
  22. base_client/core/client_wrapper.py +102 -0
  23. base_client/core/datetime_utils.py +70 -0
  24. base_client/core/file.py +67 -0
  25. base_client/core/force_multipart.py +18 -0
  26. base_client/core/http_client.py +839 -0
  27. base_client/core/http_response.py +59 -0
  28. base_client/core/http_sse/__init__.py +42 -0
  29. base_client/core/http_sse/_api.py +170 -0
  30. base_client/core/http_sse/_decoders.py +61 -0
  31. base_client/core/http_sse/_exceptions.py +7 -0
  32. base_client/core/http_sse/_models.py +17 -0
  33. base_client/core/jsonable_encoder.py +120 -0
  34. base_client/core/logging.py +107 -0
  35. base_client/core/parse_error.py +36 -0
  36. base_client/core/pydantic_utilities.py +508 -0
  37. base_client/core/query_encoder.py +58 -0
  38. base_client/core/remove_none_from_dict.py +11 -0
  39. base_client/core/request_options.py +35 -0
  40. base_client/core/serialization.py +347 -0
  41. base_client/dsn/__init__.py +4 -0
  42. base_client/dsn/client.py +104 -0
  43. base_client/dsn/raw_client.py +128 -0
  44. base_client/errors/__init__.py +38 -0
  45. base_client/errors/bad_request_error.py +11 -0
  46. base_client/errors/forbidden_error.py +11 -0
  47. base_client/reference.md +591 -0
  48. base_client/sync_state/__init__.py +34 -0
  49. base_client/sync_state/client.py +206 -0
  50. base_client/sync_state/raw_client.py +280 -0
  51. base_client/sync_state/types/__init__.py +34 -0
  52. base_client/sync_state/types/sync_state_input_bindings_value.py +23 -0
  53. base_client/tests/conftest.py +21 -0
  54. base_client/tests/test_aiohttp_autodetect.py +113 -0
  55. base_client/types/__init__.py +126 -0
  56. base_client/types/api_key_auth.py +19 -0
  57. base_client/types/authenticated_account_ref.py +20 -0
  58. base_client/types/base.py +23 -0
  59. base_client/types/binding.py +29 -0
  60. base_client/types/binding_auth.py +72 -0
  61. base_client/types/binding_auth_input.py +77 -0
  62. base_client/types/binding_auth_input_api_key.py +19 -0
  63. base_client/types/binding_auth_input_authenticated_account.py +20 -0
  64. base_client/types/binding_auth_input_client_credentials.py +20 -0
  65. base_client/types/binding_auth_input_none.py +17 -0
  66. base_client/types/binding_auth_none.py +17 -0
  67. base_client/types/binding_models.py +23 -0
  68. base_client/types/binding_state.py +24 -0
  69. base_client/types/binding_state_response.py +21 -0
  70. base_client/types/client_credentials_auth.py +20 -0
  71. base_client/types/dagster_all_plan_binding.py +27 -0
  72. base_client/types/dagster_all_plan_binding_mode.py +5 -0
  73. base_client/types/dagster_binding_plan_all.py +23 -0
  74. base_client/types/dsn_response.py +19 -0
  75. base_client/types/error.py +19 -0
  76. base_client/types/run_status.py +10 -0
  77. contextbase_base_client-0.5.0.dist-info/METADATA +10 -0
  78. contextbase_base_client-0.5.0.dist-info/RECORD +79 -0
  79. contextbase_base_client-0.5.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,326 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from json.decoder import JSONDecodeError
5
+
6
+ from ..core.api_error import ApiError
7
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8
+ from ..core.http_response import AsyncHttpResponse, HttpResponse
9
+ from ..core.jsonable_encoder import encode_path_param
10
+ from ..core.parse_error import ParsingError
11
+ from ..core.pydantic_utilities import parse_obj_as
12
+ from ..core.request_options import RequestOptions
13
+ from ..core.serialization import convert_and_respect_annotation_metadata
14
+ from ..errors.bad_request_error import BadRequestError
15
+ from ..errors.forbidden_error import ForbiddenError
16
+ from ..types.binding import Binding
17
+ from ..types.binding_auth_input import BindingAuthInput
18
+ from ..types.binding_models import BindingModels
19
+ from ..types.error import Error
20
+ from .types.list_bindings_response import ListBindingsResponse
21
+ from pydantic import ValidationError
22
+
23
+ # this is used as the default value for optional parameters
24
+ OMIT = typing.cast(typing.Any, ...)
25
+
26
+
27
+ class RawBindingsClient:
28
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
29
+ self._client_wrapper = client_wrapper
30
+
31
+ def list_bindings(
32
+ self, base_id: str, *, request_options: typing.Optional[RequestOptions] = None
33
+ ) -> HttpResponse[ListBindingsResponse]:
34
+ """
35
+ Parameters
36
+ ----------
37
+ base_id : str
38
+
39
+ request_options : typing.Optional[RequestOptions]
40
+ Request-specific configuration.
41
+
42
+ Returns
43
+ -------
44
+ HttpResponse[ListBindingsResponse]
45
+ Bindings for the base.
46
+ """
47
+ _response = self._client_wrapper.httpx_client.request(
48
+ f"base/bases/{encode_path_param(base_id)}/bindings",
49
+ method="GET",
50
+ request_options=request_options,
51
+ )
52
+ try:
53
+ if 200 <= _response.status_code < 300:
54
+ _data = typing.cast(
55
+ ListBindingsResponse,
56
+ parse_obj_as(
57
+ type_=ListBindingsResponse, # type: ignore
58
+ object_=_response.json(),
59
+ ),
60
+ )
61
+ return HttpResponse(response=_response, data=_data)
62
+ if _response.status_code == 403:
63
+ raise ForbiddenError(
64
+ headers=dict(_response.headers),
65
+ body=typing.cast(
66
+ Error,
67
+ parse_obj_as(
68
+ type_=Error, # type: ignore
69
+ object_=_response.json(),
70
+ ),
71
+ ),
72
+ )
73
+ _response_json = _response.json()
74
+ except JSONDecodeError:
75
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
76
+ except ValidationError as e:
77
+ raise ParsingError(
78
+ status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
79
+ )
80
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
81
+
82
+ def create_binding(
83
+ self,
84
+ base_id: str,
85
+ *,
86
+ auth: BindingAuthInput,
87
+ plugin_id: str,
88
+ config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
89
+ enabled: typing.Optional[bool] = OMIT,
90
+ models: typing.Optional[BindingModels] = OMIT,
91
+ request_options: typing.Optional[RequestOptions] = None,
92
+ ) -> HttpResponse[Binding]:
93
+ """
94
+ Parameters
95
+ ----------
96
+ base_id : str
97
+
98
+ auth : BindingAuthInput
99
+
100
+ plugin_id : str
101
+
102
+ config : typing.Optional[typing.Dict[str, typing.Any]]
103
+
104
+ enabled : typing.Optional[bool]
105
+
106
+ models : typing.Optional[BindingModels]
107
+
108
+ request_options : typing.Optional[RequestOptions]
109
+ Request-specific configuration.
110
+
111
+ Returns
112
+ -------
113
+ HttpResponse[Binding]
114
+ The created binding.
115
+ """
116
+ _response = self._client_wrapper.httpx_client.request(
117
+ f"base/bases/{encode_path_param(base_id)}/bindings",
118
+ method="POST",
119
+ json={
120
+ "auth": convert_and_respect_annotation_metadata(
121
+ object_=auth, annotation=BindingAuthInput, direction="write"
122
+ ),
123
+ "config": config,
124
+ "enabled": enabled,
125
+ "models": convert_and_respect_annotation_metadata(
126
+ object_=models, annotation=typing.Optional[BindingModels], direction="write"
127
+ ),
128
+ "plugin_id": plugin_id,
129
+ },
130
+ headers={
131
+ "content-type": "application/json",
132
+ },
133
+ request_options=request_options,
134
+ omit=OMIT,
135
+ )
136
+ try:
137
+ if 200 <= _response.status_code < 300:
138
+ _data = typing.cast(
139
+ Binding,
140
+ parse_obj_as(
141
+ type_=Binding, # type: ignore
142
+ object_=_response.json(),
143
+ ),
144
+ )
145
+ return HttpResponse(response=_response, data=_data)
146
+ if _response.status_code == 400:
147
+ raise BadRequestError(
148
+ headers=dict(_response.headers),
149
+ body=typing.cast(
150
+ Error,
151
+ parse_obj_as(
152
+ type_=Error, # type: ignore
153
+ object_=_response.json(),
154
+ ),
155
+ ),
156
+ )
157
+ if _response.status_code == 403:
158
+ raise ForbiddenError(
159
+ headers=dict(_response.headers),
160
+ body=typing.cast(
161
+ Error,
162
+ parse_obj_as(
163
+ type_=Error, # type: ignore
164
+ object_=_response.json(),
165
+ ),
166
+ ),
167
+ )
168
+ _response_json = _response.json()
169
+ except JSONDecodeError:
170
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
171
+ except ValidationError as e:
172
+ raise ParsingError(
173
+ status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
174
+ )
175
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
176
+
177
+
178
+ class AsyncRawBindingsClient:
179
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
180
+ self._client_wrapper = client_wrapper
181
+
182
+ async def list_bindings(
183
+ self, base_id: str, *, request_options: typing.Optional[RequestOptions] = None
184
+ ) -> AsyncHttpResponse[ListBindingsResponse]:
185
+ """
186
+ Parameters
187
+ ----------
188
+ base_id : str
189
+
190
+ request_options : typing.Optional[RequestOptions]
191
+ Request-specific configuration.
192
+
193
+ Returns
194
+ -------
195
+ AsyncHttpResponse[ListBindingsResponse]
196
+ Bindings for the base.
197
+ """
198
+ _response = await self._client_wrapper.httpx_client.request(
199
+ f"base/bases/{encode_path_param(base_id)}/bindings",
200
+ method="GET",
201
+ request_options=request_options,
202
+ )
203
+ try:
204
+ if 200 <= _response.status_code < 300:
205
+ _data = typing.cast(
206
+ ListBindingsResponse,
207
+ parse_obj_as(
208
+ type_=ListBindingsResponse, # type: ignore
209
+ object_=_response.json(),
210
+ ),
211
+ )
212
+ return AsyncHttpResponse(response=_response, data=_data)
213
+ if _response.status_code == 403:
214
+ raise ForbiddenError(
215
+ headers=dict(_response.headers),
216
+ body=typing.cast(
217
+ Error,
218
+ parse_obj_as(
219
+ type_=Error, # type: ignore
220
+ object_=_response.json(),
221
+ ),
222
+ ),
223
+ )
224
+ _response_json = _response.json()
225
+ except JSONDecodeError:
226
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
227
+ except ValidationError as e:
228
+ raise ParsingError(
229
+ status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
230
+ )
231
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
232
+
233
+ async def create_binding(
234
+ self,
235
+ base_id: str,
236
+ *,
237
+ auth: BindingAuthInput,
238
+ plugin_id: str,
239
+ config: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
240
+ enabled: typing.Optional[bool] = OMIT,
241
+ models: typing.Optional[BindingModels] = OMIT,
242
+ request_options: typing.Optional[RequestOptions] = None,
243
+ ) -> AsyncHttpResponse[Binding]:
244
+ """
245
+ Parameters
246
+ ----------
247
+ base_id : str
248
+
249
+ auth : BindingAuthInput
250
+
251
+ plugin_id : str
252
+
253
+ config : typing.Optional[typing.Dict[str, typing.Any]]
254
+
255
+ enabled : typing.Optional[bool]
256
+
257
+ models : typing.Optional[BindingModels]
258
+
259
+ request_options : typing.Optional[RequestOptions]
260
+ Request-specific configuration.
261
+
262
+ Returns
263
+ -------
264
+ AsyncHttpResponse[Binding]
265
+ The created binding.
266
+ """
267
+ _response = await self._client_wrapper.httpx_client.request(
268
+ f"base/bases/{encode_path_param(base_id)}/bindings",
269
+ method="POST",
270
+ json={
271
+ "auth": convert_and_respect_annotation_metadata(
272
+ object_=auth, annotation=BindingAuthInput, direction="write"
273
+ ),
274
+ "config": config,
275
+ "enabled": enabled,
276
+ "models": convert_and_respect_annotation_metadata(
277
+ object_=models, annotation=typing.Optional[BindingModels], direction="write"
278
+ ),
279
+ "plugin_id": plugin_id,
280
+ },
281
+ headers={
282
+ "content-type": "application/json",
283
+ },
284
+ request_options=request_options,
285
+ omit=OMIT,
286
+ )
287
+ try:
288
+ if 200 <= _response.status_code < 300:
289
+ _data = typing.cast(
290
+ Binding,
291
+ parse_obj_as(
292
+ type_=Binding, # type: ignore
293
+ object_=_response.json(),
294
+ ),
295
+ )
296
+ return AsyncHttpResponse(response=_response, data=_data)
297
+ if _response.status_code == 400:
298
+ raise BadRequestError(
299
+ headers=dict(_response.headers),
300
+ body=typing.cast(
301
+ Error,
302
+ parse_obj_as(
303
+ type_=Error, # type: ignore
304
+ object_=_response.json(),
305
+ ),
306
+ ),
307
+ )
308
+ if _response.status_code == 403:
309
+ raise ForbiddenError(
310
+ headers=dict(_response.headers),
311
+ body=typing.cast(
312
+ Error,
313
+ parse_obj_as(
314
+ type_=Error, # type: ignore
315
+ object_=_response.json(),
316
+ ),
317
+ ),
318
+ )
319
+ _response_json = _response.json()
320
+ except JSONDecodeError:
321
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
322
+ except ValidationError as e:
323
+ raise ParsingError(
324
+ status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
325
+ )
326
+ raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
@@ -0,0 +1,34 @@
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 .list_bindings_response import ListBindingsResponse
10
+ _dynamic_imports: typing.Dict[str, str] = {"ListBindingsResponse": ".list_bindings_response"}
11
+
12
+
13
+ def __getattr__(attr_name: str) -> typing.Any:
14
+ module_name = _dynamic_imports.get(attr_name)
15
+ if module_name is None:
16
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
17
+ try:
18
+ module = import_module(module_name, __package__)
19
+ if module_name == f".{attr_name}":
20
+ return module
21
+ else:
22
+ return getattr(module, attr_name)
23
+ except ImportError as e:
24
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
25
+ except AttributeError as e:
26
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
27
+
28
+
29
+ def __dir__():
30
+ lazy_attrs = list(_dynamic_imports.keys())
31
+ return sorted(lazy_attrs)
32
+
33
+
34
+ __all__ = ["ListBindingsResponse"]
@@ -0,0 +1,20 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import pydantic
6
+ from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
7
+ from ...types.binding import Binding
8
+
9
+
10
+ class ListBindingsResponse(UniversalBaseModel):
11
+ bindings: typing.List[Binding]
12
+
13
+ if IS_PYDANTIC_V2:
14
+ model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
15
+ else:
16
+
17
+ class Config:
18
+ frozen = True
19
+ smart_union = True
20
+ extra = pydantic.Extra.allow
base_client/client.py ADDED
@@ -0,0 +1,252 @@
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
+
11
+ if typing.TYPE_CHECKING:
12
+ from .bases.client import AsyncBasesClient, BasesClient
13
+ from .binding_plan.client import AsyncBindingPlanClient, BindingPlanClient
14
+ from .bindings.client import AsyncBindingsClient, BindingsClient
15
+ from .dsn.client import AsyncDsnClient, DsnClient
16
+ from .sync_state.client import AsyncSyncStateClient, SyncStateClient
17
+
18
+
19
+ class BaseAPIClient:
20
+ """
21
+ 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.
22
+
23
+ Parameters
24
+ ----------
25
+ base_url : str
26
+ The base url to use for requests from the client.
27
+
28
+ headers : typing.Optional[typing.Dict[str, str]]
29
+ Additional headers to send with every request.
30
+
31
+ timeout : typing.Optional[float]
32
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
33
+
34
+ max_retries : typing.Optional[int]
35
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
36
+
37
+ follow_redirects : typing.Optional[bool]
38
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
39
+
40
+ httpx_client : typing.Optional[httpx.Client]
41
+ 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.
42
+
43
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
44
+ 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.
45
+
46
+ Examples
47
+ --------
48
+ from base_client import BaseAPIClient
49
+
50
+ client = BaseAPIClient(
51
+ base_url="https://yourhost.com/path/to/api",
52
+ )
53
+ """
54
+
55
+ def __init__(
56
+ self,
57
+ *,
58
+ base_url: str,
59
+ headers: typing.Optional[typing.Dict[str, str]] = None,
60
+ timeout: typing.Optional[float] = None,
61
+ max_retries: typing.Optional[int] = None,
62
+ follow_redirects: typing.Optional[bool] = True,
63
+ httpx_client: typing.Optional[httpx.Client] = None,
64
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
65
+ ):
66
+ _defaulted_timeout = (
67
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
68
+ )
69
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
70
+ self._client_wrapper = SyncClientWrapper(
71
+ base_url=base_url,
72
+ headers=headers,
73
+ httpx_client=httpx_client
74
+ if httpx_client is not None
75
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
76
+ if follow_redirects is not None
77
+ else httpx.Client(timeout=_defaulted_timeout),
78
+ timeout=_defaulted_timeout,
79
+ max_retries=_defaulted_max_retries,
80
+ logging=logging,
81
+ )
82
+ self._bases: typing.Optional[BasesClient] = None
83
+ self._binding_plan: typing.Optional[BindingPlanClient] = None
84
+ self._bindings: typing.Optional[BindingsClient] = None
85
+ self._dsn: typing.Optional[DsnClient] = None
86
+ self._sync_state: typing.Optional[SyncStateClient] = None
87
+
88
+ @property
89
+ def bases(self):
90
+ if self._bases is None:
91
+ from .bases.client import BasesClient # noqa: E402
92
+
93
+ self._bases = BasesClient(client_wrapper=self._client_wrapper)
94
+ return self._bases
95
+
96
+ @property
97
+ def binding_plan(self):
98
+ if self._binding_plan is None:
99
+ from .binding_plan.client import BindingPlanClient # noqa: E402
100
+
101
+ self._binding_plan = BindingPlanClient(client_wrapper=self._client_wrapper)
102
+ return self._binding_plan
103
+
104
+ @property
105
+ def bindings(self):
106
+ if self._bindings is None:
107
+ from .bindings.client import BindingsClient # noqa: E402
108
+
109
+ self._bindings = BindingsClient(client_wrapper=self._client_wrapper)
110
+ return self._bindings
111
+
112
+ @property
113
+ def dsn(self):
114
+ if self._dsn is None:
115
+ from .dsn.client import DsnClient # noqa: E402
116
+
117
+ self._dsn = DsnClient(client_wrapper=self._client_wrapper)
118
+ return self._dsn
119
+
120
+ @property
121
+ def sync_state(self):
122
+ if self._sync_state is None:
123
+ from .sync_state.client import SyncStateClient # noqa: E402
124
+
125
+ self._sync_state = SyncStateClient(client_wrapper=self._client_wrapper)
126
+ return self._sync_state
127
+
128
+
129
+ def _make_default_async_client(
130
+ timeout: typing.Optional[float],
131
+ follow_redirects: typing.Optional[bool],
132
+ ) -> httpx.AsyncClient:
133
+ try:
134
+ import httpx_aiohttp # type: ignore[import-not-found]
135
+ except ImportError:
136
+ pass
137
+ else:
138
+ if follow_redirects is not None:
139
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
140
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)
141
+
142
+ if follow_redirects is not None:
143
+ return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
144
+ return httpx.AsyncClient(timeout=timeout)
145
+
146
+
147
+ class AsyncBaseAPIClient:
148
+ """
149
+ 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.
150
+
151
+ Parameters
152
+ ----------
153
+ base_url : str
154
+ The base url to use for requests from the client.
155
+
156
+ headers : typing.Optional[typing.Dict[str, str]]
157
+ Additional headers to send with every request.
158
+
159
+ timeout : typing.Optional[float]
160
+ 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.
161
+
162
+ max_retries : typing.Optional[int]
163
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
164
+
165
+ follow_redirects : typing.Optional[bool]
166
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
167
+
168
+ httpx_client : typing.Optional[httpx.AsyncClient]
169
+ 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.
170
+
171
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
172
+ 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.
173
+
174
+ Examples
175
+ --------
176
+ from base_client import AsyncBaseAPIClient
177
+
178
+ client = AsyncBaseAPIClient(
179
+ base_url="https://yourhost.com/path/to/api",
180
+ )
181
+ """
182
+
183
+ def __init__(
184
+ self,
185
+ *,
186
+ base_url: str,
187
+ headers: typing.Optional[typing.Dict[str, str]] = None,
188
+ timeout: typing.Optional[float] = None,
189
+ max_retries: typing.Optional[int] = None,
190
+ follow_redirects: typing.Optional[bool] = True,
191
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
192
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
193
+ ):
194
+ _defaulted_timeout = (
195
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
196
+ )
197
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
198
+ self._client_wrapper = AsyncClientWrapper(
199
+ base_url=base_url,
200
+ headers=headers,
201
+ httpx_client=httpx_client
202
+ if httpx_client is not None
203
+ else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
204
+ timeout=_defaulted_timeout,
205
+ max_retries=_defaulted_max_retries,
206
+ logging=logging,
207
+ )
208
+ self._bases: typing.Optional[AsyncBasesClient] = None
209
+ self._binding_plan: typing.Optional[AsyncBindingPlanClient] = None
210
+ self._bindings: typing.Optional[AsyncBindingsClient] = None
211
+ self._dsn: typing.Optional[AsyncDsnClient] = None
212
+ self._sync_state: typing.Optional[AsyncSyncStateClient] = None
213
+
214
+ @property
215
+ def bases(self):
216
+ if self._bases is None:
217
+ from .bases.client import AsyncBasesClient # noqa: E402
218
+
219
+ self._bases = AsyncBasesClient(client_wrapper=self._client_wrapper)
220
+ return self._bases
221
+
222
+ @property
223
+ def binding_plan(self):
224
+ if self._binding_plan is None:
225
+ from .binding_plan.client import AsyncBindingPlanClient # noqa: E402
226
+
227
+ self._binding_plan = AsyncBindingPlanClient(client_wrapper=self._client_wrapper)
228
+ return self._binding_plan
229
+
230
+ @property
231
+ def bindings(self):
232
+ if self._bindings is None:
233
+ from .bindings.client import AsyncBindingsClient # noqa: E402
234
+
235
+ self._bindings = AsyncBindingsClient(client_wrapper=self._client_wrapper)
236
+ return self._bindings
237
+
238
+ @property
239
+ def dsn(self):
240
+ if self._dsn is None:
241
+ from .dsn.client import AsyncDsnClient # noqa: E402
242
+
243
+ self._dsn = AsyncDsnClient(client_wrapper=self._client_wrapper)
244
+ return self._dsn
245
+
246
+ @property
247
+ def sync_state(self):
248
+ if self._sync_state is None:
249
+ from .sync_state.client import AsyncSyncStateClient # noqa: E402
250
+
251
+ self._sync_state = AsyncSyncStateClient(client_wrapper=self._client_wrapper)
252
+ return self._sync_state