!!! abstract "Usage Documentation" [`model_dump`](../concepts/serialization.md#python-mode) 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,
polymorphic_serialization: bool | None = None,
)
| 425 | return copied |
| 426 | |
| 427 | def model_dump( |
| 428 | self, |
| 429 | *, |
| 430 | mode: Literal[&class="cm">#x27;jsonclass="st">', 'pythonclass="st">'] | str = 'python', |
| 431 | include: IncEx | None = None, |
| 432 | exclude: IncEx | None = None, |
| 433 | context: Any | None = None, |
| 434 | by_alias: bool | None = None, |
| 435 | exclude_unset: bool = False, |
| 436 | exclude_defaults: bool = False, |
| 437 | exclude_none: bool = False, |
| 438 | exclude_computed_fields: bool = False, |
| 439 | round_trip: bool = False, |
| 440 | warnings: bool | Literal[&class="cm">#x27;noneclass="st">', 'warnclass="st">', 'error'] = True, |
| 441 | fallback: Callable[[Any], Any] | None = None, |
| 442 | serialize_as_any: bool = False, |
| 443 | polymorphic_serialization: bool | None = None, |
| 444 | ) -> dict[str, Any]: |
| 445 | class="st">""class="st">"!!! abstract "Usage Documentation" |
| 446 | [`model_dump`](../concepts/serialization.mdclass="cm">#python-mode) |
| 447 | |
| 448 | Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. |
| 449 | |
| 450 | Args: |
| 451 | mode: The mode in which `to_python` should run. |
| 452 | If mode is &class="cm">#x27;json', the output will only contain JSON serializable types. |
| 453 | If mode is &class="cm">#x27;python', the output may contain non-JSON-serializable Python objects. |
| 454 | include: A set of fields to include in the output. |
| 455 | exclude: A set of fields to exclude from the output. |
| 456 | context: Additional context to pass to the serializer. |
| 457 | by_alias: Whether to use the field&class="cm">#x27;s alias in the dictionary key if defined. |
| 458 | exclude_unset: Whether to exclude fields that have not been explicitly set. |
| 459 | exclude_defaults: Whether to exclude fields that are set to their default value. |
| 460 | exclude_none: Whether to exclude fields that have a value of `None`. |
| 461 | exclude_computed_fields: Whether to exclude computed fields. |
| 462 | While this can be useful for round-tripping, it is usually recommended to use the dedicated |
| 463 | `round_trip` parameter instead. |
| 464 | round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
| 465 | warnings: How to handle serialization errors. False/class="st">"none" ignores them, True/class="st">"warn" logs errors, |
| 466 | class="st">"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError]. |
| 467 | fallback: A function to call when an unknown value is encountered. If not provided, |
| 468 | a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised. |
| 469 | serialize_as_any: Whether to serialize fields with duck-typing serialization behavior. |
| 470 | polymorphic_serialization: Whether to use model and dataclass polymorphic serialization for this call. |
| 471 | |
| 472 | Returns: |
| 473 | A dictionary representation of the model. |
| 474 | class="st">""" |
| 475 | return self.__pydantic_serializer__.to_python( |
| 476 | self, |
| 477 | mode=mode, |
| 478 | by_alias=by_alias, |
| 479 | include=include, |
| 480 | exclude=exclude, |
| 481 | context=context, |
| 482 | exclude_unset=exclude_unset, |
| 483 | exclude_defaults=exclude_defaults, |
| 484 | exclude_none=exclude_none, |
no outgoing calls