channel3-sdk 1.0.0__py3-none-any.whl → 2.1.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.
Potentially problematic release.
This version of channel3-sdk might be problematic. Click here for more details.
- channel3_sdk/__init__.py +94 -44
- channel3_sdk/_base_client.py +1995 -0
- channel3_sdk/_client.py +549 -0
- channel3_sdk/_compat.py +219 -0
- channel3_sdk/_constants.py +14 -0
- channel3_sdk/_exceptions.py +108 -0
- channel3_sdk/_files.py +123 -0
- channel3_sdk/_models.py +829 -0
- channel3_sdk/_qs.py +150 -0
- channel3_sdk/_resource.py +43 -0
- channel3_sdk/_response.py +832 -0
- channel3_sdk/_streaming.py +333 -0
- channel3_sdk/_types.py +253 -0
- channel3_sdk/_utils/__init__.py +64 -0
- channel3_sdk/_utils/_compat.py +45 -0
- channel3_sdk/_utils/_datetime_parse.py +136 -0
- channel3_sdk/_utils/_logs.py +25 -0
- channel3_sdk/_utils/_proxy.py +65 -0
- channel3_sdk/_utils/_reflection.py +42 -0
- channel3_sdk/_utils/_resources_proxy.py +24 -0
- channel3_sdk/_utils/_streams.py +12 -0
- channel3_sdk/_utils/_sync.py +86 -0
- channel3_sdk/_utils/_transform.py +457 -0
- channel3_sdk/_utils/_typing.py +156 -0
- channel3_sdk/_utils/_utils.py +421 -0
- channel3_sdk/_version.py +4 -0
- channel3_sdk/lib/.keep +4 -0
- channel3_sdk/py.typed +0 -0
- channel3_sdk/resources/__init__.py +61 -0
- channel3_sdk/resources/brands.py +268 -0
- channel3_sdk/resources/enrich.py +167 -0
- channel3_sdk/resources/products.py +163 -0
- channel3_sdk/resources/search.py +227 -0
- channel3_sdk/types/__init__.py +15 -0
- channel3_sdk/types/availability_status.py +9 -0
- channel3_sdk/types/brand.py +17 -0
- channel3_sdk/types/brand_list_params.py +16 -0
- channel3_sdk/types/brand_list_response.py +25 -0
- channel3_sdk/types/enrich_enrich_url_params.py +12 -0
- channel3_sdk/types/enrich_enrich_url_response.py +20 -0
- channel3_sdk/types/price.py +18 -0
- channel3_sdk/types/product_retrieve_response.py +39 -0
- channel3_sdk/types/search_perform_params.py +64 -0
- channel3_sdk/types/search_perform_response.py +36 -0
- channel3_sdk/types/variant.py +13 -0
- channel3_sdk-2.1.0.dist-info/METADATA +414 -0
- channel3_sdk-2.1.0.dist-info/RECORD +49 -0
- {channel3_sdk-1.0.0.dist-info → channel3_sdk-2.1.0.dist-info}/WHEEL +1 -1
- channel3_sdk-2.1.0.dist-info/licenses/LICENSE +201 -0
- channel3_sdk/_gen/.gitignore +0 -23
- channel3_sdk/_gen/README.md +0 -124
- channel3_sdk/_gen/fast_api_client/__init__.py +0 -8
- channel3_sdk/_gen/fast_api_client/api/__init__.py +0 -1
- channel3_sdk/_gen/fast_api_client/api/channel3_api/__init__.py +0 -1
- channel3_sdk/_gen/fast_api_client/api/channel3_api/get_brand_detail_v0_brands_brand_id_get.py +0 -179
- channel3_sdk/_gen/fast_api_client/api/channel3_api/get_brands_v0_brands_get.py +0 -218
- channel3_sdk/_gen/fast_api_client/api/channel3_api/get_product_detail_v0_products_product_id_get.py +0 -179
- channel3_sdk/_gen/fast_api_client/api/channel3_api/search_v0_search_post.py +0 -193
- channel3_sdk/_gen/fast_api_client/api/default/__init__.py +0 -1
- channel3_sdk/_gen/fast_api_client/api/default/root_get.py +0 -79
- channel3_sdk/_gen/fast_api_client/client.py +0 -268
- channel3_sdk/_gen/fast_api_client/errors.py +0 -16
- channel3_sdk/_gen/fast_api_client/models/__init__.py +0 -35
- channel3_sdk/_gen/fast_api_client/models/availability_status.py +0 -15
- channel3_sdk/_gen/fast_api_client/models/brand.py +0 -109
- channel3_sdk/_gen/fast_api_client/models/error_response.py +0 -59
- channel3_sdk/_gen/fast_api_client/models/paginated_response_brand.py +0 -83
- channel3_sdk/_gen/fast_api_client/models/pagination_meta.py +0 -84
- channel3_sdk/_gen/fast_api_client/models/price.py +0 -89
- channel3_sdk/_gen/fast_api_client/models/product.py +0 -166
- channel3_sdk/_gen/fast_api_client/models/product_detail.py +0 -306
- channel3_sdk/_gen/fast_api_client/models/product_detail_gender_type_0.py +0 -10
- channel3_sdk/_gen/fast_api_client/models/search_config.py +0 -69
- channel3_sdk/_gen/fast_api_client/models/search_filter_price.py +0 -92
- channel3_sdk/_gen/fast_api_client/models/search_filters.py +0 -191
- channel3_sdk/_gen/fast_api_client/models/search_filters_gender_type_0.py +0 -10
- channel3_sdk/_gen/fast_api_client/models/search_request.py +0 -191
- channel3_sdk/_gen/fast_api_client/models/variant.py +0 -75
- channel3_sdk/_gen/fast_api_client/py.typed +0 -1
- channel3_sdk/_gen/fast_api_client/types.py +0 -54
- channel3_sdk/_gen/pyproject.toml +0 -26
- channel3_sdk/client.py +0 -361
- channel3_sdk/exceptions.py +0 -48
- channel3_sdk-1.0.0.dist-info/METADATA +0 -341
- channel3_sdk-1.0.0.dist-info/RECORD +0 -38
channel3_sdk/_client.py
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Any, Dict, Union, Mapping, cast
|
|
7
|
+
from typing_extensions import Self, Literal, override
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
from . import _exceptions
|
|
12
|
+
from ._qs import Querystring
|
|
13
|
+
from ._types import (
|
|
14
|
+
NOT_GIVEN,
|
|
15
|
+
Body,
|
|
16
|
+
Omit,
|
|
17
|
+
Query,
|
|
18
|
+
Headers,
|
|
19
|
+
Timeout,
|
|
20
|
+
NotGiven,
|
|
21
|
+
Transport,
|
|
22
|
+
ProxiesTypes,
|
|
23
|
+
RequestOptions,
|
|
24
|
+
)
|
|
25
|
+
from ._utils import is_given, get_async_library
|
|
26
|
+
from ._version import __version__
|
|
27
|
+
from ._response import (
|
|
28
|
+
to_raw_response_wrapper,
|
|
29
|
+
to_streamed_response_wrapper,
|
|
30
|
+
async_to_raw_response_wrapper,
|
|
31
|
+
async_to_streamed_response_wrapper,
|
|
32
|
+
)
|
|
33
|
+
from .resources import brands, enrich, search, products
|
|
34
|
+
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
|
|
35
|
+
from ._exceptions import Channel3Error, APIStatusError
|
|
36
|
+
from ._base_client import (
|
|
37
|
+
DEFAULT_MAX_RETRIES,
|
|
38
|
+
SyncAPIClient,
|
|
39
|
+
AsyncAPIClient,
|
|
40
|
+
make_request_options,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
"ENVIRONMENTS",
|
|
45
|
+
"Timeout",
|
|
46
|
+
"Transport",
|
|
47
|
+
"ProxiesTypes",
|
|
48
|
+
"RequestOptions",
|
|
49
|
+
"Channel3",
|
|
50
|
+
"AsyncChannel3",
|
|
51
|
+
"Client",
|
|
52
|
+
"AsyncClient",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
ENVIRONMENTS: Dict[str, str] = {
|
|
56
|
+
"production": "https://api.trychannel3.com",
|
|
57
|
+
"development": "https://localhost:8000",
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class Channel3(SyncAPIClient):
|
|
62
|
+
search: search.SearchResource
|
|
63
|
+
products: products.ProductsResource
|
|
64
|
+
brands: brands.BrandsResource
|
|
65
|
+
enrich: enrich.EnrichResource
|
|
66
|
+
with_raw_response: Channel3WithRawResponse
|
|
67
|
+
with_streaming_response: Channel3WithStreamedResponse
|
|
68
|
+
|
|
69
|
+
# client options
|
|
70
|
+
api_key: str
|
|
71
|
+
|
|
72
|
+
_environment: Literal["production", "development"] | NotGiven
|
|
73
|
+
|
|
74
|
+
def __init__(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
api_key: str | None = None,
|
|
78
|
+
environment: Literal["production", "development"] | NotGiven = NOT_GIVEN,
|
|
79
|
+
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
|
|
80
|
+
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
|
81
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
82
|
+
default_headers: Mapping[str, str] | None = None,
|
|
83
|
+
default_query: Mapping[str, object] | None = None,
|
|
84
|
+
# Configure a custom httpx client.
|
|
85
|
+
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
|
|
86
|
+
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
|
87
|
+
http_client: httpx.Client | None = None,
|
|
88
|
+
# Enable or disable schema validation for data returned by the API.
|
|
89
|
+
# When enabled an error APIResponseValidationError is raised
|
|
90
|
+
# if the API responds with invalid data for the expected schema.
|
|
91
|
+
#
|
|
92
|
+
# This parameter may be removed or changed in the future.
|
|
93
|
+
# If you rely on this feature, please open a GitHub issue
|
|
94
|
+
# outlining your use-case to help us decide if it should be
|
|
95
|
+
# part of our public interface in the future.
|
|
96
|
+
_strict_response_validation: bool = False,
|
|
97
|
+
) -> None:
|
|
98
|
+
"""Construct a new synchronous Channel3 client instance.
|
|
99
|
+
|
|
100
|
+
This automatically infers the `api_key` argument from the `CHANNEL3_API_KEY` environment variable if it is not provided.
|
|
101
|
+
"""
|
|
102
|
+
if api_key is None:
|
|
103
|
+
api_key = os.environ.get("CHANNEL3_API_KEY")
|
|
104
|
+
if api_key is None:
|
|
105
|
+
raise Channel3Error(
|
|
106
|
+
"The api_key client option must be set either by passing api_key to the client or by setting the CHANNEL3_API_KEY environment variable"
|
|
107
|
+
)
|
|
108
|
+
self.api_key = api_key
|
|
109
|
+
|
|
110
|
+
self._environment = environment
|
|
111
|
+
|
|
112
|
+
base_url_env = os.environ.get("CHANNEL3_BASE_URL")
|
|
113
|
+
if is_given(base_url) and base_url is not None:
|
|
114
|
+
# cast required because mypy doesn't understand the type narrowing
|
|
115
|
+
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
|
|
116
|
+
elif is_given(environment):
|
|
117
|
+
if base_url_env and base_url is not None:
|
|
118
|
+
raise ValueError(
|
|
119
|
+
"Ambiguous URL; The `CHANNEL3_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
try:
|
|
123
|
+
base_url = ENVIRONMENTS[environment]
|
|
124
|
+
except KeyError as exc:
|
|
125
|
+
raise ValueError(f"Unknown environment: {environment}") from exc
|
|
126
|
+
elif base_url_env is not None:
|
|
127
|
+
base_url = base_url_env
|
|
128
|
+
else:
|
|
129
|
+
self._environment = environment = "production"
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
base_url = ENVIRONMENTS[environment]
|
|
133
|
+
except KeyError as exc:
|
|
134
|
+
raise ValueError(f"Unknown environment: {environment}") from exc
|
|
135
|
+
|
|
136
|
+
super().__init__(
|
|
137
|
+
version=__version__,
|
|
138
|
+
base_url=base_url,
|
|
139
|
+
max_retries=max_retries,
|
|
140
|
+
timeout=timeout,
|
|
141
|
+
http_client=http_client,
|
|
142
|
+
custom_headers=default_headers,
|
|
143
|
+
custom_query=default_query,
|
|
144
|
+
_strict_response_validation=_strict_response_validation,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
self.search = search.SearchResource(self)
|
|
148
|
+
self.products = products.ProductsResource(self)
|
|
149
|
+
self.brands = brands.BrandsResource(self)
|
|
150
|
+
self.enrich = enrich.EnrichResource(self)
|
|
151
|
+
self.with_raw_response = Channel3WithRawResponse(self)
|
|
152
|
+
self.with_streaming_response = Channel3WithStreamedResponse(self)
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
@override
|
|
156
|
+
def qs(self) -> Querystring:
|
|
157
|
+
return Querystring(array_format="comma")
|
|
158
|
+
|
|
159
|
+
@property
|
|
160
|
+
@override
|
|
161
|
+
def auth_headers(self) -> dict[str, str]:
|
|
162
|
+
api_key = self.api_key
|
|
163
|
+
return {"x-api-key": api_key}
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
@override
|
|
167
|
+
def default_headers(self) -> dict[str, str | Omit]:
|
|
168
|
+
return {
|
|
169
|
+
**super().default_headers,
|
|
170
|
+
"X-Stainless-Async": "false",
|
|
171
|
+
**self._custom_headers,
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
def copy(
|
|
175
|
+
self,
|
|
176
|
+
*,
|
|
177
|
+
api_key: str | None = None,
|
|
178
|
+
environment: Literal["production", "development"] | None = None,
|
|
179
|
+
base_url: str | httpx.URL | None = None,
|
|
180
|
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
|
181
|
+
http_client: httpx.Client | None = None,
|
|
182
|
+
max_retries: int | NotGiven = NOT_GIVEN,
|
|
183
|
+
default_headers: Mapping[str, str] | None = None,
|
|
184
|
+
set_default_headers: Mapping[str, str] | None = None,
|
|
185
|
+
default_query: Mapping[str, object] | None = None,
|
|
186
|
+
set_default_query: Mapping[str, object] | None = None,
|
|
187
|
+
_extra_kwargs: Mapping[str, Any] = {},
|
|
188
|
+
) -> Self:
|
|
189
|
+
"""
|
|
190
|
+
Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
191
|
+
"""
|
|
192
|
+
if default_headers is not None and set_default_headers is not None:
|
|
193
|
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
|
194
|
+
|
|
195
|
+
if default_query is not None and set_default_query is not None:
|
|
196
|
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
|
197
|
+
|
|
198
|
+
headers = self._custom_headers
|
|
199
|
+
if default_headers is not None:
|
|
200
|
+
headers = {**headers, **default_headers}
|
|
201
|
+
elif set_default_headers is not None:
|
|
202
|
+
headers = set_default_headers
|
|
203
|
+
|
|
204
|
+
params = self._custom_query
|
|
205
|
+
if default_query is not None:
|
|
206
|
+
params = {**params, **default_query}
|
|
207
|
+
elif set_default_query is not None:
|
|
208
|
+
params = set_default_query
|
|
209
|
+
|
|
210
|
+
http_client = http_client or self._client
|
|
211
|
+
return self.__class__(
|
|
212
|
+
api_key=api_key or self.api_key,
|
|
213
|
+
base_url=base_url or self.base_url,
|
|
214
|
+
environment=environment or self._environment,
|
|
215
|
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
|
216
|
+
http_client=http_client,
|
|
217
|
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
|
218
|
+
default_headers=headers,
|
|
219
|
+
default_query=params,
|
|
220
|
+
**_extra_kwargs,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
# Alias for `copy` for nicer inline usage, e.g.
|
|
224
|
+
# client.with_options(timeout=10).foo.create(...)
|
|
225
|
+
with_options = copy
|
|
226
|
+
|
|
227
|
+
def retrieve(
|
|
228
|
+
self,
|
|
229
|
+
*,
|
|
230
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
231
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
232
|
+
extra_headers: Headers | None = None,
|
|
233
|
+
extra_query: Query | None = None,
|
|
234
|
+
extra_body: Body | None = None,
|
|
235
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
236
|
+
) -> object:
|
|
237
|
+
"""Root"""
|
|
238
|
+
return self.get(
|
|
239
|
+
"/",
|
|
240
|
+
options=make_request_options(
|
|
241
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
242
|
+
),
|
|
243
|
+
cast_to=object,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
@override
|
|
247
|
+
def _make_status_error(
|
|
248
|
+
self,
|
|
249
|
+
err_msg: str,
|
|
250
|
+
*,
|
|
251
|
+
body: object,
|
|
252
|
+
response: httpx.Response,
|
|
253
|
+
) -> APIStatusError:
|
|
254
|
+
if response.status_code == 400:
|
|
255
|
+
return _exceptions.BadRequestError(err_msg, response=response, body=body)
|
|
256
|
+
|
|
257
|
+
if response.status_code == 401:
|
|
258
|
+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
|
|
259
|
+
|
|
260
|
+
if response.status_code == 403:
|
|
261
|
+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
|
|
262
|
+
|
|
263
|
+
if response.status_code == 404:
|
|
264
|
+
return _exceptions.NotFoundError(err_msg, response=response, body=body)
|
|
265
|
+
|
|
266
|
+
if response.status_code == 409:
|
|
267
|
+
return _exceptions.ConflictError(err_msg, response=response, body=body)
|
|
268
|
+
|
|
269
|
+
if response.status_code == 422:
|
|
270
|
+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
|
|
271
|
+
|
|
272
|
+
if response.status_code == 429:
|
|
273
|
+
return _exceptions.RateLimitError(err_msg, response=response, body=body)
|
|
274
|
+
|
|
275
|
+
if response.status_code >= 500:
|
|
276
|
+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
|
|
277
|
+
return APIStatusError(err_msg, response=response, body=body)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
class AsyncChannel3(AsyncAPIClient):
|
|
281
|
+
search: search.AsyncSearchResource
|
|
282
|
+
products: products.AsyncProductsResource
|
|
283
|
+
brands: brands.AsyncBrandsResource
|
|
284
|
+
enrich: enrich.AsyncEnrichResource
|
|
285
|
+
with_raw_response: AsyncChannel3WithRawResponse
|
|
286
|
+
with_streaming_response: AsyncChannel3WithStreamedResponse
|
|
287
|
+
|
|
288
|
+
# client options
|
|
289
|
+
api_key: str
|
|
290
|
+
|
|
291
|
+
_environment: Literal["production", "development"] | NotGiven
|
|
292
|
+
|
|
293
|
+
def __init__(
|
|
294
|
+
self,
|
|
295
|
+
*,
|
|
296
|
+
api_key: str | None = None,
|
|
297
|
+
environment: Literal["production", "development"] | NotGiven = NOT_GIVEN,
|
|
298
|
+
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
|
|
299
|
+
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
|
300
|
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
301
|
+
default_headers: Mapping[str, str] | None = None,
|
|
302
|
+
default_query: Mapping[str, object] | None = None,
|
|
303
|
+
# Configure a custom httpx client.
|
|
304
|
+
# We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
|
|
305
|
+
# See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
|
|
306
|
+
http_client: httpx.AsyncClient | None = None,
|
|
307
|
+
# Enable or disable schema validation for data returned by the API.
|
|
308
|
+
# When enabled an error APIResponseValidationError is raised
|
|
309
|
+
# if the API responds with invalid data for the expected schema.
|
|
310
|
+
#
|
|
311
|
+
# This parameter may be removed or changed in the future.
|
|
312
|
+
# If you rely on this feature, please open a GitHub issue
|
|
313
|
+
# outlining your use-case to help us decide if it should be
|
|
314
|
+
# part of our public interface in the future.
|
|
315
|
+
_strict_response_validation: bool = False,
|
|
316
|
+
) -> None:
|
|
317
|
+
"""Construct a new async AsyncChannel3 client instance.
|
|
318
|
+
|
|
319
|
+
This automatically infers the `api_key` argument from the `CHANNEL3_API_KEY` environment variable if it is not provided.
|
|
320
|
+
"""
|
|
321
|
+
if api_key is None:
|
|
322
|
+
api_key = os.environ.get("CHANNEL3_API_KEY")
|
|
323
|
+
if api_key is None:
|
|
324
|
+
raise Channel3Error(
|
|
325
|
+
"The api_key client option must be set either by passing api_key to the client or by setting the CHANNEL3_API_KEY environment variable"
|
|
326
|
+
)
|
|
327
|
+
self.api_key = api_key
|
|
328
|
+
|
|
329
|
+
self._environment = environment
|
|
330
|
+
|
|
331
|
+
base_url_env = os.environ.get("CHANNEL3_BASE_URL")
|
|
332
|
+
if is_given(base_url) and base_url is not None:
|
|
333
|
+
# cast required because mypy doesn't understand the type narrowing
|
|
334
|
+
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
|
|
335
|
+
elif is_given(environment):
|
|
336
|
+
if base_url_env and base_url is not None:
|
|
337
|
+
raise ValueError(
|
|
338
|
+
"Ambiguous URL; The `CHANNEL3_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
try:
|
|
342
|
+
base_url = ENVIRONMENTS[environment]
|
|
343
|
+
except KeyError as exc:
|
|
344
|
+
raise ValueError(f"Unknown environment: {environment}") from exc
|
|
345
|
+
elif base_url_env is not None:
|
|
346
|
+
base_url = base_url_env
|
|
347
|
+
else:
|
|
348
|
+
self._environment = environment = "production"
|
|
349
|
+
|
|
350
|
+
try:
|
|
351
|
+
base_url = ENVIRONMENTS[environment]
|
|
352
|
+
except KeyError as exc:
|
|
353
|
+
raise ValueError(f"Unknown environment: {environment}") from exc
|
|
354
|
+
|
|
355
|
+
super().__init__(
|
|
356
|
+
version=__version__,
|
|
357
|
+
base_url=base_url,
|
|
358
|
+
max_retries=max_retries,
|
|
359
|
+
timeout=timeout,
|
|
360
|
+
http_client=http_client,
|
|
361
|
+
custom_headers=default_headers,
|
|
362
|
+
custom_query=default_query,
|
|
363
|
+
_strict_response_validation=_strict_response_validation,
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
self.search = search.AsyncSearchResource(self)
|
|
367
|
+
self.products = products.AsyncProductsResource(self)
|
|
368
|
+
self.brands = brands.AsyncBrandsResource(self)
|
|
369
|
+
self.enrich = enrich.AsyncEnrichResource(self)
|
|
370
|
+
self.with_raw_response = AsyncChannel3WithRawResponse(self)
|
|
371
|
+
self.with_streaming_response = AsyncChannel3WithStreamedResponse(self)
|
|
372
|
+
|
|
373
|
+
@property
|
|
374
|
+
@override
|
|
375
|
+
def qs(self) -> Querystring:
|
|
376
|
+
return Querystring(array_format="comma")
|
|
377
|
+
|
|
378
|
+
@property
|
|
379
|
+
@override
|
|
380
|
+
def auth_headers(self) -> dict[str, str]:
|
|
381
|
+
api_key = self.api_key
|
|
382
|
+
return {"x-api-key": api_key}
|
|
383
|
+
|
|
384
|
+
@property
|
|
385
|
+
@override
|
|
386
|
+
def default_headers(self) -> dict[str, str | Omit]:
|
|
387
|
+
return {
|
|
388
|
+
**super().default_headers,
|
|
389
|
+
"X-Stainless-Async": f"async:{get_async_library()}",
|
|
390
|
+
**self._custom_headers,
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
def copy(
|
|
394
|
+
self,
|
|
395
|
+
*,
|
|
396
|
+
api_key: str | None = None,
|
|
397
|
+
environment: Literal["production", "development"] | None = None,
|
|
398
|
+
base_url: str | httpx.URL | None = None,
|
|
399
|
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
|
400
|
+
http_client: httpx.AsyncClient | None = None,
|
|
401
|
+
max_retries: int | NotGiven = NOT_GIVEN,
|
|
402
|
+
default_headers: Mapping[str, str] | None = None,
|
|
403
|
+
set_default_headers: Mapping[str, str] | None = None,
|
|
404
|
+
default_query: Mapping[str, object] | None = None,
|
|
405
|
+
set_default_query: Mapping[str, object] | None = None,
|
|
406
|
+
_extra_kwargs: Mapping[str, Any] = {},
|
|
407
|
+
) -> Self:
|
|
408
|
+
"""
|
|
409
|
+
Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
410
|
+
"""
|
|
411
|
+
if default_headers is not None and set_default_headers is not None:
|
|
412
|
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
|
413
|
+
|
|
414
|
+
if default_query is not None and set_default_query is not None:
|
|
415
|
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
|
416
|
+
|
|
417
|
+
headers = self._custom_headers
|
|
418
|
+
if default_headers is not None:
|
|
419
|
+
headers = {**headers, **default_headers}
|
|
420
|
+
elif set_default_headers is not None:
|
|
421
|
+
headers = set_default_headers
|
|
422
|
+
|
|
423
|
+
params = self._custom_query
|
|
424
|
+
if default_query is not None:
|
|
425
|
+
params = {**params, **default_query}
|
|
426
|
+
elif set_default_query is not None:
|
|
427
|
+
params = set_default_query
|
|
428
|
+
|
|
429
|
+
http_client = http_client or self._client
|
|
430
|
+
return self.__class__(
|
|
431
|
+
api_key=api_key or self.api_key,
|
|
432
|
+
base_url=base_url or self.base_url,
|
|
433
|
+
environment=environment or self._environment,
|
|
434
|
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
|
435
|
+
http_client=http_client,
|
|
436
|
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
|
437
|
+
default_headers=headers,
|
|
438
|
+
default_query=params,
|
|
439
|
+
**_extra_kwargs,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
# Alias for `copy` for nicer inline usage, e.g.
|
|
443
|
+
# client.with_options(timeout=10).foo.create(...)
|
|
444
|
+
with_options = copy
|
|
445
|
+
|
|
446
|
+
async def retrieve(
|
|
447
|
+
self,
|
|
448
|
+
*,
|
|
449
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
450
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
451
|
+
extra_headers: Headers | None = None,
|
|
452
|
+
extra_query: Query | None = None,
|
|
453
|
+
extra_body: Body | None = None,
|
|
454
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
455
|
+
) -> object:
|
|
456
|
+
"""Root"""
|
|
457
|
+
return await self.get(
|
|
458
|
+
"/",
|
|
459
|
+
options=make_request_options(
|
|
460
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
461
|
+
),
|
|
462
|
+
cast_to=object,
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
@override
|
|
466
|
+
def _make_status_error(
|
|
467
|
+
self,
|
|
468
|
+
err_msg: str,
|
|
469
|
+
*,
|
|
470
|
+
body: object,
|
|
471
|
+
response: httpx.Response,
|
|
472
|
+
) -> APIStatusError:
|
|
473
|
+
if response.status_code == 400:
|
|
474
|
+
return _exceptions.BadRequestError(err_msg, response=response, body=body)
|
|
475
|
+
|
|
476
|
+
if response.status_code == 401:
|
|
477
|
+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
|
|
478
|
+
|
|
479
|
+
if response.status_code == 403:
|
|
480
|
+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
|
|
481
|
+
|
|
482
|
+
if response.status_code == 404:
|
|
483
|
+
return _exceptions.NotFoundError(err_msg, response=response, body=body)
|
|
484
|
+
|
|
485
|
+
if response.status_code == 409:
|
|
486
|
+
return _exceptions.ConflictError(err_msg, response=response, body=body)
|
|
487
|
+
|
|
488
|
+
if response.status_code == 422:
|
|
489
|
+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
|
|
490
|
+
|
|
491
|
+
if response.status_code == 429:
|
|
492
|
+
return _exceptions.RateLimitError(err_msg, response=response, body=body)
|
|
493
|
+
|
|
494
|
+
if response.status_code >= 500:
|
|
495
|
+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
|
|
496
|
+
return APIStatusError(err_msg, response=response, body=body)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
class Channel3WithRawResponse:
|
|
500
|
+
def __init__(self, client: Channel3) -> None:
|
|
501
|
+
self.search = search.SearchResourceWithRawResponse(client.search)
|
|
502
|
+
self.products = products.ProductsResourceWithRawResponse(client.products)
|
|
503
|
+
self.brands = brands.BrandsResourceWithRawResponse(client.brands)
|
|
504
|
+
self.enrich = enrich.EnrichResourceWithRawResponse(client.enrich)
|
|
505
|
+
|
|
506
|
+
self.retrieve = to_raw_response_wrapper(
|
|
507
|
+
client.retrieve,
|
|
508
|
+
)
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
class AsyncChannel3WithRawResponse:
|
|
512
|
+
def __init__(self, client: AsyncChannel3) -> None:
|
|
513
|
+
self.search = search.AsyncSearchResourceWithRawResponse(client.search)
|
|
514
|
+
self.products = products.AsyncProductsResourceWithRawResponse(client.products)
|
|
515
|
+
self.brands = brands.AsyncBrandsResourceWithRawResponse(client.brands)
|
|
516
|
+
self.enrich = enrich.AsyncEnrichResourceWithRawResponse(client.enrich)
|
|
517
|
+
|
|
518
|
+
self.retrieve = async_to_raw_response_wrapper(
|
|
519
|
+
client.retrieve,
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
class Channel3WithStreamedResponse:
|
|
524
|
+
def __init__(self, client: Channel3) -> None:
|
|
525
|
+
self.search = search.SearchResourceWithStreamingResponse(client.search)
|
|
526
|
+
self.products = products.ProductsResourceWithStreamingResponse(client.products)
|
|
527
|
+
self.brands = brands.BrandsResourceWithStreamingResponse(client.brands)
|
|
528
|
+
self.enrich = enrich.EnrichResourceWithStreamingResponse(client.enrich)
|
|
529
|
+
|
|
530
|
+
self.retrieve = to_streamed_response_wrapper(
|
|
531
|
+
client.retrieve,
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
class AsyncChannel3WithStreamedResponse:
|
|
536
|
+
def __init__(self, client: AsyncChannel3) -> None:
|
|
537
|
+
self.search = search.AsyncSearchResourceWithStreamingResponse(client.search)
|
|
538
|
+
self.products = products.AsyncProductsResourceWithStreamingResponse(client.products)
|
|
539
|
+
self.brands = brands.AsyncBrandsResourceWithStreamingResponse(client.brands)
|
|
540
|
+
self.enrich = enrich.AsyncEnrichResourceWithStreamingResponse(client.enrich)
|
|
541
|
+
|
|
542
|
+
self.retrieve = async_to_streamed_response_wrapper(
|
|
543
|
+
client.retrieve,
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
Client = Channel3
|
|
548
|
+
|
|
549
|
+
AsyncClient = AsyncChannel3
|