linq-python 0.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.
Files changed (139) hide show
  1. linq/__init__.py +102 -0
  2. linq/_base_client.py +2149 -0
  3. linq/_client.py +2479 -0
  4. linq/_compat.py +226 -0
  5. linq/_constants.py +14 -0
  6. linq/_exceptions.py +108 -0
  7. linq/_files.py +123 -0
  8. linq/_models.py +878 -0
  9. linq/_qs.py +153 -0
  10. linq/_resource.py +43 -0
  11. linq/_response.py +833 -0
  12. linq/_streaming.py +338 -0
  13. linq/_types.py +271 -0
  14. linq/_utils/__init__.py +65 -0
  15. linq/_utils/_compat.py +45 -0
  16. linq/_utils/_datetime_parse.py +136 -0
  17. linq/_utils/_json.py +35 -0
  18. linq/_utils/_logs.py +25 -0
  19. linq/_utils/_path.py +127 -0
  20. linq/_utils/_proxy.py +65 -0
  21. linq/_utils/_reflection.py +42 -0
  22. linq/_utils/_resources_proxy.py +24 -0
  23. linq/_utils/_streams.py +12 -0
  24. linq/_utils/_sync.py +58 -0
  25. linq/_utils/_transform.py +457 -0
  26. linq/_utils/_typing.py +156 -0
  27. linq/_utils/_utils.py +421 -0
  28. linq/_version.py +4 -0
  29. linq/lib/.keep +4 -0
  30. linq/pagination.py +95 -0
  31. linq/py.typed +0 -0
  32. linq/resources/__init__.py +134 -0
  33. linq/resources/attachments.py +589 -0
  34. linq/resources/capability.py +297 -0
  35. linq/resources/chats/__init__.py +61 -0
  36. linq/resources/chats/chats.py +1492 -0
  37. linq/resources/chats/messages.py +416 -0
  38. linq/resources/chats/participants.py +322 -0
  39. linq/resources/chats/typing.py +299 -0
  40. linq/resources/contact_card.py +472 -0
  41. linq/resources/messages.py +686 -0
  42. linq/resources/phone_numbers.py +163 -0
  43. linq/resources/phonenumbers.py +165 -0
  44. linq/resources/webhook_events.py +319 -0
  45. linq/resources/webhook_subscriptions.py +776 -0
  46. linq/resources/webhooks.py +34 -0
  47. linq/types/__init__.py +90 -0
  48. linq/types/attachment_create_params.py +42 -0
  49. linq/types/attachment_create_response.py +44 -0
  50. linq/types/attachment_retrieve_response.py +55 -0
  51. linq/types/capability_check_RCS_params.py +20 -0
  52. linq/types/capability_check_i_message_params.py +20 -0
  53. linq/types/chat.py +44 -0
  54. linq/types/chat_create_params.py +33 -0
  55. linq/types/chat_create_response.py +44 -0
  56. linq/types/chat_created_webhook_event.py +87 -0
  57. linq/types/chat_group_icon_update_failed_webhook_event.py +65 -0
  58. linq/types/chat_group_icon_updated_webhook_event.py +66 -0
  59. linq/types/chat_group_name_update_failed_webhook_event.py +65 -0
  60. linq/types/chat_group_name_updated_webhook_event.py +66 -0
  61. linq/types/chat_leave_chat_response.py +15 -0
  62. linq/types/chat_list_chats_params.py +36 -0
  63. linq/types/chat_send_voicememo_params.py +23 -0
  64. linq/types/chat_send_voicememo_response.py +79 -0
  65. linq/types/chat_typing_indicator_started_webhook_event.py +52 -0
  66. linq/types/chat_typing_indicator_stopped_webhook_event.py +52 -0
  67. linq/types/chat_update_params.py +15 -0
  68. linq/types/chat_update_response.py +13 -0
  69. linq/types/chats/__init__.py +12 -0
  70. linq/types/chats/message_list_params.py +15 -0
  71. linq/types/chats/message_send_params.py +18 -0
  72. linq/types/chats/message_send_response.py +16 -0
  73. linq/types/chats/participant_add_params.py +12 -0
  74. linq/types/chats/participant_add_response.py +15 -0
  75. linq/types/chats/participant_remove_params.py +12 -0
  76. linq/types/chats/participant_remove_response.py +15 -0
  77. linq/types/chats/sent_message.py +69 -0
  78. linq/types/contact_card_create_params.py +24 -0
  79. linq/types/contact_card_retrieve_params.py +15 -0
  80. linq/types/contact_card_retrieve_response.py +23 -0
  81. linq/types/contact_card_update_params.py +21 -0
  82. linq/types/events_webhook_event.py +50 -0
  83. linq/types/handle_check_response.py +13 -0
  84. linq/types/link_part_param.py +22 -0
  85. linq/types/media_part_param.py +54 -0
  86. linq/types/message.py +87 -0
  87. linq/types/message_add_reaction_params.py +32 -0
  88. linq/types/message_add_reaction_response.py +15 -0
  89. linq/types/message_content_param.py +82 -0
  90. linq/types/message_delivered_webhook_event.py +65 -0
  91. linq/types/message_edited_webhook_event.py +100 -0
  92. linq/types/message_effect.py +23 -0
  93. linq/types/message_effect_param.py +22 -0
  94. linq/types/message_event_v2.py +116 -0
  95. linq/types/message_failed_webhook_event.py +72 -0
  96. linq/types/message_list_messages_thread_params.py +18 -0
  97. linq/types/message_read_webhook_event.py +65 -0
  98. linq/types/message_received_webhook_event.py +65 -0
  99. linq/types/message_sent_webhook_event.py +65 -0
  100. linq/types/message_update_params.py +15 -0
  101. linq/types/participant_added_webhook_event.py +66 -0
  102. linq/types/participant_removed_webhook_event.py +66 -0
  103. linq/types/phone_number_list_response.py +20 -0
  104. linq/types/phone_number_status_updated_webhook_event.py +82 -0
  105. linq/types/phonenumber_list_response.py +39 -0
  106. linq/types/reaction_added_webhook_event.py +46 -0
  107. linq/types/reaction_event_base.py +85 -0
  108. linq/types/reaction_removed_webhook_event.py +46 -0
  109. linq/types/reply_to.py +21 -0
  110. linq/types/reply_to_param.py +21 -0
  111. linq/types/schemas_media_part_response.py +29 -0
  112. linq/types/schemas_message_effect.py +18 -0
  113. linq/types/schemas_text_part_response.py +22 -0
  114. linq/types/set_contact_card.py +24 -0
  115. linq/types/shared/__init__.py +9 -0
  116. linq/types/shared/chat_handle.py +33 -0
  117. linq/types/shared/media_part_response.py +34 -0
  118. linq/types/shared/reaction.py +56 -0
  119. linq/types/shared/reaction_type.py +7 -0
  120. linq/types/shared/service_type.py +7 -0
  121. linq/types/shared/text_decoration.py +23 -0
  122. linq/types/shared/text_part_response.py +26 -0
  123. linq/types/shared_params/__init__.py +5 -0
  124. linq/types/shared_params/reaction_type.py +9 -0
  125. linq/types/shared_params/service_type.py +9 -0
  126. linq/types/shared_params/text_decoration.py +23 -0
  127. linq/types/supported_content_type.py +60 -0
  128. linq/types/text_part_param.py +44 -0
  129. linq/types/webhook_event_list_response.py +17 -0
  130. linq/types/webhook_event_type.py +33 -0
  131. linq/types/webhook_subscription.py +35 -0
  132. linq/types/webhook_subscription_create_params.py +27 -0
  133. linq/types/webhook_subscription_create_response.py +46 -0
  134. linq/types/webhook_subscription_list_response.py +13 -0
  135. linq/types/webhook_subscription_update_params.py +30 -0
  136. linq_python-0.1.0.dist-info/METADATA +572 -0
  137. linq_python-0.1.0.dist-info/RECORD +139 -0
  138. linq_python-0.1.0.dist-info/WHEEL +4 -0
  139. linq_python-0.1.0.dist-info/licenses/LICENSE +201 -0
