Package
paper-pptx 0.2.0 API reference
An overall .pptx package.
Attributes
core_properties
attributecore_propertiesCorePropertiesPartInstance of CoreProperties holding read/write Dublin Core doc properties.
Creates a default core properties part if one is not present (not common).
main_document_part
attributemain_document_partPresentationPartReturn Part subtype serving as the main document part for this package.
In this case it will be a Presentation part.
presentation_part
attributepresentation_partReference to the Presentation instance contained in this package.
Functions
drop_rel
funcdrop_rel(rId: str) -> NoneRemove relationship identified by rId.
paramrIdstrReturns
Noneget_or_add_image_part
funcget_or_add_image_part(image_file: str | IO[bytes])Return an ImagePart object containing the image in image_file. If
the image part already exists in this package, it is reused,
otherwise a new one is created.
paramimage_filestr | IO[bytes]get_or_add_media_part
funcget_or_add_media_part(media)Return a MediaPart object containing the media in media.
If a media part for this media bytestream ("file") is already present in this package, it is reused, otherwise a new one is created.
parammediaiter_parts
funciter_parts() -> Iterator[Part]Generate exactly one reference to each part in the package.
Returns
typing.Iterator[pptx.opc.package.Part]iter_rels
funciter_rels() -> Iterator[_Relationship]Generate exactly one reference to each relationship in package.
Performs a depth-first traversal of the rels graph.
Returns
typing.Iterator[pptx.opc.package._Relationship]next_image_partname
funcnext_image_partname(ext: str) -> PackURIReturn a PackURI instance representing the next available image partname.
Partname uses the next available sequence number. ext is used as the extention on the returned partname.
paramextstrReturns
pptx.opc.packuri.PackURInext_media_partname
funcnext_media_partname(ext)Return PackURI instance for next available media partname.
Partname is first available, starting at sequence number 1. Empty sequence numbers are reused. ext is used as the extension on the returned partname.
paramextnext_partname
funcnext_partname(tmpl: str) -> PackURIReturn PackURI next available partname matching tmpl.
tmpl is a printf (%)-style template string containing a single replacement item, a '%d'
to be used to insert the integer portion of the partname. Example:
'/ppt/slides/slide%d.xml'
paramtmplstrReturns
pptx.opc.packuri.PackURIopen
funcopen(pkg_file: str | IO[bytes]) -> SelfReturn an OpcPackage instance loaded with the contents of pkg_file.
parampkg_filestr | IO[bytes]Returns
typing_extensions.Selfpart_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.Partsave
funcsave(pkg_file: str | IO[bytes]) -> NoneSave this package to pkg_file.
pkg_file can be a filesystem path (str or os.PathLike) or a file-like object open
for writing bytes.
A path destination is written atomically: the package is serialized into a temporary
file in the destination's directory and moved into place with os.replace(), so a
failure part-way through leaves any existing file untouched. Symlinks are resolved, so
the file a link names is the file that is written.
A stream destination is serialized into a private staging buffer and then written
straight through, so no bytes reach the stream unless the whole package serialized. Only
write is required of the stream. The package is written at the stream's current
position; past that, bytes beyond the package are the caller's and are left alone.
What a failure during that copy costs depends on what the destination supports. One
that can be read, rewound and truncated has its prior contents and cursor restored, and
if that restore itself fails the original error is replaced by a RuntimeError carrying
it as __cause__. A write-only or unseekable sink keeps whatever partial package landed;
a caller writing to a pipe cannot expect otherwise. The same capability decides
truncation: a readable stream positioned at the start is truncated to the package, so no
tail of a previous document survives, while a write-only stream keeps that tail.
Atomic path writes are a deliberate departure from the v0 rule that save() behavior is
unchanged from upstream, accepted because upstream serialized directly into the
destination, so a mid-write failure on the ordinary prs.save(same_path) pattern
destroyed the deck being edited, irrecoverably.
The costs of replacing rather than overwriting: owner, group, ACLs, extended attributes and hard links do not survive (mode bits are carried over), and the destination's directory must be writable, not just the file.
parampkg_filestr | IO[bytes]Returns
Nonetarget_ref
functarget_ref(rId: str) -> strReturn URL contained in target ref of relationship identified by rId.
paramrIdstrReturns
str