rel
rel
¶
Relationship-related objects.
_RelatedParts
¶
Bases: Dict[str, 'Part']
Mapping of rId to target part, reporting an unresolvable rId usefully.
A reference to an rId that has no target part is what a document looks like after a
relationship to a missing part has been dropped on load: the w:drawing (or other
referring element) is still there, but its rId no longer resolves. Subclasses dict
and raises KeyError, so existing handling is unaffected; only the message
improves.
Relationships
¶
Bases: Dict[str, '_Relationship']
Collection object for _Relationship instances, having list semantics.
Source code in src/docx/opc/rel.py
related_parts
property
¶
Dict mapping rIds to target parts for all the internal relationships in the collection.
xml
property
¶
Serialize this relationship collection into XML suitable for storage as a .rels file in an OPC package.
add_relationship
¶
add_relationship(
reltype: str,
target: Part | str,
rId: str,
is_external: bool = False,
) -> "_Relationship"
Return a newly added _Relationship instance.
Source code in src/docx/opc/rel.py
get_or_add
¶
get_or_add(
reltype: str, target_part: Part
) -> _Relationship
Return relationship of reltype to target_part, newly added if not already
present in collection.
Source code in src/docx/opc/rel.py
get_or_add_ext_rel
¶
Return rId of external relationship of reltype to target_ref, newly added
if not already present in collection.