linq/_streaming.py ADDED
@@ -0,0 +1,338 @@
1
+ # Note: initially copied from https://github.com/florimondmanca/httpx-sse/blob/master/src/httpx_sse/_decoders.py
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import inspect
6
+ from types import TracebackType
7
+ from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, Optional, AsyncIterator, cast
8
+ from typing_extensions import Self, Protocol, TypeGuard, override, get_origin, runtime_checkable
9
+
10
+ import httpx
11
+
12
+ from ._utils import extract_type_var_from_base
13
+
14
+ if TYPE_CHECKING:
15
+ from ._client import LinqAPIV3, AsyncLinqAPIV3
16
+ from ._models import FinalRequestOptions
17
+
18
+
19
+ _T = TypeVar("_T")
20
+
21
+
22
+ class Stream(Generic[_T]):
23
+ """Provides the core interface to iterate over a synchronous stream response."""
24
+
25
+ response: httpx.Response
26
+ _options: Optional[FinalRequestOptions] = None
27
+ _decoder: SSEBytesDecoder
28
+
29
+ def __init__(
30
+ self,
31
+ *,
32
+ cast_to: type[_T],
33
+ response: httpx.Response,
34
+ client: LinqAPIV3,
35
+ options: Optional[FinalRequestOptions] = None,
36
+ ) -> None:
37
+ self.response = response
38
+ self._cast_to = cast_to
39
+ self._client = client
40
+ self._options = options
41
+ self._decoder = client._make_sse_decoder()
42
+ self._iterator = self.__stream__()
43
+
44
+ def __next__(self) -> _T:
45
+ return self._iterator.__next__()
46
+
47
+ def __iter__(self) -> Iterator[_T]:
48
+ for item in self._iterator:
49
+ yield item
50
+
51
+ def _iter_events(self) -> Iterator[ServerSentEvent]:
52
+ yield from self._decoder.iter_bytes(self.response.iter_bytes())
53
+
54
+ def __stream__(self) -> Iterator[_T]:
55
+ cast_to = cast(Any, self._cast_to)
56
+ response = self.response
57
+ process_data = self._client._process_response_data
58
+ iterator = self._iter_events()
59
+
60
+ try:
61
+ for sse in iterator:
62
+ yield process_data(data=sse.json(), cast_to=cast_to, response=response)
63
+ finally:
64
+ # Ensure the response is closed even if the consumer doesn't read all data
65
+ response.close()
66
+
67
+ def __enter__(self) -> Self:
68
+ return self
69
+
70
+ def __exit__(
71
+ self,
72
+ exc_type: type[BaseException] | None,
73
+ exc: BaseException | None,
74
+ exc_tb: TracebackType | None,
75
+ ) -> None:
76
+ self.close()
77
+
78
+ def close(self) -> None:
79
+ """
80
+ Close the response and release the connection.
81
+
82
+ Automatically called if the response body is read to completion.
83
+ """
84
+ self.response.close()
85
+
86
+
87
+ class AsyncStream(Generic[_T]):
88
+ """Provides the core interface to iterate over an asynchronous stream response."""
89
+
90
+ response: httpx.Response
91
+ _options: Optional[FinalRequestOptions] = None
92
+ _decoder: SSEDecoder | SSEBytesDecoder
93
+
94
+ def __init__(
95
+ self,
96
+ *,
97
+ cast_to: type[_T],
98
+ response: httpx.Response,
99
+ client: AsyncLinqAPIV3,
100
+ options: Optional[FinalRequestOptions] = None,
101
+ ) -> None:
102
+ self.response = response
103
+ self._cast_to = cast_to
104
+ self._client = client
105
+ self._options = options
106
+ self._decoder = client._make_sse_decoder()
107
+ self._iterator = self.__stream__()
108
+
109
+ async def __anext__(self) -> _T:
110
+ return await self._iterator.__anext__()
111
+
112
+ async def __aiter__(self) -> AsyncIterator[_T]:
113
+ async for item in self._iterator:
114
+ yield item
115
+
116
+ async def _iter_events(self) -> AsyncIterator[ServerSentEvent]:
117
+ async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
118
+ yield sse
119
+
120
+ async def __stream__(self) -> AsyncIterator[_T]:
121
+ cast_to = cast(Any, self._cast_to)
122
+ response = self.response
123
+ process_data = self._client._process_response_data
124
+ iterator = self._iter_events()
125
+
126
+ try:
127
+ async for sse in iterator:
128
+ yield process_data(data=sse.json(), cast_to=cast_to, response=response)
129
+ finally:
130
+ # Ensure the response is closed even if the consumer doesn't read all data
131
+ await response.aclose()
132
+
133
+ async def __aenter__(self) -> Self:
134
+ return self
135
+
136
+ async def __aexit__(
137
+ self,
138
+ exc_type: type[BaseException] | None,
139
+ exc: BaseException | None,
140
+ exc_tb: TracebackType | None,
141
+ ) -> None:
142
+ await self.close()
143
+
144
+ async def close(self) -> None:
145
+ """
146
+ Close the response and release the connection.
147
+
148
+ Automatically called if the response body is read to completion.
149
+ """
150
+ await self.response.aclose()
151
+
152
+
153
+ class ServerSentEvent:
154
+ def __init__(
155
+ self,
156
+ *,
157
+ event: str | None = None,
158
+ data: str | None = None,
159
+ id: str | None = None,
160
+ retry: int | None = None,
161
+ ) -> None:
162
+ if data is None:
163
+ data = ""
164
+
165
+ self._id = id
166
+ self._data = data
167
+ self._event = event or None
168
+ self._retry = retry
169
+
170
+ @property
171
+ def event(self) -> str | None:
172
+ return self._event
173
+
174
+ @property
175
+ def id(self) -> str | None:
176
+ return self._id
177
+
178
+ @property
179
+ def retry(self) -> int | None:
180
+ return self._retry
181
+
182
+ @property
183
+ def data(self) -> str:
184
+ return self._data
185
+
186
+ def json(self) -> Any:
187
+ return json.loads(self.data)
188
+
189
+ @override
190
+ def __repr__(self) -> str:
191
+ return f"ServerSentEvent(event={self.event}, data={self.data}, id={self.id}, retry={self.retry})"
192
+
193
+
194
+ class SSEDecoder:
195
+ _data: list[str]
196
+ _event: str | None
197
+ _retry: int | None
198
+ _last_event_id: str | None
199
+
200
+ def __init__(self) -> None:
201
+ self._event = None
202
+ self._data = []
203
+ self._last_event_id = None
204
+ self._retry = None
205
+
206
+ def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
207
+ """Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
208
+ for chunk in self._iter_chunks(iterator):
209
+ # Split before decoding so splitlines() only uses \r and \n
210
+ for raw_line in chunk.splitlines():
211
+ line = raw_line.decode("utf-8")
212
+ sse = self.decode(line)
213
+ if sse:
214
+ yield sse
215
+
216
+ def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
217
+ """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
218
+ data = b""
219
+ for chunk in iterator:
220
+ for line in chunk.splitlines(keepends=True):
221
+ data += line
222
+ if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
223
+ yield data
224
+ data = b""
225
+ if data:
226
+ yield data
227
+
228
+ async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
229
+ """Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
230
+ async for chunk in self._aiter_chunks(iterator):
231
+ # Split before decoding so splitlines() only uses \r and \n
232
+ for raw_line in chunk.splitlines():
233
+ line = raw_line.decode("utf-8")
234
+ sse = self.decode(line)
235
+ if sse:
236
+ yield sse
237
+
238
+ async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]:
239
+ """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
240
+ data = b""
241
+ async for chunk in iterator:
242
+ for line in chunk.splitlines(keepends=True):
243
+ data += line
244
+ if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
245
+ yield data
246
+ data = b""
247
+ if data:
248
+ yield data
249
+
250
+ def decode(self, line: str) -> ServerSentEvent | None:
251
+ # See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501
252
+
253
+ if not line:
254
+ if not self._event and not self._data and not self._last_event_id and self._retry is None:
255
+ return None
256
+
257
+ sse = ServerSentEvent(
258
+ event=self._event,
259
+ data="\n".join(self._data),
260
+ id=self._last_event_id,
261
+ retry=self._retry,
262
+ )
263
+
264
+ # NOTE: as per the SSE spec, do not reset last_event_id.
265
+ self._event = None
266
+ self._data = []
267
+ self._retry = None
268
+
269
+ return sse
270
+
271
+ if line.startswith(":"):
272
+ return None
273
+
274
+ fieldname, _, value = line.partition(":")
275
+
276
+ if value.startswith(" "):
277
+ value = value[1:]
278
+
279
+ if fieldname == "event":
280
+ self._event = value
281
+ elif fieldname == "data":
282
+ self._data.append(value)
283
+ elif fieldname == "id":
284
+ if "\0" in value:
285
+ pass
286
+ else:
287
+ self._last_event_id = value
288
+ elif fieldname == "retry":
289
+ try:
290
+ self._retry = int(value)
291
+ except (TypeError, ValueError):
292
+ pass
293
+ else:
294
+ pass # Field is ignored.
295
+
296
+ return None
297
+
298
+
299
+ @runtime_checkable
300
+ class SSEBytesDecoder(Protocol):
301
+ def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
302
+ """Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
303
+ ...
304
+
305
+ def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
306
+ """Given an async iterator that yields raw binary data, iterate over it & yield every event encountered"""
307
+ ...
308
+
309
+
310
+ def is_stream_class_type(typ: type) -> TypeGuard[type[Stream[object]] | type[AsyncStream[object]]]:
311
+ """TypeGuard for determining whether or not the given type is a subclass of `Stream` / `AsyncStream`"""
312
+ origin = get_origin(typ) or typ
313
+ return inspect.isclass(origin) and issubclass(origin, (Stream, AsyncStream))
314
+
315
+
316
+ def extract_stream_chunk_type(
317
+ stream_cls: type,
318
+ *,
319
+ failure_message: str | None = None,
320
+ ) -> type:
321
+ """Given a type like `Stream[T]`, returns the generic type variable `T`.
322
+
323
+ This also handles the case where a concrete subclass is given, e.g.
324
+ ```py
325
+ class MyStream(Stream[bytes]):
326
+ ...
327
+
328
+ extract_stream_chunk_type(MyStream) -> bytes
329
+ ```
330
+ """
331
+ from ._base_client import Stream, AsyncStream
332
+
333
+ return extract_type_var_from_base(
334
+ stream_cls,
335
+ index=0,
336
+ generic_bases=cast("tuple[type, ...]", (Stream, AsyncStream)),
337
+ failure_message=failure_message,
338
+ )
linq/_types.py ADDED
@@ -0,0 +1,271 @@
1
+ from __future__ import annotations
2
+
3
+ from os import PathLike
4
+ from typing import (
5
+ IO,
6
+ TYPE_CHECKING,
7
+ Any,
8
+ Dict,
9
+ List,
10
+ Type,
11
+ Tuple,
12
+ Union,
13
+ Mapping,
14
+ TypeVar,
15
+ Callable,
16
+ Iterable,
17
+ Iterator,
18
+ Optional,
19
+ Sequence,
20
+ AsyncIterable,
21
+ )
22
+ from typing_extensions import (
23
+ Set,
24
+ Literal,
25
+ Protocol,
26
+ TypeAlias,
27
+ TypedDict,
28
+ SupportsIndex,
29
+ overload,
30
+ override,
31
+ runtime_checkable,
32
+ )
33
+
34
+ import httpx
35
+ import pydantic
36
+ from httpx import URL, Proxy, Timeout, Response, BaseTransport, AsyncBaseTransport
37
+
38
+ if TYPE_CHECKING:
39
+ from ._models import BaseModel, SecurityOptions
40
+ from ._response import APIResponse, AsyncAPIResponse
41
+
42
+ Transport = BaseTransport
43
+ AsyncTransport = AsyncBaseTransport
44
+ Query = Mapping[str, object]
45
+ Body = object
46
+ AnyMapping = Mapping[str, object]
47
+ ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
48
+ _T = TypeVar("_T")
49
+
50
+
51
+ # Approximates httpx internal ProxiesTypes and RequestFiles types
52
+ # while adding support for `PathLike` instances
53
+ ProxiesDict = Dict["str | URL", Union[None, str, URL, Proxy]]
54
+ ProxiesTypes = Union[str, Proxy, ProxiesDict]
55
+ if TYPE_CHECKING:
56
+ Base64FileInput = Union[IO[bytes], PathLike[str]]
57
+ FileContent = Union[IO[bytes], bytes, PathLike[str]]
58
+ else:
59
+ Base64FileInput = Union[IO[bytes], PathLike]
60
+ FileContent = Union[IO[bytes], bytes, PathLike] # PathLike is not subscriptable in Python 3.8.
61
+
62
+
63
+ # Used for sending raw binary data / streaming data in request bodies
64
+ # e.g. for file uploads without multipart encoding
65
+ BinaryTypes = Union[bytes, bytearray, IO[bytes], Iterable[bytes]]
66
+ AsyncBinaryTypes = Union[bytes, bytearray, IO[bytes], AsyncIterable[bytes]]
67
+
68
+ FileTypes = Union[
69
+ # file (or bytes)
70
+ FileContent,
71
+ # (filename, file (or bytes))
72
+ Tuple[Optional[str], FileContent],
73
+ # (filename, file (or bytes), content_type)
74
+ Tuple[Optional[str], FileContent, Optional[str]],
75
+ # (filename, file (or bytes), content_type, headers)
76
+ Tuple[Optional[str], FileContent, Optional[str], Mapping[str, str]],
77
+ ]
78
+ RequestFiles = Union[Mapping[str, FileTypes], Sequence[Tuple[str, FileTypes]]]
79
+
80
+ # duplicate of the above but without our custom file support
81
+ HttpxFileContent = Union[IO[bytes], bytes]
82
+ HttpxFileTypes = Union[
83
+ # file (or bytes)
84
+ HttpxFileContent,
85
+ # (filename, file (or bytes))
86
+ Tuple[Optional[str], HttpxFileContent],
87
+ # (filename, file (or bytes), content_type)
88
+ Tuple[Optional[str], HttpxFileContent, Optional[str]],
89
+ # (filename, file (or bytes), content_type, headers)
90
+ Tuple[Optional[str], HttpxFileContent, Optional[str], Mapping[str, str]],
91
+ ]
92
+ HttpxRequestFiles = Union[Mapping[str, HttpxFileTypes], Sequence[Tuple[str, HttpxFileTypes]]]
93
+
94
+ # Workaround to support (cast_to: Type[ResponseT]) -> ResponseT
95
+ # where ResponseT includes `None`. In order to support directly
96
+ # passing `None`, overloads would have to be defined for every
97
+ # method that uses `ResponseT` which would lead to an unacceptable
98
+ # amount of code duplication and make it unreadable. See _base_client.py
99
+ # for example usage.
100
+ #
101
+ # This unfortunately means that you will either have
102
+ # to import this type and pass it explicitly:
103
+ #
104
+ # from linq import NoneType
105
+ # client.get('/foo', cast_to=NoneType)
106
+ #
107
+ # or build it yourself:
108
+ #
109
+ # client.get('/foo', cast_to=type(None))
110
+ if TYPE_CHECKING:
111
+ NoneType: Type[None]
112
+ else:
113
+ NoneType = type(None)
114
+
115
+
116
+ class RequestOptions(TypedDict, total=False):
117
+ headers: Headers
118
+ max_retries: int
119
+ timeout: float | Timeout | None
120
+ params: Query
121
+ extra_json: AnyMapping
122
+ idempotency_key: str
123
+ follow_redirects: bool
124
+ security: SecurityOptions
125
+
126
+
127
+ # Sentinel class used until PEP 0661 is accepted
128
+ class NotGiven:
129
+ """
130
+ For parameters with a meaningful None value, we need to distinguish between
131
+ the user explicitly passing None, and the user not passing the parameter at
132
+ all.
133
+
134
+ User code shouldn't need to use not_given directly.
135
+
136
+ For example:
137
+
138
+ ```py
139
+ def create(timeout: Timeout | None | NotGiven = not_given): ...
140
+
141
+
142
+ create(timeout=1) # 1s timeout
143
+ create(timeout=None) # No timeout
144
+ create() # Default timeout behavior
145
+ ```
146
+ """
147
+
148
+ def __bool__(self) -> Literal[False]:
149
+ return False
150
+
151
+ @override
152
+ def __repr__(self) -> str:
153
+ return "NOT_GIVEN"
154
+
155
+
156
+ not_given = NotGiven()
157
+ # for backwards compatibility:
158
+ NOT_GIVEN = NotGiven()
159
+
160
+
161
+ class Omit:
162
+ """
163
+ To explicitly omit something from being sent in a request, use `omit`.
164
+
165
+ ```py
166
+ # as the default `Content-Type` header is `application/json` that will be sent
167
+ client.post("/upload/files", files={"file": b"my raw file content"})
168
+
169
+ # you can't explicitly override the header as it has to be dynamically generated
170
+ # to look something like: 'multipart/form-data; boundary=0d8382fcf5f8c3be01ca2e11002d2983'
171
+ client.post(..., headers={"Content-Type": "multipart/form-data"})
172
+
173
+ # instead you can remove the default `application/json` header by passing omit
174
+ client.post(..., headers={"Content-Type": omit})
175
+ ```
176
+ """
177
+
178
+ def __bool__(self) -> Literal[False]:
179
+ return False
180
+
181
+
182
+ omit = Omit()
183
+
184
+
185
+ @runtime_checkable
186
+ class ModelBuilderProtocol(Protocol):
187
+ @classmethod
188
+ def build(
189
+ cls: type[_T],
190
+ *,
191
+ response: Response,
192
+ data: object,
193
+ ) -> _T: ...
194
+
195
+
196
+ Headers = Mapping[str, Union[str, Omit]]
197
+
198
+
199
+ class HeadersLikeProtocol(Protocol):
200
+ def get(self, __key: str) -> str | None: ...
201
+
202
+
203
+ HeadersLike = Union[Headers, HeadersLikeProtocol]
204
+
205
+ ResponseT = TypeVar(
206
+ "ResponseT",
207
+ bound=Union[
208
+ object,
209
+ str,
210
+ None,
211
+ "BaseModel",
212
+ List[Any],
213
+ Dict[str, Any],
214
+ Response,
215
+ ModelBuilderProtocol,
216
+ "APIResponse[Any]",
217
+ "AsyncAPIResponse[Any]",
218
+ ],
219
+ )
220
+
221
+ StrBytesIntFloat = Union[str, bytes, int, float]
222
+
223
+ # Note: copied from Pydantic
224
+ # https://github.com/pydantic/pydantic/blob/6f31f8f68ef011f84357330186f603ff295312fd/pydantic/main.py#L79
225
+ IncEx: TypeAlias = Union[Set[int], Set[str], Mapping[int, Union["IncEx", bool]], Mapping[str, Union["IncEx", bool]]]
226
+
227
+ PostParser = Callable[[Any], Any]
228
+
229
+
230
+ @runtime_checkable
231
+ class InheritsGeneric(Protocol):
232
+ """Represents a type that has inherited from `Generic`
233
+
234
+ The `__orig_bases__` property can be used to determine the resolved
235
+ type variable for a given base class.
236
+ """
237
+
238
+ __orig_bases__: tuple[_GenericAlias]
239
+
240
+
241
+ class _GenericAlias(Protocol):
242
+ __origin__: type[object]
243
+
244
+
245
+ class HttpxSendArgs(TypedDict, total=False):
246
+ auth: httpx.Auth
247
+ follow_redirects: bool
248
+
249
+
250
+ _T_co = TypeVar("_T_co", covariant=True)
251
+
252
+
253
+ if TYPE_CHECKING:
254
+ # This works because str.__contains__ does not accept object (either in typeshed or at runtime)
255
+ # https://github.com/hauntsaninja/useful_types/blob/5e9710f3875107d068e7679fd7fec9cfab0eff3b/useful_types/__init__.py#L285
256
+ #
257
+ # Note: index() and count() methods are intentionally omitted to allow pyright to properly
258
+ # infer TypedDict types when dict literals are used in lists assigned to SequenceNotStr.
259
+ class SequenceNotStr(Protocol[_T_co]):
260
+ @overload
261
+ def __getitem__(self, index: SupportsIndex, /) -> _T_co: ...
262
+ @overload
263
+ def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ...
264
+ def __contains__(self, value: object, /) -> bool: ...
265
+ def __len__(self) -> int: ...
266
+ def __iter__(self) -> Iterator[_T_co]: ...
267
+ def __reversed__(self) -> Iterator[_T_co]: ...
268
+ else:
269
+ # just point this to a normal `Sequence` at runtime to avoid having to special case
270
+ # deserializing our custom sequence type
271
+ SequenceNotStr = Sequence
@@ -0,0 +1,65 @@
1
+ from ._path import path_template as path_template
2
+ from ._sync import asyncify as asyncify
3
+ from ._proxy import LazyProxy as LazyProxy
4
+ from ._utils import (
5
+ flatten as flatten,
6
+ is_dict as is_dict,
7
+ is_list as is_list,
8
+ is_given as is_given,
9
+ is_tuple as is_tuple,
10
+ json_safe as json_safe,
11
+ lru_cache as lru_cache,
12
+ is_mapping as is_mapping,
13
+ is_tuple_t as is_tuple_t,
14
+ is_iterable as is_iterable,
15
+ is_sequence as is_sequence,
16
+ coerce_float as coerce_float,
17
+ is_mapping_t as is_mapping_t,
18
+ removeprefix as removeprefix,
19
+ removesuffix as removesuffix,
20
+ extract_files as extract_files,
21
+ is_sequence_t as is_sequence_t,
22
+ required_args as required_args,
23
+ coerce_boolean as coerce_boolean,
24
+ coerce_integer as coerce_integer,
25
+ file_from_path as file_from_path,
26
+ strip_not_given as strip_not_given,
27
+ deepcopy_minimal as deepcopy_minimal,
28
+ get_async_library as get_async_library,
29
+ maybe_coerce_float as maybe_coerce_float,
30
+ get_required_header as get_required_header,
31
+ maybe_coerce_boolean as maybe_coerce_boolean,
32
+ maybe_coerce_integer as maybe_coerce_integer,
33
+ )
34
+ from ._compat import (
35
+ get_args as get_args,
36
+ is_union as is_union,
37
+ get_origin as get_origin,
38
+ is_typeddict as is_typeddict,
39
+ is_literal_type as is_literal_type,
40
+ )
41
+ from ._typing import (
42
+ is_list_type as is_list_type,
43
+ is_union_type as is_union_type,
44
+ extract_type_arg as extract_type_arg,
45
+ is_iterable_type as is_iterable_type,
46
+ is_required_type as is_required_type,
47
+ is_sequence_type as is_sequence_type,
48
+ is_annotated_type as is_annotated_type,
49
+ is_type_alias_type as is_type_alias_type,
50
+ strip_annotated_type as strip_annotated_type,
51
+ extract_type_var_from_base as extract_type_var_from_base,
52
+ )
53
+ from ._streams import consume_sync_iterator as consume_sync_iterator, consume_async_iterator as consume_async_iterator
54
+ from ._transform import (
55
+ PropertyInfo as PropertyInfo,
56
+ transform as transform,
57
+ async_transform as async_transform,
58
+ maybe_transform as maybe_transform,
59
+ async_maybe_transform as async_maybe_transform,
60
+ )
61
+ from ._reflection import (
62
+ function_has_argument as function_has_argument,
63
+ assert_signatures_in_sync as assert_signatures_in_sync,
64
+ )
65
+ from ._datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime