chunkify-analytics-sdk 0.9.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 (179) hide show
  1. chunkify_analytics/__init__.py +102 -0
  2. chunkify_analytics/_base_client.py +2153 -0
  3. chunkify_analytics/_client.py +1262 -0
  4. chunkify_analytics/_compat.py +226 -0
  5. chunkify_analytics/_constants.py +14 -0
  6. chunkify_analytics/_exceptions.py +108 -0
  7. chunkify_analytics/_files.py +173 -0
  8. chunkify_analytics/_models.py +964 -0
  9. chunkify_analytics/_qs.py +149 -0
  10. chunkify_analytics/_resource.py +43 -0
  11. chunkify_analytics/_response.py +835 -0
  12. chunkify_analytics/_streaming.py +338 -0
  13. chunkify_analytics/_types.py +274 -0
  14. chunkify_analytics/_utils/__init__.py +64 -0
  15. chunkify_analytics/_utils/_compat.py +45 -0
  16. chunkify_analytics/_utils/_datetime_parse.py +136 -0
  17. chunkify_analytics/_utils/_json.py +35 -0
  18. chunkify_analytics/_utils/_logs.py +25 -0
  19. chunkify_analytics/_utils/_path.py +127 -0
  20. chunkify_analytics/_utils/_proxy.py +65 -0
  21. chunkify_analytics/_utils/_reflection.py +42 -0
  22. chunkify_analytics/_utils/_resources_proxy.py +24 -0
  23. chunkify_analytics/_utils/_streams.py +12 -0
  24. chunkify_analytics/_utils/_sync.py +58 -0
  25. chunkify_analytics/_utils/_transform.py +457 -0
  26. chunkify_analytics/_utils/_typing.py +156 -0
  27. chunkify_analytics/_utils/_utils.py +433 -0
  28. chunkify_analytics/_version.py +4 -0
  29. chunkify_analytics/lib/.keep +4 -0
  30. chunkify_analytics/pagination.py +221 -0
  31. chunkify_analytics/py.typed +0 -0
  32. chunkify_analytics/resources/__init__.py +243 -0
  33. chunkify_analytics/resources/admin/__init__.py +33 -0
  34. chunkify_analytics/resources/admin/admin.py +253 -0
  35. chunkify_analytics/resources/admin/keys.py +283 -0
  36. chunkify_analytics/resources/dimensions.py +436 -0
  37. chunkify_analytics/resources/engagement.py +479 -0
  38. chunkify_analytics/resources/errors.py +400 -0
  39. chunkify_analytics/resources/events.py +562 -0
  40. chunkify_analytics/resources/exports.py +584 -0
  41. chunkify_analytics/resources/health.py +159 -0
  42. chunkify_analytics/resources/playback_rates.py +391 -0
  43. chunkify_analytics/resources/project/__init__.py +33 -0
  44. chunkify_analytics/resources/project/keys.py +379 -0
  45. chunkify_analytics/resources/project/project.py +322 -0
  46. chunkify_analytics/resources/quality.py +471 -0
  47. chunkify_analytics/resources/renditions.py +391 -0
  48. chunkify_analytics/resources/retention.py +377 -0
  49. chunkify_analytics/resources/subtitles.py +389 -0
  50. chunkify_analytics/resources/summary.py +469 -0
  51. chunkify_analytics/resources/timeseries.py +399 -0
  52. chunkify_analytics/resources/videos.py +424 -0
  53. chunkify_analytics/resources/views.py +579 -0
  54. chunkify_analytics/types/__init__.py +145 -0
  55. chunkify_analytics/types/admin/__init__.py +3 -0
  56. chunkify_analytics/types/admin_create_project_params.py +25 -0
  57. chunkify_analytics/types/analytics_event.py +32 -0
  58. chunkify_analytics/types/analytics_event_param.py +30 -0
  59. chunkify_analytics/types/created_project.py +37 -0
  60. chunkify_analytics/types/created_project_key.py +34 -0
  61. chunkify_analytics/types/deleted_project.py +18 -0
  62. chunkify_analytics/types/dimension_list_values_params.py +124 -0
  63. chunkify_analytics/types/dimension_values.py +42 -0
  64. chunkify_analytics/types/engagement.py +60 -0
  65. chunkify_analytics/types/engagement_breakdown_page.py +44 -0
  66. chunkify_analytics/types/engagement_response.py +11 -0
  67. chunkify_analytics/types/engagement_retrieve_params.py +158 -0
  68. chunkify_analytics/types/engagement_timeseries.py +28 -0
  69. chunkify_analytics/types/engagement_timeseries_bucket.py +63 -0
  70. chunkify_analytics/types/error_group.py +17 -0
  71. chunkify_analytics/types/error_list_params.py +124 -0
  72. chunkify_analytics/types/error_page.py +14 -0
  73. chunkify_analytics/types/event_ingest_params.py +19 -0
  74. chunkify_analytics/types/event_ingest_response.py +11 -0
  75. chunkify_analytics/types/event_list_params.py +146 -0
  76. chunkify_analytics/types/event_page.py +18 -0
  77. chunkify_analytics/types/export.py +18 -0
  78. chunkify_analytics/types/export_columns.py +12 -0
  79. chunkify_analytics/types/export_create_params.py +40 -0
  80. chunkify_analytics/types/export_download_response.py +7 -0
  81. chunkify_analytics/types/export_list_columns_params.py +69 -0
  82. chunkify_analytics/types/export_query_param.py +141 -0
  83. chunkify_analytics/types/health.py +11 -0
  84. chunkify_analytics/types/metrics.py +13 -0
  85. chunkify_analytics/types/metrics_breakdown_page.py +40 -0
  86. chunkify_analytics/types/metrics_response.py +11 -0
  87. chunkify_analytics/types/native_created.py +13 -0
  88. chunkify_analytics/types/native_duplicate.py +13 -0
  89. chunkify_analytics/types/playback_error.py +180 -0
  90. chunkify_analytics/types/playback_error_param.py +182 -0
  91. chunkify_analytics/types/playback_rate_changed.py +150 -0
  92. chunkify_analytics/types/playback_rate_changed_param.py +152 -0
  93. chunkify_analytics/types/playback_rate_metric.py +21 -0
  94. chunkify_analytics/types/playback_rate_report.py +31 -0
  95. chunkify_analytics/types/playback_rate_retrieve_params.py +117 -0
  96. chunkify_analytics/types/playback_state_changed.py +150 -0
  97. chunkify_analytics/types/playback_state_changed_param.py +156 -0
  98. chunkify_analytics/types/project/__init__.py +6 -0
  99. chunkify_analytics/types/project/key_create_params.py +21 -0
  100. chunkify_analytics/types/project/project.py +35 -0
  101. chunkify_analytics/types/project_key.py +21 -0
  102. chunkify_analytics/types/project_keys.py +14 -0
  103. chunkify_analytics/types/project_update_params.py +25 -0
  104. chunkify_analytics/types/quality.py +117 -0
  105. chunkify_analytics/types/quality_breakdown_page.py +44 -0
  106. chunkify_analytics/types/quality_response.py +11 -0
  107. chunkify_analytics/types/quality_retrieve_params.py +158 -0
  108. chunkify_analytics/types/quality_timeseries.py +28 -0
  109. chunkify_analytics/types/quality_timeseries_bucket.py +120 -0
  110. chunkify_analytics/types/rendition_changed.py +156 -0
  111. chunkify_analytics/types/rendition_changed_param.py +158 -0
  112. chunkify_analytics/types/rendition_metric.py +40 -0
  113. chunkify_analytics/types/rendition_report.py +43 -0
  114. chunkify_analytics/types/rendition_retrieve_params.py +117 -0
  115. chunkify_analytics/types/retention_bucket.py +22 -0
  116. chunkify_analytics/types/retention_report.py +33 -0
  117. chunkify_analytics/types/retention_retrieve_params.py +110 -0
  118. chunkify_analytics/types/rotated_project_key.py +29 -0
  119. chunkify_analytics/types/seek_completed.py +166 -0
  120. chunkify_analytics/types/seek_completed_param.py +168 -0
  121. chunkify_analytics/types/shared/__init__.py +24 -0
  122. chunkify_analytics/types/shared/browser_context.py +62 -0
  123. chunkify_analytics/types/shared/custom_dimensions.py +8 -0
  124. chunkify_analytics/types/shared/event_context.py +161 -0
  125. chunkify_analytics/types/shared/event_envelope.py +152 -0
  126. chunkify_analytics/types/shared/metric_count_ratio.py +18 -0
  127. chunkify_analytics/types/shared/otlp_any_value.py +56 -0
  128. chunkify_analytics/types/shared/otlp_attribute.py +24 -0
  129. chunkify_analytics/types/shared/otlp_attribute_value.py +136 -0
  130. chunkify_analytics/types/shared/otlp_context_attribute.py +22 -0
  131. chunkify_analytics/types/shared/otlp_log_record.py +48 -0
  132. chunkify_analytics/types/shared/otlp_resource.py +20 -0
  133. chunkify_analytics/types/shared/otlp_scope.py +24 -0
  134. chunkify_analytics/types/shared/playback_rate_playing_time.py +12 -0
  135. chunkify_analytics/types/shared/playback_score.py +28 -0
  136. chunkify_analytics/types/shared/played_range.py +13 -0
  137. chunkify_analytics/types/shared/progress_reached.py +39 -0
  138. chunkify_analytics/types/shared/rendition_playing_time.py +21 -0
  139. chunkify_analytics/types/shared/startup_outcomes.py +39 -0
  140. chunkify_analytics/types/shared/stored_otlp_context.py +50 -0
  141. chunkify_analytics/types/shared/subtitle_playing_time.py +14 -0
  142. chunkify_analytics/types/shared/view_metrics.py +100 -0
  143. chunkify_analytics/types/shared/watch_time_distribution.py +41 -0
  144. chunkify_analytics/types/shared_params/__init__.py +8 -0
  145. chunkify_analytics/types/shared_params/browser_context.py +62 -0
  146. chunkify_analytics/types/shared_params/custom_dimensions.py +10 -0
  147. chunkify_analytics/types/shared_params/playback_rate_playing_time.py +14 -0
  148. chunkify_analytics/types/shared_params/played_range.py +15 -0
  149. chunkify_analytics/types/shared_params/rendition_playing_time.py +22 -0
  150. chunkify_analytics/types/shared_params/subtitle_playing_time.py +15 -0
  151. chunkify_analytics/types/stored_event.py +44 -0
  152. chunkify_analytics/types/subtitle_changed.py +150 -0
  153. chunkify_analytics/types/subtitle_changed_param.py +152 -0
  154. chunkify_analytics/types/subtitle_metric.py +26 -0
  155. chunkify_analytics/types/subtitle_report.py +31 -0
  156. chunkify_analytics/types/subtitle_retrieve_params.py +117 -0
  157. chunkify_analytics/types/summary_retrieve_params.py +158 -0
  158. chunkify_analytics/types/time_bucket.py +22 -0
  159. chunkify_analytics/types/timeseries.py +28 -0
  160. chunkify_analytics/types/timeseries_response.py +12 -0
  161. chunkify_analytics/types/timesery_retrieve_params.py +115 -0
  162. chunkify_analytics/types/video_list_params.py +140 -0
  163. chunkify_analytics/types/video_metrics.py +23 -0
  164. chunkify_analytics/types/video_page.py +14 -0
  165. chunkify_analytics/types/view.py +43 -0
  166. chunkify_analytics/types/view_detail.py +21 -0
  167. chunkify_analytics/types/view_ended.py +180 -0
  168. chunkify_analytics/types/view_ended_param.py +182 -0
  169. chunkify_analytics/types/view_list_params.py +152 -0
  170. chunkify_analytics/types/view_page.py +14 -0
  171. chunkify_analytics/types/view_retrieve_params.py +23 -0
  172. chunkify_analytics/types/view_snapshot.py +180 -0
  173. chunkify_analytics/types/view_snapshot_param.py +182 -0
  174. chunkify_analytics/types/view_started.py +192 -0
  175. chunkify_analytics/types/view_started_param.py +194 -0
  176. chunkify_analytics_sdk-0.9.0.dist-info/METADATA +487 -0
  177. chunkify_analytics_sdk-0.9.0.dist-info/RECORD +179 -0
  178. chunkify_analytics_sdk-0.9.0.dist-info/WHEEL +4 -0
  179. chunkify_analytics_sdk-0.9.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,964 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import inspect
