MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / model_dump

Method model_dump

src/anthropic/_models.py:293–361  ·  view source on GitHub ↗

Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. Args: mode: The mode in which `to_python` should run.

(
            self,
            *,
            mode: Literal["json", "python"] | str = "python",
            include: IncEx | None = None,
            exclude: IncEx | None = None,
            context: Any | None = None,
            by_alias: bool | None = None,
            exclude_unset: bool = False,
            exclude_defaults: bool = False,
            exclude_none: bool = False,
            exclude_computed_fields: bool = False,
            round_trip: bool = False,
            warnings: bool | Literal["none", "warn", "error"] = True,
            fallback: Callable[[Any], Any] | None = None,
            serialize_as_any: bool = False,
        )

Source from the content-addressed store, hash-verified

291
292 @override
293 def model_dump(
294 self,
295 *,
296 mode: Literal["json", "python"] | str = "python",
297 include: IncEx | None = None,
298 exclude: IncEx | None = None,
299 context: Any | None = None,
300 by_alias: bool | None = None,
301 exclude_unset: bool = False,
302 exclude_defaults: bool = False,
303 exclude_none: bool = False,
304 exclude_computed_fields: bool = False,
305 round_trip: bool = False,
306 warnings: bool | Literal["none", "warn", "error"] = True,
307 fallback: Callable[[Any], Any] | None = None,
308 serialize_as_any: bool = False,
309 ) -> dict[str, Any]:
310 """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
311
312 Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
313
314 Args:
315 mode: The mode in which `to_python` should run.
316 If mode is 'json', the output will only contain JSON serializable types.
317 If mode is 'python', the output may contain non-JSON-serializable Python objects.
318 include: A set of fields to include in the output.
319 exclude: A set of fields to exclude from the output.
320 context: Additional context to pass to the serializer.
321 by_alias: Whether to use the field's alias in the dictionary key if defined.
322 exclude_unset: Whether to exclude fields that have not been explicitly set.
323 exclude_defaults: Whether to exclude fields that are set to their default value.
324 exclude_none: Whether to exclude fields that have a value of `None`.
325 exclude_computed_fields: Whether to exclude computed fields.
326 While this can be useful for round-tripping, it is usually recommended to use the dedicated
327 `round_trip` parameter instead.
328 round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
329 warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
330 "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
331 fallback: A function to call when an unknown value is encountered. If not provided,
332 a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
333 serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
334
335 Returns:
336 A dictionary representation of the model.
337 """
338 if mode not in {"json", "python"}:
339 raise ValueError("mode must be either 'json' or 'python'")
340 if round_trip != False:
341 raise ValueError("round_trip is only supported in Pydantic v2")
342 if warnings != True:
343 raise ValueError("warnings is only supported in Pydantic v2")
344 if context is not None:
345 raise ValueError("context is only supported in Pydantic v2")
346 if serialize_as_any != False:
347 raise ValueError("serialize_as_any is only supported in Pydantic v2")
348 if fallback is not None:
349 raise ValueError("fallback is only supported in Pydantic v2")
350 if exclude_computed_fields != False:

Callers 15

to_dictMethod · 0.95
model_dumpFunction · 0.80
accumulate_eventFunction · 0.80
test_text_resourceMethod · 0.80
test_pdf_resourceMethod · 0.80
test_image_resourceMethod · 0.80
test_text_resourceMethod · 0.80

Calls 1

json_safeFunction · 0.85