Package
paper-docx 0.2.0 API reference
Customizations specific to a WordprocessingML package.
Attributes
core_properties
attributecore_propertiesCorePropertiesCoreProperties object providing read/write access to the Dublin Core
properties for this document.
image_parts
attributeimage_partsImagePartsImageParts collection object for this package.
main_document_part
attributemain_document_partReturn a reference to the main document part for this package.
Examples include a document part for a WordprocessingML package, a presentation part for a PresentationML package, or a workbook part for a SpreadsheetML package.
parts
attributepartslist[Part]Return a list containing a reference to each of the parts in this package.
rels
attributerelsReturn a reference to the Relationships instance holding the collection of
relationships for this package.
Functions
after_unmarshal
funcafter_unmarshal()Called by loading code after all parts and relationships have been loaded.
This method affords the opportunity for any required post-processing.
get_or_add_image_part
funcget_or_add_image_part(image_descriptor: str | IO[bytes]) -> ImagePartReturn ImagePart containing image specified by image_descriptor.
The image-part is newly created if a matching one is not already present in the collection.
paramimage_descriptorstr | IO[bytes]Returns
docx.parts.image.ImagePartiter_parts
funciter_parts() -> Iterator[Part]Generate exactly one reference to each of the parts in the package by performing a depth-first traversal of the rels graph.
Returns
typing.Iterator[docx.opc.part.Part]iter_rels
funciter_rels() -> Iterator[_Relationship]Generate exactly one reference to each relationship in the package by performing a depth-first traversal of the rels graph.
Returns
typing.Iterator[docx.opc.rel._Relationship]load_rel
funcload_rel(reltype: str, target: Part | str, rId: str, is_external: bool = False)Return newly added _Relationship instance of reltype between this part
and target with key rId.
Target mode is set to RTM.EXTERNAL if is_external is True. Intended for
use during load from a serialized package, where the rId is well known. Other
methods exist for adding a new relationship to the package during processing.
paramreltypestrparamtargetPart | strparamrIdstrparamis_externalbool= Falsenext_partname
funcnext_partname(template: str) -> PackURIReturn a PackURI instance representing partname matching template.
The returned part-name has the next available numeric suffix to distinguish it
from other parts of its type. template 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: "/word/header%d.xml"
paramtemplatestrReturns
docx.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 part to which this package has a relationship of reltype.
Raises KeyError if no such relationship is found and ValueError if more than
one such relationship is found.
paramreltypestrReturns
docx.opc.part.Partrelate_to
funcrelate_to(part: Part, reltype: str)Return rId key of new or existing relationship to part.
If a relationship of reltype to part already exists, its rId is returned. Otherwise a
new relationship is created and that rId is returned.
parampartPartparamreltypestrsave
funcsave(pkg_file: str | IO[bytes])Save this package to pkg_file, a path or a stream positioned at byte zero.
Serializes to a sibling temp file, reparses it to confirm it opens, then replaces the destination. A failed save leaves the original untouched and never leaves behind a package Word cannot open. An existing destination keeps its permission bits. A symlink destination is followed and its target replaced.
Raises MalformedPackageError when the serialized output will not reparse, and
OSError for a stream in append mode, a stream positioned past byte zero, or a
destination symlink that moves mid-save.
parampkg_filestr | IO[bytes]