Paper Office
paper-pptxAPI referenceopc.package

_Relationships

paper-pptx 0.2.0 API reference

Collection of _Relationship instances having dict semantics.

Relationships are keyed by their rId, but may also be found in other ways, such as by their relationship type. Relationship objects are keyed by their rId.

Iterating this collection has normal mapping semantics, generating the keys (rIds) of the mapping. rels.keys(), rels.values(), and rels.items() can be used as they would be for a dict`.

_Relationships(base_uri: str)

Attributes

xml

attributexml

bytes XML serialization of this relationship collection.

This value is suitable for storage as a .rels file in an OPC package. Includes a <?xml.. declaration header with encoding as UTF-8.

Functions

__contains__

func__contains__(rId: object) -> bool

Implement 'in' operation, like "rId7" in relationships.

paramrIdobject

Returns

bool

__getitem__

func__getitem__(rId: str) -> _Relationship

Implement relationship lookup by rId using indexed access, like rels[rId].

paramrIdstr

Returns

pptx.opc.package._Relationship

__iter__

func__iter__() -> Iterator[str]

Implement iteration of rIds (iterating a mapping produces its keys).

Returns

typing.Iterator[str]

__len__

func__len__() -> int

Return count of relationships in collection.

Returns

int

get_or_add

funcget_or_add(reltype: str, target_part: Part) -> str

Return str rId of reltype to target_part.

The rId of an existing matching relationship is used if present. Otherwise, a new relationship is added and that rId is returned.

paramreltypestr
paramtarget_partPart

Returns

str

get_or_add_ext_rel

funcget_or_add_ext_rel(reltype: str, target_ref: str) -> str

Return str rId of external relationship of reltype to target_ref.

The rId of an existing matching relationship is used if present. Otherwise, a new relationship is added and that rId is returned.

paramreltypestr
paramtarget_refstr

Returns

str

load_from_xml

funcload_from_xml(base_uri: str, xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> None

Replace any relationships in this collection with those from xml_rels.

parambase_uristr
paramxml_relsCT_Relationships
parampartsdict[PackURI, Part]

Returns

None

part_with_reltype

funcpart_with_reltype(reltype: str) -> Part

Return target part of relationship with matching reltype.

Raises KeyError if not found and ValueError if more than one matching relationship is found.

paramreltypestr

Returns

pptx.opc.package.Part

pop

funcpop(rId: str) -> _Relationship

Return _Relationship identified by rId after removing it from collection.

The caller is responsible for ensuring it is no longer required.

paramrIdstr

Returns

pptx.opc.package._Relationship

On this page