Part
paper-pptx 0.2.0 API reference
Base class for package parts.
Provides common properties and methods, but intended to be subclassed in client code to implement specific part behaviors. Also serves as the default class for parts that are not yet given specific behaviors.
Part(partname: PackURI, content_type: str, package: Package, blob: bytes | None = None)Attributes
blob
attributeblobbytesContents of this package part as a sequence of bytes.
Intended to be overridden by subclasses. Default behavior is to return the blob initial
loaded during Package.open() operation.
content_type
attributecontent_typestrContent-type (MIME-type) of this part.
package
attributepackagePackagePackage this part belongs to.
partname
attributepartnamePackURIPackURI partname for this part, e.g. "/ppt/slides/slide1.xml".
rels
attributerels_RelationshipsCollection of relationships from this part to other parts.
Functions
load
funcload(partname: PackURI, content_type: str, package: Package, blob: bytes) -> SelfReturn cls instance loaded from arguments.
This one is a straight pass-through, but subtypes may do some pre-processing, see XmlPart for an example.
parampartnamePackURIparamcontent_typestrparampackagePackageparamblobbytesReturns
typing_extensions.Selfload_rels_from_xml
funcload_rels_from_xml(xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> Noneload _Relationships for this part from xml_rels.
Part references are resolved using the parts dict that maps each partname to the loaded
part with that partname. These relationships are loaded from a serialized package and so
already have assigned rIds. This method is only used during package loading.
paramxml_relsCT_Relationshipsparampartsdict[PackURI, Part]Returns
Nonepart_related_by
funcpart_related_by(reltype: str) -> PartReturn (single) part having relationship to this package of reltype.
Raises KeyError if no such relationship is found and ValueError if more than one such
relationship is found.
paramreltypestrReturns
pptx.opc.package.Partrelate_to
funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> strReturn rId key of relationship of reltype to target.
If such a relationship already exists, its rId is returned. Otherwise the relationship is added and its new rId returned.
paramtargetPart | strparamreltypestrparamis_externalbool= FalseReturns
strrelated_part
funcrelated_part(rId: str) -> PartReturn related Part subtype identified by rId.
paramrIdstrReturns
pptx.opc.package.Parttarget_ref
functarget_ref(rId: str) -> strReturn URL contained in target ref of relationship identified by rId.
paramrIdstrReturns
str