Developer Interface#
pydantic xml serialization/deserialization extension
- class pydantic_xml.BaseXmlModel[source]#
Bases:
BaseModel
Base pydantic-xml model.
- classmethod model_rebuild(**kwargs)[source]#
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Args:
force: Whether to force the rebuilding of the model schema, defaults to False. raise_errors: Whether to raise errors, defaults to True. _parent_namespace_depth: The depth level of the parent namespace, defaults to 2. _types_namespace: The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Parameters:
kwargs (Any) –
- Return type:
None
- classmethod from_xml_tree(root, context=None)[source]#
Deserializes an xml element tree to an object of cls type.
- classmethod from_xml(source, context=None)[source]#
Deserializes an xml string to an object of cls type.
- to_xml_tree(*, skip_empty=False)[source]#
Serializes the object to an xml tree.
- Parameters:
skip_empty (bool) – skip empty elements (elements without sub-elements, attributes and text, Nones)
- Returns:
object xml representation
- Return type:
Element
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pydantic_xml.RootXmlModel(root=PydanticUndefined)[source]#
Bases:
RootModel[~RootModelRootType]
,BaseXmlModel
,Generic
[RootModelRootType
]Base pydantic-xml root model.
- Parameters:
root (RootModelRootType) –
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- pydantic_xml.attr(name=None, ns=None, **kwargs)[source]#
Marks a pydantic field as an xml attribute.
- pydantic_xml.element(tag=None, ns=None, nsmap=None, nillable=False, **kwargs)[source]#
Marks a pydantic field as an xml element.
- Parameters:
- Return type:
- pydantic_xml.wrapped(path, entity=None, ns=None, nsmap=None, **kwargs)[source]#
Marks a pydantic field as a wrapped xml entity.
- pydantic_xml.computed_attr(prop=None, *, name=None, ns=None, **kwargs)[source]#
Marks a property as an xml attribute.
- pydantic_xml.computed_element(prop=None, *, tag=None, ns=None, nsmap=None, nillable=False, **kwargs)[source]#
Marks a property as an xml element.