5
+ import weakref
6
+ from typing import (
7
+ IO,
8
+ TYPE_CHECKING,
9
+ Any,
10
+ Type,
11
+ Union,
12
+ Generic,
13
+ TypeVar,
14
+ Callable,
15
+ Iterable,
16
+ Optional,
17
+ AsyncIterable,
18
+ cast,
19
+ )
20
+ from datetime import date, datetime
21
+ from typing_extensions import (
22
+ List,
23
+ Unpack,
24
+ Literal,
25
+ ClassVar,
26
+ Protocol,
27
+ Required,
28
+ Annotated,
29
+ ParamSpec,
30
+ TypeAlias,
31
+ TypedDict,
32
+ TypeGuard,
33
+ final,
34
+ override,
35
+ runtime_checkable,
36
+ )
37
+
38
+ import pydantic
39
+ from pydantic.fields import FieldInfo
40
+
41
+ from ._types import (
42
+ Body,
43
+ IncEx,
44
+ Query,
45
+ ModelT,
46
+ Headers,
47
+ Timeout,
48
+ NotGiven,
49
+ AnyMapping,
50
+ HttpxRequestFiles,
51
+ )
52
+ from ._utils import (
53
+ PropertyInfo,
54
+ is_list,
55
+ is_given,
56
+ json_safe,
57
+ lru_cache,
58
+ is_mapping,
59
+ parse_date,
60
+ coerce_boolean,
61
+ parse_datetime,
62
+ strip_not_given,
63
+ extract_type_arg,
64
+ is_annotated_type,
65
+ is_type_alias_type,
66
+ strip_annotated_type,
67
+ )
68
+ from ._compat import (
69
+ PYDANTIC_V1,
70
+ ConfigDict,
71
+ GenericModel as BaseGenericModel,
72
+ get_args,
73
+ is_union,
74
+ parse_obj,
75
+ get_origin,
76
+ is_literal_type,
77
+ get_model_config,
78
+ get_model_fields,
79
+ field_get_default,
80
+ )
81
+ from ._constants import RAW_RESPONSE_HEADER
82
+
83
+ if TYPE_CHECKING:
84
+ from pydantic import GetCoreSchemaHandler, ValidatorFunctionWrapHandler
85
+ from pydantic_core import CoreSchema, core_schema
86
+ from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema
87
+ else:
88
+ try:
89
+ from pydantic_core import CoreSchema, core_schema
90
+ except ImportError:
91
+ CoreSchema = None
92
+ core_schema = None
93
+
94
+ __all__ = ["BaseModel", "GenericModel"]
95
+
96
+ _T = TypeVar("_T")
97
+ _BaseModelT = TypeVar("_BaseModelT", bound="BaseModel")
98
+
99
+ P = ParamSpec("P")
100
+
101
+
102
+ @runtime_checkable
103
+ class _ConfigProtocol(Protocol):
104
+ allow_population_by_field_name: bool
105
+
106
+
107
+ class BaseModel(pydantic.BaseModel):
108
+ if PYDANTIC_V1:
109
+
110
+ @property
111
+ @override
112
+ def model_fields_set(self) -> set[str]:
113
+ # a forwards-compat shim for pydantic v2
114
+ return self.__fields_set__ # type: ignore
115
+
116
+ class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
117
+ extra: Any = pydantic.Extra.allow # type: ignore
118
+ else:
119
+ model_config: ClassVar[ConfigDict] = ConfigDict(
120
+ extra="allow", defer_build=coerce_boolean(os.environ.get("DEFER_PYDANTIC_BUILD", "true"))
121
+ )
122
+
123
+ def to_dict(
124
+ self,
125
+ *,
126
+ mode: Literal["json", "python"] = "python",
127
+ use_api_names: bool = True,
128
+ exclude_unset: bool = True,
129
+ exclude_defaults: bool = False,
130
+ exclude_none: bool = False,
131
+ warnings: bool = True,
132
+ ) -> dict[str, object]:
133
+ """Recursively generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
134
+
135
+ By default, fields that were not set by the API will not be included,
136
+ and keys will match the API response, *not* the property names from the model.
137
+
138
+ For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
139
+ the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).
140
+
141
+ Args:
142
+ mode:
143
+ If mode is 'json', the dictionary will only contain JSON serializable types. e.g. `datetime` will be turned into a string, `"2024-3-22T18:11:19.117000Z"`.
144
+ If mode is 'python', the dictionary may contain any Python objects. e.g. `datetime(2024, 3, 22)`
145
+
146
+ use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
147
+ exclude_unset: Whether to exclude fields that have not been explicitly set.
148
+ exclude_defaults: Whether to exclude fields that are set to their default value from the output.
149
+ exclude_none: Whether to exclude fields that have a value of `None` from the output.
150
+ warnings: Whether to log warnings when invalid fields are encountered. This is only supported in Pydantic v2.
151
+ """
152
+ return self.model_dump(
153
+ mode=mode,
154
+ by_alias=use_api_names,
155
+ exclude_unset=exclude_unset,
156
+ exclude_defaults=exclude_defaults,
157
+ exclude_none=exclude_none,
158
+ warnings=warnings,
159
+ )
160
+
161
+ def to_json(
162
+ self,
163
+ *,
164
+ indent: int | None = 2,
165
+ use_api_names: bool = True,
166
+ exclude_unset: bool = True,
167
+ exclude_defaults: bool = False,
168
+ exclude_none: bool = False,
169
+ warnings: bool = True,
170
+ ) -> str:
171
+ """Generates a JSON string representing this model as it would be received from or sent to the API (but with indentation).
172
+
173
+ By default, fields that were not set by the API will not be included,
174
+ and keys will match the API response, *not* the property names from the model.
175
+
176
+ For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
177
+ the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).
178
+
179
+ Args:
180
+ indent: Indentation to use in the JSON output. If `None` is passed, the output will be compact. Defaults to `2`
181
+ use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
182
+ exclude_unset: Whether to exclude fields that have not been explicitly set.
183
+ exclude_defaults: Whether to exclude fields that have the default value.
184
+ exclude_none: Whether to exclude fields that have a value of `None`.
185
+ warnings: Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.
186
+ """
187
+ return self.model_dump_json(
188
+ indent=indent,
189
+ by_alias=use_api_names,
190
+ exclude_unset=exclude_unset,
191
+ exclude_defaults=exclude_defaults,
192
+ exclude_none=exclude_none,
193
+ warnings=warnings,
194
+ )
195
+
196
+ @override
197
+ def __str__(self) -> str:
198
+ # mypy complains about an invalid self arg
199
+ return f"{self.__repr_name__()}({self.__repr_str__(', ')})" # type: ignore[misc]
200
+
201
+ # Override the 'construct' method in a way that supports recursive parsing without validation.
202
+ # Based on https://github.com/samuelcolvin/pydantic/issues/1168#issuecomment-817742836.
203
+ @classmethod
204
+ @override
205
+ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
206
+ __cls: Type[ModelT],
207
+ _fields_set: set[str] | None = None,
208
+ **values: object,
209
+ ) -> ModelT:
210
+ m = __cls.__new__(__cls)
211
+ fields_values: dict[str, object] = {}
212
+
213
+ config = get_model_config(__cls)
214
+ populate_by_name = (
215
+ config.allow_population_by_field_name
216
+ if isinstance(config, _ConfigProtocol)
217
+ else config.get("populate_by_name")
218
+ )
219
+
220
+ if _fields_set is None:
221
+ _fields_set = set()
222
+
223
+ model_fields = get_model_fields(__cls)
224
+ for name, field in model_fields.items():
225
+ key = field.alias
226
+ if key is None or (key not in values and populate_by_name):
227
+ key = name
228
+
229
+ if key in values:
230
+ fields_values[name] = _construct_field(value=values[key], field=field, key=key)
231
+ _fields_set.add(name)
232
+ else:
233
+ fields_values[name] = field_get_default(field)
234
+
235
+ extra_field_type = _get_extra_fields_type(__cls)
236
+
237
+ _extra = {}
238
+ for key, value in values.items():
239
+ if key not in model_fields:
240
+ parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
241
+
242
+ if PYDANTIC_V1:
243
+ _fields_set.add(key)
244
+ fields_values[key] = parsed
245
+ else:
246
+ _extra[key] = parsed
247
+
248
+ object.__setattr__(m, "__dict__", fields_values)
249
+
250
+ if PYDANTIC_V1:
251
+ # init_private_attributes() does not exist in v2
252
+ m._init_private_attributes() # type: ignore
253
+
254
+ # copied from Pydantic v1's `construct()` method
255
+ object.__setattr__(m, "__fields_set__", _fields_set)
256
+ else:
257
+ # these properties are copied from Pydantic's `model_construct()` method
258
+ object.__setattr__(m, "__pydantic_private__", None)
259
+ object.__setattr__(m, "__pydantic_extra__", _extra)
260
+ object.__setattr__(m, "__pydantic_fields_set__", _fields_set)
261
+
262
+ return m
263
+
264
+ if not TYPE_CHECKING:
265
+ # type checkers incorrectly complain about this assignment
266
+ # because the type signatures are technically different
267
+ # although not in practice
268
+ model_construct = construct
269
+
270
+ if PYDANTIC_V1:
271
+ # we define aliases for some of the new pydantic v2 methods so
272
+ # that we can just document these methods without having to specify
273
+ # a specific pydantic version as some users may not know which
274
+ # pydantic version they are currently using
275
+
276
+ @override
277
+ def model_dump(
278
+ self,
279
+ *,
280
+ mode: Literal["json", "python"] | str = "python",
281
+ include: IncEx | None = None,
282
+ exclude: IncEx | None = None,
283
+ context: Any | None = None,
284
+ by_alias: bool | None = None,
285
+ exclude_unset: bool = False,
286
+ exclude_defaults: bool = False,
287
+ exclude_none: bool = False,
288
+ exclude_computed_fields: bool = False,
289
+ round_trip: bool = False,
290
+ warnings: bool | Literal["none", "warn", "error"] = True,
291
+ fallback: Callable[[Any], Any] | None = None,
292
+ serialize_as_any: bool = False,
293
+ ) -> dict[str, Any]:
294
+ """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
295
+
296
+ Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
297
+
298
+ Args:
299
+ mode: The mode in which `to_python` should run.
300
+ If mode is 'json', the output will only contain JSON serializable types.
301
+ If mode is 'python', the output may contain non-JSON-serializable Python objects.
302
+ include: A set of fields to include in the output.
303
+ exclude: A set of fields to exclude from the output.
304
+ context: Additional context to pass to the serializer.
305
+ by_alias: Whether to use the field's alias in the dictionary key if defined.
306
+ exclude_unset: Whether to exclude fields that have not been explicitly set.
307
+ exclude_defaults: Whether to exclude fields that are set to their default value.
308
+ exclude_none: Whether to exclude fields that have a value of `None`.
309
+ exclude_computed_fields: Whether to exclude computed fields.
310
+ While this can be useful for round-tripping, it is usually recommended to use the dedicated
311
+ `round_trip` parameter instead.
312
+ round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
313
+ warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
314
+ "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
315
+ fallback: A function to call when an unknown value is encountered. If not provided,
316
+ a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
317
+ serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
318
+
319
+ Returns:
320
+ A dictionary representation of the model.
321
+ """
322
+ if mode not in {"json", "python"}:
323
+ raise ValueError("mode must be either 'json' or 'python'")
324
+ if round_trip != False:
325
+ raise ValueError("round_trip is only supported in Pydantic v2")
326
+ if warnings != True:
327
+ raise ValueError("warnings is only supported in Pydantic v2")
328
+ if context is not None:
329
+ raise ValueError("context is only supported in Pydantic v2")
330
+ if serialize_as_any != False:
331
+ raise ValueError("serialize_as_any is only supported in Pydantic v2")
332
+ if fallback is not None:
333
+ raise ValueError("fallback is only supported in Pydantic v2")
334
+ if exclude_computed_fields != False:
335
+ raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
336
+ dumped = super().dict( # pyright: ignore[reportDeprecated]
337
+ include=include,
338
+ exclude=exclude,
339
+ by_alias=by_alias if by_alias is not None else False,
340
+ exclude_unset=exclude_unset,
341
+ exclude_defaults=exclude_defaults,
342
+ exclude_none=exclude_none,
343
+ )
344
+
345
+ return cast("dict[str, Any]", json_safe(dumped)) if mode == "json" else dumped
346
+
347
+ @override
348
+ def model_dump_json(
349
+ self,
350
+ *,
351
+ indent: int | None = None,
352
+ ensure_ascii: bool = False,
353
+ include: IncEx | None = None,
354
+ exclude: IncEx | None = None,
355
+ context: Any | None = None,
356
+ by_alias: bool | None = None,
357
+ exclude_unset: bool = False,
358
+ exclude_defaults: bool = False,
359
+ exclude_none: bool = False,
360
+ exclude_computed_fields: bool = False,
361
+ round_trip: bool = False,
362
+ warnings: bool | Literal["none", "warn", "error"] = True,
363
+ fallback: Callable[[Any], Any] | None = None,
364
+ serialize_as_any: bool = False,
365
+ ) -> str:
366
+ """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
367
+
368
+ Generates a JSON representation of the model using Pydantic's `to_json` method.
369
+
370
+ Args:
371
+ indent: Indentation to use in the JSON output. If None is passed, the output will be compact.
372
+ include: Field(s) to include in the JSON output. Can take either a string or set of strings.
373
+ exclude: Field(s) to exclude from the JSON output. Can take either a string or set of strings.
374
+ by_alias: Whether to serialize using field aliases.
375
+ exclude_unset: Whether to exclude fields that have not been explicitly set.
376
+ exclude_defaults: Whether to exclude fields that have the default value.
377
+ exclude_none: Whether to exclude fields that have a value of `None`.
378
+ round_trip: Whether to use serialization/deserialization between JSON and class instance.
379
+ warnings: Whether to show any warnings that occurred during serialization.
380
+
381
+ Returns:
382
+ A JSON string representation of the model.
383
+ """
384
+ if round_trip != False:
385
+ raise ValueError("round_trip is only supported in Pydantic v2")
386
+ if warnings != True:
387
+ raise ValueError("warnings is only supported in Pydantic v2")
388
+ if context is not None:
389
+ raise ValueError("context is only supported in Pydantic v2")
390
+ if serialize_as_any != False:
391
+ raise ValueError("serialize_as_any is only supported in Pydantic v2")
392
+ if fallback is not None:
393
+ raise ValueError("fallback is only supported in Pydantic v2")
394
+ if ensure_ascii != False:
395
+ raise ValueError("ensure_ascii is only supported in Pydantic v2")
396
+ if exclude_computed_fields != False:
397
+ raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
398
+ return super().json( # type: ignore[reportDeprecated]
399
+ indent=indent,
400
+ include=include,
401
+ exclude=exclude,
402
+ by_alias=by_alias if by_alias is not None else False,
403
+ exclude_unset=exclude_unset,
404
+ exclude_defaults=exclude_defaults,
405
+ exclude_none=exclude_none,
406
+ )
407
+
408
+
409
+ class _EagerIterable(list[_T], Generic[_T]):
410
+ """
411
+ Accepts any Iterable[T] input (including generators), consumes it
412
+ eagerly, and validates all items upfront.
413
+
414
+ Validation preserves the original container type where possible
415
+ (e.g. a set[T] stays a set[T]). Serialization (model_dump / JSON)
416
+ always emits a list — round-tripping through model_dump() will not
417
+ restore the original container type.
418
+ """
419
+
420
+ @classmethod
421
+ def __get_pydantic_core_schema__(
422
+ cls,
423
+ source_type: Any,
424
+ handler: GetCoreSchemaHandler,
425
+ ) -> CoreSchema:
426
+ (item_type,) = get_args(source_type) or (Any,)
427
+ item_schema: CoreSchema = handler.generate_schema(item_type)
428
+ list_of_items_schema: CoreSchema = core_schema.list_schema(item_schema)
429
+
430
+ return core_schema.no_info_wrap_validator_function(
431
+ cls._validate,
432
+ list_of_items_schema,
433
+ serialization=core_schema.plain_serializer_function_ser_schema(
434
+ cls._serialize,
435
+ info_arg=False,
436
+ ),
437
+ )
438
+
439
+ @staticmethod
440
+ def _validate(v: Iterable[_T], handler: "ValidatorFunctionWrapHandler") -> Any:
441
+ original_type: type[Any] = type(v)
442
+
443
+ # Normalize to list so list_schema can validate each item
444
+ if isinstance(v, list):
445
+ items: list[_T] = v
446
+ else:
447
+ try:
448
+ items = list(v)
449
+ except TypeError as e:
450
+ raise TypeError("Value is not iterable") from e
451
+
452
+ # Validate items against the inner schema
453
+ validated: list[_T] = handler(items)
454
+
455
+ # Reconstruct original container type
456
+ if original_type is list:
457
+ return validated
458
+ # str(list) produces the list's repr, not a string built from items,
459
+ # so skip reconstruction for str and its subclasses.
460
+ if issubclass(original_type, str):
461
+ return validated
462
+ try:
463
+ return original_type(validated)
464
+ except (TypeError, ValueError):
465
+ # If the type cannot be reconstructed, just return the validated list
466
+ return validated
467
+
468
+ @staticmethod
469
+ def _serialize(v: Iterable[_T]) -> list[_T]:
470
+ """Always serialize as a list so Pydantic's JSON encoder is happy."""
471
+ if isinstance(v, list):
472
+ return v
473
+ return list(v)
474
+
475
+
476
+ EagerIterable: TypeAlias = Annotated[Iterable[_T], _EagerIterable]
477
+
478
+
479
+ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
480
+ if value is None:
481
+ return field_get_default(field)
482
+
483
+ if PYDANTIC_V1:
484
+ type_ = cast(type, field.outer_type_) # type: ignore
485
+ else:
486
+ type_ = field.annotation # type: ignore
487
+
488
+ if type_ is None:
489
+ raise RuntimeError(f"Unexpected field type is None for {key}")
490
+
491
+ return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None))
492
+
493
+
494
+ def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
495
+ if PYDANTIC_V1:
496
+ # TODO
497
+ return None
498
+
499
+ schema = cls.__pydantic_core_schema__
500
+ if schema["type"] == "model":
501
+ fields = schema["schema"]
502
+ if fields["type"] == "model-fields":
503
+ extras = fields.get("extras_schema")
504
+ if extras and "cls" in extras:
505
+ # mypy can't narrow the type
506
+ return extras["cls"] # type: ignore[no-any-return]
507
+
508
+ return None
509
+
510
+
511
+ def is_basemodel(type_: type) -> bool:
512
+ """Returns whether or not the given type is either a `BaseModel` or a union of `BaseModel`"""
513
+ if is_union(type_):
514
+ for variant in get_args(type_):
515
+ if is_basemodel(variant):
516
+ return True
517
+
518
+ return False
519
+
520
+ return is_basemodel_type(type_)
521
+
522
+
523
+ def is_basemodel_type(type_: type) -> TypeGuard[type[BaseModel] | type[GenericModel]]:
524
+ origin = get_origin(type_) or type_
525
+ if not inspect.isclass(origin):
526
+ return False
527
+ return issubclass(origin, BaseModel) or issubclass(origin, GenericModel)
528
+
529
+
530
+ def build(
531
+ base_model_cls: Callable[P, _BaseModelT],
532
+ *args: P.args,
533
+ **kwargs: P.kwargs,
534
+ ) -> _BaseModelT:
535
+ """Construct a BaseModel class without validation.
536
+
537
+ This is useful for cases where you need to instantiate a `BaseModel`
538
+ from an API response as this provides type-safe params which isn't supported
539
+ by helpers like `construct_type()`.
540
+
541
+ ```py
542
+ build(MyModel, my_field_a="foo", my_field_b=123)
543
+ ```
544
+ """
545
+ if args:
546
+ raise TypeError(
547
+ "Received positional arguments which are not supported; Keyword arguments must be used instead",
548
+ )
549
+
550
+ return cast(_BaseModelT, construct_type(type_=base_model_cls, value=kwargs))
551
+
552
+
553
+ def construct_type_unchecked(*, value: object, type_: type[_T]) -> _T:
554
+ """Loose coercion to the expected type with construction of nested values.
555
+
556
+ Note: the returned value from this function is not guaranteed to match the
557
+ given type.
558
+ """
559
+ return cast(_T, construct_type(value=value, type_=type_))
560
+
561
+
562
+ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]] = None) -> object:
563
+ """Loose coercion to the expected type with construction of nested values.
564
+
565
+ If the given value does not match the expected type then it is returned as-is.
566
+ """
567
+
568
+ # store a reference to the original type we were given before we extract any inner
569
+ # types so that we can properly resolve forward references in `TypeAliasType` annotations
570
+ original_type = None
571
+
572
+ # we allow `object` as the input type because otherwise, passing things like
573
+ # `Literal['value']` will be reported as a type error by type checkers
574
+ type_ = cast("type[object]", type_)
575
+ if is_type_alias_type(type_):
576
+ original_type = type_ # type: ignore[unreachable]
577
+ type_ = type_.__value__ # type: ignore[unreachable]
578
+
579
+ # unwrap `Annotated[T, ...]` -> `T`
580
+ if metadata is not None and len(metadata) > 0:
581
+ meta: tuple[Any, ...] = tuple(metadata)
582
+ elif is_annotated_type(type_):
583
+ meta = get_args(type_)[1:]
584
+ type_ = extract_type_arg(type_, 0)
585
+ else:
586
+ meta = tuple()
587
+
588
+ # we need to use the origin class for any types that are subscripted generics
589
+ # e.g. Dict[str, object]
590
+ origin = get_origin(type_) or type_
591
+ args = get_args(type_)
592
+
593
+ if is_union(origin):
594
+ try:
595
+ return validate_type(type_=cast("type[object]", original_type or type_), value=value)
596
+ except Exception:
597
+ pass
598
+
599
+ # if the type is a discriminated union then we want to construct the right variant
600
+ # in the union, even if the data doesn't match exactly, otherwise we'd break code
601
+ # that relies on the constructed class types, e.g.
602
+ #
603
+ # class FooType:
604
+ # kind: Literal['foo']
605
+ # value: str
606
+ #
607
+ # class BarType:
608
+ # kind: Literal['bar']
609
+ # value: int
610
+ #
611
+ # without this block, if the data we get is something like `{'kind': 'bar', 'value': 'foo'}` then
612
+ # we'd end up constructing `FooType` when it should be `BarType`.
613
+ discriminator = _build_discriminated_union_meta(union=type_, meta_annotations=meta)
614
+ if discriminator and is_mapping(value):
615
+ variant_value = value.get(discriminator.field_alias_from or discriminator.field_name)
616
+ if variant_value and isinstance(variant_value, str):
617
+ variant_type = discriminator.mapping.get(variant_value)
618
+ if variant_type:
619
+ return construct_type(type_=variant_type, value=value)
620
+
621
+ # if the data is not valid, use the first variant that doesn't fail while deserializing
622
+ for variant in args:
623
+ try:
624
+ return construct_type(value=value, type_=variant)
625
+ except Exception:
626
+ continue
627
+
628
+ raise RuntimeError(f"Could not convert data into a valid instance of {type_}")
629
+
630
+ if origin == dict:
631
+ if not is_mapping(value):
632
+ return value
633
+
634
+ _, items_type = get_args(type_) # Dict[_, items_type]
635
+ return {key: construct_type(value=item, type_=items_type) for key, item in value.items()}
636
+
637
+ if (
638
+ not is_literal_type(type_)
639
+ and inspect.isclass(origin)
640
+ and (issubclass(origin, BaseModel) or issubclass(origin, GenericModel))
641
+ ):
642
+ if is_list(value):
643
+ return [cast(Any, type_).construct(**entry) if is_mapping(entry) else entry for entry in value]
644
+
645
+ if is_mapping(value):
646
+ if issubclass(type_, BaseModel):
647
+ return type_.construct(**value) # type: ignore[arg-type]
648
+
649
+ return cast(Any, type_).construct(**value)
650
+
651
+ if origin == list:
652
+ if not is_list(value):
653
+ return value
654
+
655
+ inner_type = args[0] # List[inner_type]
656
+ return [construct_type(value=entry, type_=inner_type) for entry in value]
657
+
658
+ if origin == float:
659
+ if isinstance(value, int):
660
+ coerced = float(value)
661
+ if coerced != value:
662
+ return value
663
+ return coerced
664
+
665
+ return value
666
+
667
+ if type_ == datetime:
668
+ try:
669
+ return parse_datetime(value) # type: ignore
670
+ except Exception:
671
+ return value
672
+
673
+ if type_ == date:
674
+ try:
675
+ return parse_date(value) # type: ignore
676
+ except Exception:
677
+ return value
678
+
679
+ return value
680
+
681
+
682
+ @runtime_checkable
683
+ class CachedDiscriminatorType(Protocol):
684
+ __discriminator__: DiscriminatorDetails
685
+
686
+
687
+ DISCRIMINATOR_CACHE: weakref.WeakKeyDictionary[type, DiscriminatorDetails] = weakref.WeakKeyDictionary()
688
+
689
+
690
+ class DiscriminatorDetails:
691
+ field_name: str
692
+ """The name of the discriminator field in the variant class, e.g.
693
+
694
+ ```py
695
+ class Foo(BaseModel):
696
+ type: Literal['foo']
697
+ ```
698
+
699
+ Will result in field_name='type'
700
+ """
701
+
702
+ field_alias_from: str | None
703
+ """The name of the discriminator field in the API response, e.g.
704
+
705
+ ```py
706
+ class Foo(BaseModel):
707
+ type: Literal['foo'] = Field(alias='type_from_api')
708
+ ```
709
+
710
+ Will result in field_alias_from='type_from_api'
711
+ """
712
+
713
+ mapping: dict[str, type]
714
+ """Mapping of discriminator value to variant type, e.g.
715
+
716
+ {'foo': FooVariant, 'bar': BarVariant}
717
+ """
718
+
719
+ def __init__(
720
+ self,
721
+ *,
722
+ mapping: dict[str, type],
723
+ discriminator_field: str,
724
+ discriminator_alias: str | None,
725
+ ) -> None:
726
+ self.mapping = mapping
727
+ self.field_name = discriminator_field
728
+ self.field_alias_from = discriminator_alias
729
+
730
+
731
+ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, ...]) -> DiscriminatorDetails | None:
732
+ cached = DISCRIMINATOR_CACHE.get(union)
733
+ if cached is not None:
734
+ return cached
735
+
736
+ discriminator_field_name: str | None = None
737
+
738
+ for annotation in meta_annotations:
739
+ if isinstance(annotation, PropertyInfo) and annotation.discriminator is not None:
740
+ discriminator_field_name = annotation.discriminator
741
+ break
742
+
743
+ if not discriminator_field_name:
744
+ return None
745
+
746
+ mapping: dict[str, type] = {}
747
+ discriminator_alias: str | None = None
748
+
749
+ for variant in get_args(union):
750
+ variant = strip_annotated_type(variant)
751
+ if is_basemodel_type(variant):
752
+ if PYDANTIC_V1:
753
+ field_info = cast("dict[str, FieldInfo]", variant.__fields__).get(discriminator_field_name) # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
754
+ if not field_info:
755
+ continue
756
+
757
+ # Note: if one variant defines an alias then they all should
758
+ discriminator_alias = field_info.alias
759
+
760
+ if (annotation := getattr(field_info, "annotation", None)) and is_literal_type(annotation):
761
+ for entry in get_args(annotation):
762
+ if isinstance(entry, str):
763
+ mapping[entry] = variant
764
+ else:
765
+ field = _extract_field_schema_pv2(variant, discriminator_field_name)
766
+ if not field:
767
+ continue
768
+
769
+ # Note: if one variant defines an alias then they all should
770
+ discriminator_alias = field.get("serialization_alias")
771
+
772
+ field_schema = field["schema"]
773
+
774
+ if field_schema["type"] == "literal":
775
+ for entry in cast("LiteralSchema", field_schema)["expected"]:
776
+ if isinstance(entry, str):
777
+ mapping[entry] = variant
778
+
779
+ if not mapping:
780
+ return None
781
+
782
+ details = DiscriminatorDetails(
783
+ mapping=mapping,
784
+ discriminator_field=discriminator_field_name,
785
+ discriminator_alias=discriminator_alias,
786
+ )
787
+ DISCRIMINATOR_CACHE.setdefault(union, details)
788
+ return details
789
+
790
+
791
+ def _extract_field_schema_pv2(model: type[BaseModel], field_name: str) -> ModelField | None:
792
+ schema = model.__pydantic_core_schema__
793
+ if schema["type"] == "definitions":
794
+ schema = schema["schema"]
795
+
796
+ if schema["type"] != "model":
797
+ return None
798
+
799
+ schema = cast("ModelSchema", schema)
800
+ fields_schema = schema["schema"]
801
+ if fields_schema["type"] != "model-fields":
802
+ return None
803
+
804
+ fields_schema = cast("ModelFieldsSchema", fields_schema)
805
+ field = fields_schema["fields"].get(field_name)
806
+ if not field:
807
+ return None
808
+
809
+ return cast("ModelField", field) # pyright: ignore[reportUnnecessaryCast]
810
+
811
+
812
+ def validate_type(*, type_: type[_T], value: object) -> _T:
813
+ """Strict validation that the given value matches the expected type"""
814
+ if inspect.isclass(type_) and issubclass(type_, pydantic.BaseModel):
815
+ return cast(_T, parse_obj(type_, value))
816
+
817
+ return cast(_T, _validate_non_model_type(type_=type_, value=value))
818
+
819
+
820
+ def set_pydantic_config(typ: Any, config: pydantic.ConfigDict) -> None:
821
+ """Add a pydantic config for the given type.
822
+
823
+ Note: this is a no-op on Pydantic v1.
824
+ """
825
+ setattr(typ, "__pydantic_config__", config) # noqa: B010
826
+
827
+
828
+ # our use of subclassing here causes weirdness for type checkers,
829
+ # so we just pretend that we don't subclass
830
+ if TYPE_CHECKING:
831
+ GenericModel = BaseModel
832
+ else:
833
+
834
+ class GenericModel(BaseGenericModel, BaseModel):
835
+ pass
836
+
837
+
838
+ if not PYDANTIC_V1:
839
+ from pydantic import TypeAdapter as _TypeAdapter
840
+
841
+ _CachedTypeAdapter = cast("TypeAdapter[object]", lru_cache(maxsize=None)(_TypeAdapter))
842
+
843
+ if TYPE_CHECKING:
844
+ from pydantic import TypeAdapter
845
+ else:
846
+ TypeAdapter = _CachedTypeAdapter
847
+
848
+ def _validate_non_model_type(*, type_: type[_T], value: object) -> _T:
849
+ return TypeAdapter(type_).validate_python(value)
850
+
851
+ elif not TYPE_CHECKING: # TODO: condition is weird
852
+
853
+ class RootModel(GenericModel, Generic[_T]):
854
+ """Used as a placeholder to easily convert runtime types to a Pydantic format
855
+ to provide validation.
856
+
857
+ For example:
858
+ ```py
859
+ validated = RootModel[int](__root__="5").__root__
860
+ # validated: 5
861
+ ```
862
+ """
863
+
864
+ __root__: _T
865
+
866
+ def _validate_non_model_type(*, type_: type[_T], value: object) -> _T:
867
+ model = _create_pydantic_model(type_).validate(value)
868
+ return cast(_T, model.__root__)
869
+
870
+ def _create_pydantic_model(type_: _T) -> Type[RootModel[_T]]:
871
+ return RootModel[type_] # type: ignore
872
+
873
+
874
+ class SecurityOptions(TypedDict, total=False):
875
+ public_key: bool
876
+ secret_key: bool
877
+ admin_key: bool
878
+
879
+
880
+ class FinalRequestOptionsInput(TypedDict, total=False):
881
+ method: Required[str]
882
+ url: Required[str]
883
+ params: Query
884
+ headers: Headers
885
+ max_retries: int
886
+ timeout: float | Timeout | None
887
+ files: HttpxRequestFiles | None
888
+ idempotency_key: str
889
+ content: Union[bytes, bytearray, IO[bytes], Iterable[bytes], AsyncIterable[bytes], None]
890
+ json_data: Body
891
+ extra_json: AnyMapping
892
+ follow_redirects: bool
893
+ security: SecurityOptions
894
+
895
+
896
+ @final
897
+ class FinalRequestOptions(pydantic.BaseModel):
898
+ method: str
899
+ url: str
900
+ params: Query = {}
901
+ headers: Union[Headers, NotGiven] = NotGiven()
902
+ max_retries: Union[int, NotGiven] = NotGiven()
903
+ timeout: Union[float, Timeout, None, NotGiven] = NotGiven()
904
+ files: Union[HttpxRequestFiles, None] = None
905
+ idempotency_key: Union[str, None] = None
906
+ post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven()
907
+ follow_redirects: Union[bool, None] = None
908
+ security: SecurityOptions = {
909
+ "public_key": True,
910
+ "secret_key": True,
911
+ "admin_key": True,
912
+ }
913
+
914
+ content: Union[bytes, bytearray, IO[bytes], Iterable[bytes], AsyncIterable[bytes], None] = None
915
+ # It should be noted that we cannot use `json` here as that would override
916
+ # a BaseModel method in an incompatible fashion.
917
+ json_data: Union[Body, None] = None
918
+ extra_json: Union[AnyMapping, None] = None
919
+
920
+ if PYDANTIC_V1:
921
+
922
+ class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
923
+ arbitrary_types_allowed: bool = True
924
+ else:
925
+ model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
926
+
927
+ def get_max_retries(self, max_retries: int) -> int:
928
+ if isinstance(self.max_retries, NotGiven):
929
+ return max_retries
930
+ return self.max_retries
931
+
932
+ def _strip_raw_response_header(self) -> None:
933
+ if not is_given(self.headers):
934
+ return
935
+
936
+ if self.headers.get(RAW_RESPONSE_HEADER):
937
+ self.headers = {**self.headers}
938
+ self.headers.pop(RAW_RESPONSE_HEADER)
939
+
940
+ # override the `construct` method so that we can run custom transformations.
941
+ # this is necessary as we don't want to do any actual runtime type checking
942
+ # (which means we can't use validators) but we do want to ensure that `NotGiven`
943
+ # values are not present
944
+ #
945
+ # type ignore required because we're adding explicit types to `**values`
946
+ @classmethod
947
+ def construct( # type: ignore
948
+ cls,
949
+ _fields_set: set[str] | None = None,
950
+ **values: Unpack[FinalRequestOptionsInput],
951
+ ) -> FinalRequestOptions:
952
+ kwargs: dict[str, Any] = {
953
+ # we unconditionally call `strip_not_given` on any value
954
+ # as it will just ignore any non-mapping types
955
+ key: strip_not_given(value)
956
+ for key, value in values.items()
957
+ }
958
+ if PYDANTIC_V1:
959
+ return cast(FinalRequestOptions, super().construct(_fields_set, **kwargs)) # pyright: ignore[reportDeprecated]
960
+ return super().model_construct(_fields_set, **kwargs)
961
+
962
+ if not TYPE_CHECKING:
963
+ # type checkers incorrectly complain about this assignment
964
+ model_construct = construct