Paper Office
paper-pptxAPI referencepackage

Package

paper-pptx 0.2.0 API reference

An overall .pptx package.

Attributes

core_properties

attributecore_propertiesCorePropertiesPart

Instance 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_partPresentationPart

Return Part subtype serving as the main document part for this package.

In this case it will be a Presentation part.

presentation_part

attributepresentation_part

Reference to the Presentation instance contained in this package.

Functions

drop_rel

funcdrop_rel(rId: str) -> None

Remove relationship identified by rId.

paramrIdstr

Returns

None

get_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.

parammedia

iter_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) -> PackURI

Return 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.

paramextstr

Returns

pptx.opc.packuri.PackURI

next_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.

paramext

next_partname

funcnext_partname(tmpl: str) -> PackURI

Return 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'

paramtmplstr

Returns

pptx.opc.packuri.PackURI

open

funcopen(pkg_file: str | IO[bytes]) -> Self

Return an OpcPackage instance loaded with the contents of pkg_file.

parampkg_filestr | IO[bytes]

Returns

typing_extensions.Self
funcpart_related_by(reltype: str) -> Part

Return (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.

paramreltypestr

Returns

pptx.opc.package.Part

relate_to

funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> str

Return 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 | str
paramreltypestr
paramis_externalbool
= False

Returns

str
funcrelated_part(rId: str) -> Part

Return related Part subtype identified by rId.

paramrIdstr

Returns

pptx.opc.package.Part

save

funcsave(pkg_file: str | IO[bytes]) -> None

Save 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

None

target_ref

functarget_ref(rId: str) -> str

Return URL contained in target ref of relationship identified by rId.

paramrIdstr

Returns

str

On this page