sdkagent

python-docx API reference

224 public APIs from python-docx (python-openxml/python-docx) — 106 classes, 9 functions, 109 methods. Signatures extracted by static analysis of the actual source.

Repository: python-openxml/python-docx

KindCount
Classes106
Functions9
Methods109

API list

classsrc.docx.blkcntnr.BlockItemContainer
Base class for proxy objects that can contain block items.
classsrc.docx.comments.Comment
Proxy for a single comment in the document.
methodsrc.docx.comments.Comment.author() -> str
Read/write.
methodsrc.docx.comments.Comment.comment_id() -> int
The unique identifier of this comment.
methodsrc.docx.comments.Comment.initials() -> str | None
Read/write.
methodsrc.docx.comments.Comment.text() -> str
The text content of this comment as a string.
methodsrc.docx.comments.Comment.timestamp() -> dt.datetime | None
The date and time this comment was authored.
classsrc.docx.comments.Comments
Collection containing the comments added to this document.
methodsrc.docx.comments.Comments.add_comment(text:str='', author:str='', initials:str | None='') -> Comment
Add a new comment to the document and return it.
methodsrc.docx.comments.Comments.get(comment_id:int) -> Comment | None
Return the comment identified by `comment_id`, or |None| if not found.
classsrc.docx.document.Document
WordprocessingML (WML) document.
methodsrc.docx.document.Document.part() -> DocumentPart
The |DocumentPart| object of this document.
methodsrc.docx.document.Document.save(path_or_stream:str | IO[bytes])
Save this document to `path_or_stream`.
classsrc.docx.drawing.Drawing
Container for a DrawingML object.
methodsrc.docx.drawing.Drawing.has_picture() -> bool
True when `drawing` contains an embedded picture.
classsrc.docx.enum.base.BaseEnum
Base class for Enums that do not map XML attr values.
classsrc.docx.enum.base.BaseXmlEnum
Base class for Enums that also map XML attr values.
classsrc.docx.enum.base.DocsPageFormatter
Generate an .rst doc page for an enumeration.
classsrc.docx.enum.dml.MSO_COLOR_TYPE
Specifies the color specification scheme.
classsrc.docx.enum.shape.WD_INLINE_SHAPE_TYPE
Corresponds to WdInlineShapeType enumeration.
classsrc.docx.enum.table.WD_TABLE_ALIGNMENT
Specifies table justification type.
classsrc.docx.enum.text.WD_BREAK_TYPE
Corresponds to WdBreakType enumeration.
classsrc.docx.enum.text.WD_COLOR_INDEX
Specifies a standard preset color to apply.
classsrc.docx.enum.text.WD_TAB_ALIGNMENT
Specifies the tab stop alignment to apply.
classsrc.docx.exceptions.PythonDocxError
Generic error class.
classsrc.docx.image.bmp.Bmp
Image header parser for BMP images.
classsrc.docx.image.constants.JPEG_MARKER_CODE
JPEG marker codes.
classsrc.docx.image.constants.MIME_TYPE
Image content types.
classsrc.docx.image.constants.PNG_CHUNK_TYPE
PNG chunk type names.
classsrc.docx.image.constants.TIFF_FLD_TYPE
Tag codes for TIFF Image File Directory (IFD) entries.
classsrc.docx.image.constants.TIFF_TAG
Tag codes for TIFF Image File Directory (IFD) entries.
classsrc.docx.image.exceptions.InvalidImageStreamError
The recognized image stream appears to be corrupted.
classsrc.docx.image.exceptions.UnrecognizedImageError
The provided image stream could not be recognized.
classsrc.docx.image.gif.Gif
Image header parser for GIF images.
methodsrc.docx.image.helpers.StreamReader.read(count)
Allow pass-through read() call.
methodsrc.docx.image.helpers.StreamReader.tell()
Allow pass-through tell() call.
classsrc.docx.image.image.BaseImageHeader
Base class for image header subclasses like |Jpeg| and |Tiff|.
methodsrc.docx.image.image.BaseImageHeader.default_ext() -> str
Default filename extension for images of this type.
methodsrc.docx.image.image.Image.blob()
The bytes of the image 'file'.
methodsrc.docx.image.image.Image.content_type() -> str
MIME content type for this image, e.g.
methodsrc.docx.image.image.Image.ext()
The file extension for the image.
methodsrc.docx.image.image.Image.horz_dpi() -> int
Integer dots per inch for the width of this image.
methodsrc.docx.image.image.Image.px_height() -> int
The vertical pixel dimension of the image.
methodsrc.docx.image.image.Image.px_width() -> int
The horizontal pixel dimension of the image.
methodsrc.docx.image.image.Image.sha1()
SHA1 hash digest of the image blob.
methodsrc.docx.image.image.Image.vert_dpi() -> int
Integer dots per inch for the height of this image.
classsrc.docx.image.jpeg.Exif
Image header parser for Exif image format.
classsrc.docx.image.jpeg.Jfif
Image header parser for JFIF image format.
classsrc.docx.image.jpeg.Jpeg
Base class for JFIF and EXIF subclasses.
classsrc.docx.image.png.Png
Image header parser for PNG images.
classsrc.docx.image.tiff.Tiff
Image header parser for TIFF images.
classsrc.docx.opc.constants.NAMESPACE
Constant values for OPC XML namespaces.
classsrc.docx.opc.constants.RELATIONSHIP_TARGET_MODE
Open XML relationship target modes.
classsrc.docx.opc.exceptions.OpcError
Base error class for python-opc.
methodsrc.docx.opc.oxml.CT_Relationships.new() -> CT_Relationships
Return a new ``<Relationships>`` element.
methodsrc.docx.opc.oxml.CT_Types.new()
Return a new ``<Types>`` element.
funcsrc.docx.opc.oxml.parse_xml(text:str) -> etree._Element
`etree.fromstring()` replacement that uses oxml parser.
funcsrc.docx.opc.oxml.serialize_for_reading(element:etree._Element) -> str
Serialize `element` to human-readable XML suitable for tests.
classsrc.docx.opc.package.OpcPackage
Main API class for |python-opc|.
methodsrc.docx.opc.package.OpcPackage.save(pkg_file:str | IO[bytes])
Save this package to `pkg_file`.
methodsrc.docx.opc.packuri.PackURI.ext() -> str
The extension portion of this pack URI, e.g.
classsrc.docx.opc.part.Part
Base class for package parts.
methodsrc.docx.opc.part.Part.blob() -> bytes
Contents of this package part as a sequence of bytes.
methodsrc.docx.opc.part.Part.content_type()
Content type of this part.
methodsrc.docx.opc.part.Part.part_related_by(reltype:str) -> Part
Return part to which this part has a relationship of `reltype`.
methodsrc.docx.opc.part.Part.relate_to(target:Part | str, reltype:str, is_external:bool=False) -> str
Return rId key of relationship of `reltype` to `target`.
classsrc.docx.opc.parts.coreprops.CorePropertiesPart
Corresponds to part named ``/docProps/core.xml``.
classsrc.docx.opc.phys_pkg.PhysPkgReader
Factory for physical package reader objects.
classsrc.docx.opc.phys_pkg.PhysPkgWriter
Factory for physical package writer objects.
methodsrc.docx.opc.rel.Relationships.add_relationship(reltype:str, target:Part | str, rId:str, is_external:bool=False) -> '_Relationship'
Return a newly added |_Relationship| instance.
funcsrc.docx.opc.shared.cls_method_fn(cls:type, method_name:str)
Return method of `cls` having `method_name`.
classsrc.docx.oxml.comments.CT_Comment
`w:comment` element, representing a single comment.
methodsrc.docx.oxml.coreprops.CT_CoreProperties.author_text() -> str
The text in the `dc:creator` child element.
methodsrc.docx.oxml.coreprops.CT_CoreProperties.new() -> CT_CoreProperties
Return a new `<cp:coreProperties>` element.
methodsrc.docx.oxml.coreprops.CT_CoreProperties.revision_number() -> int
Integer value of revision property.
classsrc.docx.oxml.exceptions.XmlchemyError
Generic error class.
methodsrc.docx.oxml.ns.NamespacePrefixedTag.local_part() -> str
The local part of this tag.
methodsrc.docx.oxml.ns.NamespacePrefixedTag.nspfx() -> str
The namespace-prefix for this tag.
methodsrc.docx.oxml.ns.NamespacePrefixedTag.nsuri() -> str
The namespace URI for this tag.
funcsrc.docx.oxml.ns.nsdecls(*prefixes:str) -> str
Namespace declaration including each namespace-prefix in `prefixes`.
funcsrc.docx.oxml.ns.nspfxmap(*nspfxs:str) -> Dict[str, str]
Subset namespace-prefix mappings specified by *nspfxs*.
funcsrc.docx.oxml.ns.qn(tag:str) -> str
Stands for "qualified name".
funcsrc.docx.oxml.parser.parse_xml(xml:str | bytes) -> 'BaseOxmlElement'
Root lxml element obtained by parsing XML character string `xml`.
classsrc.docx.oxml.section.CT_HdrFtrRef
`w:headerReference` and `w:footerReference` elements.
classsrc.docx.oxml.section.CT_PageMar
``<w:pgMar>`` element, defining page margins.
classsrc.docx.oxml.settings.CT_Settings
`w:settings` element, root element for the settings part.
classsrc.docx.oxml.shape.CT_Anchor
`<wp:anchor>` element, container for a "floating" shape.
classsrc.docx.oxml.shape.CT_Inline
`<wp:inline>` element, container for an inline shape.
classsrc.docx.oxml.shape.CT_NonVisualDrawingProps
Used for ``<wp:docPr>`` element, and perhaps others.
classsrc.docx.oxml.shape.CT_Picture
``<pic:pic>`` element, a DrawingML picture.
methodsrc.docx.oxml.shape.CT_Picture.new(pic_id:int, filename:str, rId:str, cx:Length, cy:Length) -> CT_Picture
A new minimum viable `<pic:pic>` (picture) element.
classsrc.docx.oxml.shape.CT_Point2D
Used for ``<a:off>`` element, and perhaps others.
classsrc.docx.oxml.shared.CT_OnOff
Used for `w:b`, `w:i` elements and others.
classsrc.docx.oxml.shared.CT_String
Used for `w:pStyle` and `w:tblStyle` elements and others.
classsrc.docx.oxml.simpletypes.BaseSimpleType
Base class for simple-types.
classsrc.docx.oxml.simpletypes.ST_HexColorAuto
Value for `w:color/[@val="auto"] attribute setting.
classsrc.docx.oxml.simpletypes.ST_HpsMeasure
Half-point measure, e.g.
classsrc.docx.oxml.simpletypes.ST_Merge
Valid values for <w:xMerge val=""> attribute.
classsrc.docx.oxml.simpletypes.ST_VerticalAlignRun
Valid values for `w:vertAlign/@val`.
classsrc.docx.oxml.simpletypes.XsdAnyUri
There's a regex in the spec this is supposed to meet...
classsrc.docx.oxml.simpletypes.XsdStringEnumeration
Set of enumerated xsd:string values.
classsrc.docx.oxml.simpletypes.XsdToken
Xsd:string with whitespace collapsing, e.g.
classsrc.docx.oxml.styles.CT_Style
A ``<w:style>`` element, representing a style definition.
classsrc.docx.oxml.table.CT_Row
``<w:tr>`` element.
methodsrc.docx.oxml.table.CT_Row.tc_at_grid_offset(grid_offset:int) -> CT_Tc
The `tc` element in this tr at exact `grid offset`.
classsrc.docx.oxml.table.CT_Tbl
``<w:tbl>`` element.
classsrc.docx.oxml.table.CT_TblGrid
`w:tblGrid` element.
classsrc.docx.oxml.table.CT_TblLayoutType
`w:tblLayout` element.
classsrc.docx.oxml.table.CT_TblPrEx
`w:tblPrEx` element, exceptions to table-properties.
classsrc.docx.oxml.table.CT_Tc
`w:tc` table cell element.
methodsrc.docx.oxml.table.CT_Tc.grid_span() -> int
The integer number of columns this cell spans.
methodsrc.docx.oxml.table.CT_Tc.merge(other_tc:CT_Tc) -> CT_Tc
Return top-left `w:tc` element of a new span.
methodsrc.docx.oxml.table.CT_Tc.top() -> int
The top-most row index in the vertical span of this cell.
classsrc.docx.oxml.table.CT_TcPr
``<w:tcPr>`` element, defining table cell properties.
methodsrc.docx.oxml.table.CT_TcPr.grid_span() -> int
The integer number of columns this cell spans.
classsrc.docx.oxml.table.CT_TrPr
``<w:trPr>`` element, defining table row properties.
classsrc.docx.oxml.text.font.CT_Fonts
`<w:rFonts>` element.
classsrc.docx.oxml.text.font.CT_RPr
`<w:rPr>` element, containing the properties for a run.
methodsrc.docx.oxml.text.font.CT_RPr.highlight_val() -> WD_COLOR_INDEX | None
Value of `./w:highlight/@val`.
methodsrc.docx.oxml.text.font.CT_RPr.subscript() -> bool | None
|True| if `./w:vertAlign/@w:val` is "subscript".
methodsrc.docx.oxml.text.font.CT_RPr.superscript() -> bool | None
|True| if `w:vertAlign/@w:val` is 'superscript'.
methodsrc.docx.oxml.text.font.CT_RPr.sz_val() -> Length | None
The value of `w:sz/@w:val` or |None| if not present.
methodsrc.docx.oxml.text.font.CT_RPr.u_val() -> WD_UNDERLINE | None
Value of `w:u/@val`, or None if not present.
methodsrc.docx.oxml.text.hyperlink.CT_Hyperlink.text() -> str
The textual content of this hyperlink.
classsrc.docx.oxml.text.parfmt.CT_Ind
``<w:ind>`` element, specifying paragraph indentation.
classsrc.docx.oxml.text.parfmt.CT_Jc
``<w:jc>`` element, specifying paragraph justification.
classsrc.docx.oxml.text.parfmt.CT_TabStop
`<w:tab>` element, representing an individual tab stop.
methodsrc.docx.oxml.text.run.CT_R.add_t(text:str) -> CT_Text
Return a newly added `<w:t>` element containing `text`.
methodsrc.docx.oxml.text.run.CT_R.text() -> str
The textual content of this run.
classsrc.docx.oxml.xmlchemy.BaseAttribute
Base class for OptionalAttribute and RequiredAttribute.
methodsrc.docx.oxml.xmlchemy.BaseAttribute.populate_class_members(element_cls:MetaOxmlElement, prop_name:str) -> None
Add the appropriate methods to `element_cls`.
classsrc.docx.oxml.xmlchemy.BaseOxmlElement
Effective base class for all custom element classes.
methodsrc.docx.oxml.xmlchemy.BaseOxmlElement.first_child_found_in(*tagnames:str) -> _Element | None
First child with tag in `tagnames`, or None if not found.
methodsrc.docx.oxml.xmlchemy.BaseOxmlElement.remove_all(*tagnames:str) -> None
Remove child elements with tagname (e.g.
methodsrc.docx.oxml.xmlchemy.BaseOxmlElement.xpath(xpath_str:str) -> Any
Override of `lxml` _Element.xpath() method.
methodsrc.docx.oxml.xmlchemy.Choice.populate_class_members(element_cls:MetaOxmlElement, group_prop_name:str, successors:tuple[str, ...]) -> None
Add the appropriate methods to `element_cls`.
classsrc.docx.oxml.xmlchemy.MetaOxmlElement
Metaclass for BaseOxmlElement.
classsrc.docx.oxml.xmlchemy.OneAndOnlyOne
Defines a required child element for MetaOxmlElement.
methodsrc.docx.oxml.xmlchemy.OneAndOnlyOne.populate_class_members(element_cls:MetaOxmlElement, prop_name:str) -> None
Add the appropriate methods to `element_cls`.
methodsrc.docx.oxml.xmlchemy.OneOrMore.populate_class_members(element_cls:MetaOxmlElement, prop_name:str) -> None
Add the appropriate methods to `element_cls`.
classsrc.docx.oxml.xmlchemy.RequiredAttribute
Defines a required attribute on a custom element class.
methodsrc.docx.oxml.xmlchemy.ZeroOrMore.populate_class_members(element_cls:MetaOxmlElement, prop_name:str) -> None
Add the appropriate methods to `element_cls`.
classsrc.docx.oxml.xmlchemy.ZeroOrOne
Defines an optional child element for MetaOxmlElement.
methodsrc.docx.oxml.xmlchemy.ZeroOrOne.populate_class_members(element_cls:MetaOxmlElement, prop_name:str) -> None
Add the appropriate methods to `element_cls`.
classsrc.docx.package.Package
Customizations specific to a WordprocessingML package.
methodsrc.docx.package.Package.image_parts() -> ImageParts
|ImageParts| collection object for this package.
classsrc.docx.parts.comments.CommentsPart
Container part for comments added to the document.
classsrc.docx.parts.hdrftr.FooterPart
Definition of a section footer.
methodsrc.docx.parts.hdrftr.FooterPart.new(package:Package)
Return newly created footer part.
classsrc.docx.parts.hdrftr.HeaderPart
Definition of a section header.
methodsrc.docx.parts.hdrftr.HeaderPart.new(package:Package)
Return newly created header part.
classsrc.docx.parts.image.ImagePart
An image part.
classsrc.docx.parts.story.StoryPart
Base class for story parts.
methodsrc.docx.parts.story.StoryPart.get_style(style_id:str | None, style_type:WD_STYLE_TYPE) -> BaseStyle
Return the style in this document matching `style_id`.
methodsrc.docx.parts.story.StoryPart.new_pic_inline(image_descriptor:str | IO[bytes], width:int | Length | None=None, height:int | Length | None=None) -> CT_Inline
Return a newly-created `w:inline` element.
methodsrc.docx.section.Section.bottom_margin() -> Length | None
Read/write.
methodsrc.docx.section.Section.page_height() -> Length | None
Total page height used for this section.
methodsrc.docx.section.Section.page_width() -> Length | None
Total page width used for this section.
classsrc.docx.settings.Settings
Provides access to document-level settings for a document.
classsrc.docx.shared.Cm
Convenience constructor for length in centimeters, e.g.
classsrc.docx.shared.ElementProxy
Base class for lxml element proxy classes.
methodsrc.docx.shared.ElementProxy.part() -> XmlPart
The package part containing this object.
classsrc.docx.shared.Emu
Convenience constructor for length in English Metric Units, e.g.
classsrc.docx.shared.Inches
Convenience constructor for length in inches, e.g.
classsrc.docx.shared.Length
Base class for length constructor classes Inches, Cm, Mm, Px, and Emu.
methodsrc.docx.shared.Length.pt()
Floating point length in points.
classsrc.docx.shared.Mm
Convenience constructor for length in millimeters, e.g.
classsrc.docx.shared.Pt
Convenience value class for specifying a length in points.
classsrc.docx.shared.RGBColor
Immutable value object defining a particular RGB color.
classsrc.docx.shared.StoryChild
A document element within a story part.
methodsrc.docx.shared.StoryChild.part() -> StoryPart
The package part containing this object.
classsrc.docx.shared.Twips
Convenience constructor for length in twips, e.g.
funcsrc.docx.shared.write_only_property(f:Callable[[Any, Any], None])
@write_only_property decorator.
classsrc.docx.styles.BabelFish
Translates special-case style names from UI name (e.g.
methodsrc.docx.styles.style.BaseStyle.builtin()
Read-only.
methodsrc.docx.styles.style.BaseStyle.locked()
Read/write Boolean.
methodsrc.docx.styles.style.BaseStyle.name()
The UI name of this style.
methodsrc.docx.styles.style.BaseStyle.style_id() -> str
The unique key name (string) for this style.
classsrc.docx.styles.style.CharacterStyle
A character style.
classsrc.docx.styles.style.ParagraphStyle
A paragraph style.
classsrc.docx.styles.styles.Styles
Provides access to the styles defined in a document.
classsrc.docx.table.Table
Proxy class for a WordprocessingML ``<w:tbl>`` element.
methodsrc.docx.table.Table.alignment() -> WD_TABLE_ALIGNMENT | None
Read/write.
methodsrc.docx.table.Table.cell(row_idx:int, col_idx:int) -> _Cell
|_Cell| at `row_idx`, `col_idx` intersection.
methodsrc.docx.table.Table.column_cells(column_idx:int) -> list[_Cell]
Sequence of cells in the column at `column_idx` in this table.
methodsrc.docx.table.Table.row_cells(row_idx:int) -> list[_Cell]
DEPRECATED: Use `table.rows[row_idx].cells` instead.
funcsrc.docx.table._Row.iter_tc_cells(tc:CT_Tc) -> Iterator[_Cell]
Generate a cell object for each layout-grid cell in `tc`.
methodsrc.docx.text.font.Font.all_caps() -> bool | None
Read/write.
methodsrc.docx.text.font.Font.bold() -> bool | None
Read/write.
methodsrc.docx.text.font.Font.complex_script() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.cs_bold() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.cs_italic() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.double_strike() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.emboss() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.hidden() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.imprint() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.italic() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.math() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.name() -> str | None
The typeface name for this |Font|.
methodsrc.docx.text.font.Font.no_proof() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.outline() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.rtl() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.shadow() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.size() -> Length | None
Font height in English Metric Units (EMU).
methodsrc.docx.text.font.Font.small_caps() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.snap_to_grid() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.spec_vanish() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.strike() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.font.Font.underline() -> bool | WD_UNDERLINE | None
The underline style for this |Font|.
methodsrc.docx.text.font.Font.web_hidden() -> bool | None
Read/write tri-state value.
classsrc.docx.text.hyperlink.Hyperlink
Proxy object wrapping a `<w:hyperlink>` element.
methodsrc.docx.text.hyperlink.Hyperlink.runs() -> list[Run]
List of |Run| instances in this hyperlink.
classsrc.docx.text.paragraph.Paragraph
Proxy object wrapping a `<w:p>` element.
methodsrc.docx.text.paragraph.Paragraph.rendered_page_breaks() -> List[RenderedPageBreak]
All rendered page-breaks in this paragraph.
methodsrc.docx.text.paragraph.Paragraph.style() -> ParagraphStyle | None
Read/Write.
methodsrc.docx.text.paragraph.Paragraph.text() -> str
The textual content of this paragraph.
classsrc.docx.text.run.Run
Proxy object wrapping `<w:r>` element.
methodsrc.docx.text.run.Run.bold() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.run.Run.italic() -> bool | None
Read/write tri-state value.
methodsrc.docx.text.run.Run.style() -> CharacterStyle
Read/write.
methodsrc.docx.text.run.Run.underline() -> bool | WD_UNDERLINE | None
The underline style for this |Run|.
classsrc.docx.text.tabstops.TabStop
An individual tab stop applying to a paragraph or style.
classsrc.docx.types.ProvidesStoryPart
An object that provides access to the StoryPart.
classsrc.docx.types.ProvidesXmlPart
An object that provides access to its XmlPart.

About this data

These signatures were extracted from the public source of python-openxml/python-docx using Python's ast module. Argument names, default values, type annotations and return types are taken verbatim from the code. Implementation bodies are never stored. See how it works for details.

Back to all 805 libraries