usdk 1.0.1__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.
uapi/_client.py ADDED
@@ -0,0 +1,579 @@
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, Mapping
7
+ from typing_extensions import Self, override
8
+
9
+ import httpx
10
+
11
+ from . import _exceptions
12
+ from ._qs import Querystring
13
+ from .types import client_search_params, client_extract_params
14
+ from ._types import (
15
+ Body,
16
+ Omit,
17
+ Query,
18
+ Headers,
19
+ Timeout,
20
+ NotGiven,
21
+ Transport,
22
+ ProxiesTypes,
23
+ RequestOptions,
24
+ not_given,
25
+ )
26
+ from ._utils import (
27
+ is_given,
28
+ maybe_transform,
29
+ get_async_library,
30
+ async_maybe_transform,
31
+ )
32
+ from ._version import __version__
33
+ from ._response import (
34
+ to_raw_response_wrapper,
35
+ to_streamed_response_wrapper,
36
+ async_to_raw_response_wrapper,
37
+ async_to_streamed_response_wrapper,
38
+ )
39
+ from ._streaming import Stream as Stream, AsyncStream as AsyncStream
40
+ from ._exceptions import APIStatusError, uAPIError
41
+ from ._base_client import (
42
+ DEFAULT_MAX_RETRIES,
43
+ SyncAPIClient,
44
+ AsyncAPIClient,
45
+ make_request_options,
46
+ )
47
+
48
+ __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "uAPI", "AsyncuAPI", "Client", "AsyncClient"]
49
+
50
+
51
+ class uAPI(SyncAPIClient):
52
+ with_raw_response: uAPIWithRawResponse
53
+ with_streaming_response: uAPIWithStreamedResponse
54
+
55
+ # client options
56
+ api_key: str
57
+ cache_ttl: int | None
58
+
59
+ def __init__(
60
+ self,
61
+ *,
62
+ api_key: str | None = None,
63
+ cache_ttl: int | None = None,
64
+ base_url: str | httpx.URL | None = None,
65
+ timeout: float | Timeout | None | NotGiven = not_given,
66
+ max_retries: int = DEFAULT_MAX_RETRIES,
67
+ default_headers: Mapping[str, str] | None = None,
68
+ default_query: Mapping[str, object] | None = None,
69
+ # Configure a custom httpx client.
70
+ # We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
71
+ # See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
72
+ http_client: httpx.Client | None = None,
73
+ # Enable or disable schema validation for data returned by the API.
74
+ # When enabled an error APIResponseValidationError is raised
75
+ # if the API responds with invalid data for the expected schema.
76
+ #
77
+ # This parameter may be removed or changed in the future.
78
+ # If you rely on this feature, please open a GitHub issue
79
+ # outlining your use-case to help us decide if it should be
80
+ # part of our public interface in the future.
81
+ _strict_response_validation: bool = False,
82
+ ) -> None:
83
+ """Construct a new synchronous uAPI client instance.
84
+
85
+ This automatically infers the `api_key` argument from the `UAPI_API_KEY` environment variable if it is not provided.
86
+ """
87
+ if api_key is None:
88
+ api_key = os.environ.get("UAPI_API_KEY")
89
+ if api_key is None:
90
+ raise uAPIError(
91
+ "The api_key client option must be set either by passing api_key to the client or by setting the UAPI_API_KEY environment variable"
92
+ )
93
+ self.api_key = api_key
94
+
95
+ self.cache_ttl = cache_ttl
96
+
97
+ if base_url is None:
98
+ base_url = os.environ.get("UAPI_BASE_URL")
99
+ if base_url is None:
100
+ base_url = f"https://api.uapi.nl"
101
+
102
+ super().__init__(
103
+ version=__version__,
104
+ base_url=base_url,
105
+ max_retries=max_retries,
106
+ timeout=timeout,
107
+ http_client=http_client,
108
+ custom_headers=default_headers,
109
+ custom_query=default_query,
110
+ _strict_response_validation=_strict_response_validation,
111
+ )
112
+
113
+ self.with_raw_response = uAPIWithRawResponse(self)
114
+ self.with_streaming_response = uAPIWithStreamedResponse(self)
115
+
116
+ @property
117
+ @override
118
+ def qs(self) -> Querystring:
119
+ return Querystring(array_format="comma")
120
+
121
+ @property
122
+ @override
123
+ def auth_headers(self) -> dict[str, str]:
124
+ api_key = self.api_key
125
+ return {"X-API-Key": api_key}
126
+
127
+ @property
128
+ @override
129
+ def default_headers(self) -> dict[str, str | Omit]:
130
+ return {
131
+ **super().default_headers,
132
+ "X-Stainless-Async": "false",
133
+ "x-cache-ttl": str(self.cache_ttl) if self.cache_ttl is not None else Omit(),
134
+ **self._custom_headers,
135
+ }
136
+
137
+ def copy(
138
+ self,
139
+ *,
140
+ api_key: str | None = None,
141
+ cache_ttl: int | None = None,
142
+ base_url: str | httpx.URL | None = None,
143
+ timeout: float | Timeout | None | NotGiven = not_given,
144
+ http_client: httpx.Client | None = None,
145
+ max_retries: int | NotGiven = not_given,
146
+ default_headers: Mapping[str, str] | None = None,
147
+ set_default_headers: Mapping[str, str] | None = None,
148
+ default_query: Mapping[str, object] | None = None,
149
+ set_default_query: Mapping[str, object] | None = None,
150
+ _extra_kwargs: Mapping[str, Any] = {},
151
+ ) -> Self:
152
+ """
153
+ Create a new client instance re-using the same options given to the current client with optional overriding.
154
+ """
155
+ if default_headers is not None and set_default_headers is not None:
156
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
157
+
158
+ if default_query is not None and set_default_query is not None:
159
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
160
+
161
+ headers = self._custom_headers
162
+ if default_headers is not None:
163
+ headers = {**headers, **default_headers}
164
+ elif set_default_headers is not None:
165
+ headers = set_default_headers
166
+
167
+ params = self._custom_query
168
+ if default_query is not None:
169
+ params = {**params, **default_query}
170
+ elif set_default_query is not None:
171
+ params = set_default_query
172
+
173
+ http_client = http_client or self._client
174
+ return self.__class__(
175
+ api_key=api_key or self.api_key,
176
+ cache_ttl=cache_ttl or self.cache_ttl,
177
+ base_url=base_url or self.base_url,
178
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
179
+ http_client=http_client,
180
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
181
+ default_headers=headers,
182
+ default_query=params,
183
+ **_extra_kwargs,
184
+ )
185
+
186
+ # Alias for `copy` for nicer inline usage, e.g.
187
+ # client.with_options(timeout=10).foo.create(...)
188
+ with_options = copy
189
+
190
+ def extract(
191
+ self,
192
+ *,
193
+ url: str,
194
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
195
+ # The extra values given here take precedence over values defined on the client or passed to this method.
196
+ extra_headers: Headers | None = None,
197
+ extra_query: Query | None = None,
198
+ extra_body: Body | None = None,
199
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
200
+ ) -> object:
201
+ """
202
+ Extract Get
203
+
204
+ Args:
205
+ extra_headers: Send extra headers
206
+
207
+ extra_query: Add additional query parameters to the request
208
+
209
+ extra_body: Add additional JSON properties to the request
210
+
211
+ timeout: Override the client-level default timeout for this request, in seconds
212
+ """
213
+ return self.get(
214
+ "/v1/extract",
215
+ options=make_request_options(
216
+ extra_headers=extra_headers,
217
+ extra_query=extra_query,
218
+ extra_body=extra_body,
219
+ timeout=timeout,
220
+ query=maybe_transform({"url": url}, client_extract_params.ClientExtractParams),
221
+ ),
222
+ cast_to=object,
223
+ )
224
+
225
+ def search(
226
+ self,
227
+ *,
228
+ query: str,
229
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
230
+ # The extra values given here take precedence over values defined on the client or passed to this method.
231
+ extra_headers: Headers | None = None,
232
+ extra_query: Query | None = None,
233
+ extra_body: Body | None = None,
234
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
235
+ ) -> object:
236
+ """
237
+ Search Get
238
+
239
+ Args:
240
+ extra_headers: Send extra headers
241
+
242
+ extra_query: Add additional query parameters to the request
243
+
244
+ extra_body: Add additional JSON properties to the request
245
+
246
+ timeout: Override the client-level default timeout for this request, in seconds
247
+ """
248
+ return self.get(
249
+ "/v1/search",
250
+ options=make_request_options(
251
+ extra_headers=extra_headers,
252
+ extra_query=extra_query,
253
+ extra_body=extra_body,
254
+ timeout=timeout,
255
+ query=maybe_transform({"query": query}, client_search_params.ClientSearchParams),
256
+ ),
257
+ cast_to=object,
258
+ )
259
+
260
+ @override
261
+ def _make_status_error(
262
+ self,
263
+ err_msg: str,
264
+ *,
265
+ body: object,
266
+ response: httpx.Response,
267
+ ) -> APIStatusError:
268
+ if response.status_code == 400:
269
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
270
+
271
+ if response.status_code == 401:
272
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
273
+
274
+ if response.status_code == 403:
275
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
276
+
277
+ if response.status_code == 404:
278
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
279
+
280
+ if response.status_code == 409:
281
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
282
+
283
+ if response.status_code == 422:
284
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
285
+
286
+ if response.status_code == 429:
287
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
288
+
289
+ if response.status_code >= 500:
290
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
291
+ return APIStatusError(err_msg, response=response, body=body)
292
+
293
+
294
+ class AsyncuAPI(AsyncAPIClient):
295
+ with_raw_response: AsyncuAPIWithRawResponse
296
+ with_streaming_response: AsyncuAPIWithStreamedResponse
297
+
298
+ # client options
299
+ api_key: str
300
+ cache_ttl: int | None
301
+
302
+ def __init__(
303
+ self,
304
+ *,
305
+ api_key: str | None = None,
306
+ cache_ttl: int | None = None,
307
+ base_url: str | httpx.URL | None = None,
308
+ timeout: float | Timeout | None | NotGiven = not_given,
309
+ max_retries: int = DEFAULT_MAX_RETRIES,
310
+ default_headers: Mapping[str, str] | None = None,
311
+ default_query: Mapping[str, object] | None = None,
312
+ # Configure a custom httpx client.
313
+ # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
314
+ # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
315
+ http_client: httpx.AsyncClient | None = None,
316
+ # Enable or disable schema validation for data returned by the API.
317
+ # When enabled an error APIResponseValidationError is raised
318
+ # if the API responds with invalid data for the expected schema.
319
+ #
320
+ # This parameter may be removed or changed in the future.
321
+ # If you rely on this feature, please open a GitHub issue
322
+ # outlining your use-case to help us decide if it should be
323
+ # part of our public interface in the future.
324
+ _strict_response_validation: bool = False,
325
+ ) -> None:
326
+ """Construct a new async AsyncuAPI client instance.
327
+
328
+ This automatically infers the `api_key` argument from the `UAPI_API_KEY` environment variable if it is not provided.
329
+ """
330
+ if api_key is None:
331
+ api_key = os.environ.get("UAPI_API_KEY")
332
+ if api_key is None:
333
+ raise uAPIError(
334
+ "The api_key client option must be set either by passing api_key to the client or by setting the UAPI_API_KEY environment variable"
335
+ )
336
+ self.api_key = api_key
337
+
338
+ self.cache_ttl = cache_ttl
339
+
340
+ if base_url is None:
341
+ base_url = os.environ.get("UAPI_BASE_URL")
342
+ if base_url is None:
343
+ base_url = f"https://api.uapi.nl"
344
+
345
+ super().__init__(
346
+ version=__version__,
347
+ base_url=base_url,
348
+ max_retries=max_retries,
349
+ timeout=timeout,
350
+ http_client=http_client,
351
+ custom_headers=default_headers,
352
+ custom_query=default_query,
353
+ _strict_response_validation=_strict_response_validation,
354
+ )
355
+
356
+ self.with_raw_response = AsyncuAPIWithRawResponse(self)
357
+ self.with_streaming_response = AsyncuAPIWithStreamedResponse(self)
358
+
359
+ @property
360
+ @override
361
+ def qs(self) -> Querystring:
362
+ return Querystring(array_format="comma")
363
+
364
+ @property
365
+ @override
366
+ def auth_headers(self) -> dict[str, str]:
367
+ api_key = self.api_key
368
+ return {"X-API-Key": api_key}
369
+
370
+ @property
371
+ @override
372
+ def default_headers(self) -> dict[str, str | Omit]:
373
+ return {
374
+ **super().default_headers,
375
+ "X-Stainless-Async": f"async:{get_async_library()}",
376
+ "x-cache-ttl": str(self.cache_ttl) if self.cache_ttl is not None else Omit(),
377
+ **self._custom_headers,
378
+ }
379
+
380
+ def copy(
381
+ self,
382
+ *,
383
+ api_key: str | None = None,
384
+ cache_ttl: int | None = None,
385
+ base_url: str | httpx.URL | None = None,
386
+ timeout: float | Timeout | None | NotGiven = not_given,
387
+ http_client: httpx.AsyncClient | None = None,
388
+ max_retries: int | NotGiven = not_given,
389
+ default_headers: Mapping[str, str] | None = None,
390
+ set_default_headers: Mapping[str, str] | None = None,
391
+ default_query: Mapping[str, object] | None = None,
392
+ set_default_query: Mapping[str, object] | None = None,
393
+ _extra_kwargs: Mapping[str, Any] = {},
394
+ ) -> Self:
395
+ """
396
+ Create a new client instance re-using the same options given to the current client with optional overriding.
397
+ """
398
+ if default_headers is not None and set_default_headers is not None:
399
+ raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
400
+
401
+ if default_query is not None and set_default_query is not None:
402
+ raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
403
+
404
+ headers = self._custom_headers
405
+ if default_headers is not None:
406
+ headers = {**headers, **default_headers}
407
+ elif set_default_headers is not None:
408
+ headers = set_default_headers
409
+
410
+ params = self._custom_query
411
+ if default_query is not None:
412
+ params = {**params, **default_query}
413
+ elif set_default_query is not None:
414
+ params = set_default_query
415
+
416
+ http_client = http_client or self._client
417
+ return self.__class__(
418
+ api_key=api_key or self.api_key,
419
+ cache_ttl=cache_ttl or self.cache_ttl,
420
+ base_url=base_url or self.base_url,
421
+ timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
422
+ http_client=http_client,
423
+ max_retries=max_retries if is_given(max_retries) else self.max_retries,
424
+ default_headers=headers,
425
+ default_query=params,
426
+ **_extra_kwargs,
427
+ )
428
+
429
+ # Alias for `copy` for nicer inline usage, e.g.
430
+ # client.with_options(timeout=10).foo.create(...)
431
+ with_options = copy
432
+
433
+ async def extract(
434
+ self,
435
+ *,
436
+ url: str,
437
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
438
+ # The extra values given here take precedence over values defined on the client or passed to this method.
439
+ extra_headers: Headers | None = None,
440
+ extra_query: Query | None = None,
441
+ extra_body: Body | None = None,
442
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
443
+ ) -> object:
444
+ """
445
+ Extract Get
446
+
447
+ Args:
448
+ extra_headers: Send extra headers
449
+
450
+ extra_query: Add additional query parameters to the request
451
+
452
+ extra_body: Add additional JSON properties to the request
453
+
454
+ timeout: Override the client-level default timeout for this request, in seconds
455
+ """
456
+ return await self.get(
457
+ "/v1/extract",
458
+ options=make_request_options(
459
+ extra_headers=extra_headers,
460
+ extra_query=extra_query,
461
+ extra_body=extra_body,
462
+ timeout=timeout,
463
+ query=await async_maybe_transform({"url": url}, client_extract_params.ClientExtractParams),
464
+ ),
465
+ cast_to=object,
466
+ )
467
+
468
+ async def search(
469
+ self,
470
+ *,
471
+ query: str,
472
+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
473
+ # The extra values given here take precedence over values defined on the client or passed to this method.
474
+ extra_headers: Headers | None = None,
475
+ extra_query: Query | None = None,
476
+ extra_body: Body | None = None,
477
+ timeout: float | httpx.Timeout | None | NotGiven = not_given,
478
+ ) -> object:
479
+ """
480
+ Search Get
481
+
482
+ Args:
483
+ extra_headers: Send extra headers
484
+
485
+ extra_query: Add additional query parameters to the request
486
+
487
+ extra_body: Add additional JSON properties to the request
488
+
489
+ timeout: Override the client-level default timeout for this request, in seconds
490
+ """
491
+ return await self.get(
492
+ "/v1/search",
493
+ options=make_request_options(
494
+ extra_headers=extra_headers,
495
+ extra_query=extra_query,
496
+ extra_body=extra_body,
497
+ timeout=timeout,
498
+ query=await async_maybe_transform({"query": query}, client_search_params.ClientSearchParams),
499
+ ),
500
+ cast_to=object,
501
+ )
502
+
503
+ @override
504
+ def _make_status_error(
505
+ self,
506
+ err_msg: str,
507
+ *,
508
+ body: object,
509
+ response: httpx.Response,
510
+ ) -> APIStatusError:
511
+ if response.status_code == 400:
512
+ return _exceptions.BadRequestError(err_msg, response=response, body=body)
513
+
514
+ if response.status_code == 401:
515
+ return _exceptions.AuthenticationError(err_msg, response=response, body=body)
516
+
517
+ if response.status_code == 403:
518
+ return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
519
+
520
+ if response.status_code == 404:
521
+ return _exceptions.NotFoundError(err_msg, response=response, body=body)
522
+
523
+ if response.status_code == 409:
524
+ return _exceptions.ConflictError(err_msg, response=response, body=body)
525
+
526
+ if response.status_code == 422:
527
+ return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
528
+
529
+ if response.status_code == 429:
530
+ return _exceptions.RateLimitError(err_msg, response=response, body=body)
531
+
532
+ if response.status_code >= 500:
533
+ return _exceptions.InternalServerError(err_msg, response=response, body=body)
534
+ return APIStatusError(err_msg, response=response, body=body)
535
+
536
+
537
+ class uAPIWithRawResponse:
538
+ def __init__(self, client: uAPI) -> None:
539
+ self.extract = to_raw_response_wrapper(
540
+ client.extract,
541
+ )
542
+ self.search = to_raw_response_wrapper(
543
+ client.search,
544
+ )
545
+
546
+
547
+ class AsyncuAPIWithRawResponse:
548
+ def __init__(self, client: AsyncuAPI) -> None:
549
+ self.extract = async_to_raw_response_wrapper(
550
+ client.extract,
551
+ )
552
+ self.search = async_to_raw_response_wrapper(
553
+ client.search,
554
+ )
555
+
556
+
557
+ class uAPIWithStreamedResponse:
558
+ def __init__(self, client: uAPI) -> None:
559
+ self.extract = to_streamed_response_wrapper(
560
+ client.extract,
561
+ )
562
+ self.search = to_streamed_response_wrapper(
563
+ client.search,
564
+ )
565
+
566
+
567
+ class AsyncuAPIWithStreamedResponse:
568
+ def __init__(self, client: AsyncuAPI) -> None:
569
+ self.extract = async_to_streamed_response_wrapper(
570
+ client.extract,
571
+ )
572
+ self.search = async_to_streamed_response_wrapper(
573
+ client.search,
574
+ )
575
+
576
+
577
+ Client = uAPI
578
+
579
+ AsyncClient = AsyncuAPI