SlideShapes
paper-pptx 0.2.0 API reference
Sequence of shapes appearing on a slide.
The first shape in the sequence is the backmost in z-order and the last shape is topmost. Supports indexed access, len(), index(), and iteration.
Attributes
element
attributeelementThe lxml element proxied by this object.
parent
attributeparentSlidepart
attributepartSlidePartplaceholders
attributeplaceholdersSlidePlaceholdersSequence of placeholder shapes in this slide.
title
attributetitleShape | NoneThe title placeholder shape on the slide.
None if the slide has no title placeholder.
turbo_add_enabled
attributeturbo_add_enabledboolTrue if "turbo-add" mode is enabled. Read/Write.
EXPERIMENTAL: This feature can radically improve performance when adding large numbers (hundreds of shapes) to a slide. It works by caching the last shape ID used and incrementing that value to assign the next shape id. This avoids repeatedly searching all shape ids in the slide each time a new ID is required.
Performance is not noticeably improved for a slide with a relatively small number of shapes, but because the search time rises with the square of the shape count, this option can be useful for optimizing generation of a slide composed of many shapes.
Shape-id collisions can occur (causing a repair error on load) if more than one Slide
object is used to interact with the same slide in the presentation. Note that the Slides
collection creates a new Slide object each time a slide is accessed (e.g. slide = prs.slides[0], so you must be careful to limit use to a single Slide object.
Functions
__getitem__
func__getitem__(idx: int) -> BaseShapeReturn shape at idx in sequence, e.g. shapes[2].
paramidxintReturns
pptx.shapes.base.BaseShape__iter__
func__iter__() -> Iterator[BaseShape]Generate a reference to each shape in the collection, in sequence.
Returns
typing.Iterator[pptx.shapes.base.BaseShape]__len__
func__len__() -> intReturn count of shapes in this shape tree.
A group shape contributes 1 to the total, without regard to the number of shapes contained in the group.
Returns
intadd_chart
funcadd_chart(chart_type: XL_CHART_TYPE, x: Length, y: Length, cx: Length, cy: Length, chart_data: ChartData) -> ChartAdd a new chart of chart_type to the slide.
The chart is positioned at (x, y), has size (cx, cy), and depicts chart_data.
chart_type is one of the :ref:XlChartType enumeration values. chart_data is a
ChartData object populated with the categories and series values for the chart.
Note that a GraphicFrame shape object is returned, not the Chart object contained in
that graphic frame shape. The chart object may be accessed using the :attr:chart
property of the returned GraphicFrame object.
paramchart_typeXL_CHART_TYPEparamxLengthparamyLengthparamcxLengthparamcyLengthparamchart_dataChartDataReturns
pptx.chart.chart.Chartadd_connector
funcadd_connector(connector_type: MSO_CONNECTOR_TYPE, begin_x: Length, begin_y: Length, end_x: Length, end_y: Length) -> ConnectorAdd a newly created connector shape to the end of this shape tree.
connector_type is a member of the :ref:MsoConnectorType enumeration and the end-point
values are specified as EMU values. The returned connector is of type connector_type and
has begin and end points as specified.
paramconnector_typeMSO_CONNECTOR_TYPEparambegin_xLengthparambegin_yLengthparamend_xLengthparamend_yLengthReturns
pptx.shapes.connector.Connectoradd_copy
funcadd_copy(shape)Return a copy of shape (from this or another slide) added to this slide.
paper-pptx addition. The copy gets fresh shape ids; its
relationships follow the pinned policy: image/media parts shared, external
(hyperlink) relationships copied, charts deep-copied WITH their embedded workbooks
and style parts. Any other relationship type refuses with RelationshipPolicyError
before anything changes. A shape from another presentation raises
TargetNotFoundError.
paramshapeadd_group_shape
funcadd_group_shape(shapes: Iterable[BaseShape] = ()) -> GroupShapeReturn a GroupShape object newly appended to this shape tree.
The group shape is empty and must be populated with shapes using methods on its shape
tree, available on its .shapes property. The position and extents of the group shape are
determined by the shapes it contains; its position and extents are recalculated each time
a shape is added to it.
paramshapesIterable[BaseShape]= ()Returns
pptx.shapes.group.GroupShapeadd_movie
funcadd_movie(movie_file: str | IO[bytes], left: Length, top: Length, width: Length, height: Length, poster_frame_image: str | IO[bytes] | None = None, mime_type: str = CT.VIDEO) -> GraphicFrameReturn newly added movie shape displaying video in movie_file.
EXPERIMENTAL. This method has important limitations:
- The size must be specified; no auto-scaling such as that provided by :meth:
add_pictureis performed. - The MIME type of the video file should be specified, e.g. 'video/mp4'. The provided
video file is not interrogated for its type. The MIME type
video/unknownis used by default (and works fine in tests as of this writing). - A poster frame image must be provided, it cannot be automatically extracted from the video file. If no poster frame is provided, the default "media loudspeaker" image will be used.
Return a newly added movie shape to the slide, positioned at (left, top), having size
(width, height), and containing movie_file. Before the video is started,
poster_frame_image is displayed as a placeholder for the video.
parammovie_filestr | IO[bytes]paramleftLengthparamtopLengthparamwidthLengthparamheightLengthparamposter_frame_imagestr | IO[bytes] | None= Noneparammime_typestr= CT.VIDEOReturns
pptx.shapes.graphfrm.GraphicFrameadd_ole_object
funcadd_ole_object(object_file: str | IO[bytes], prog_id: str, left: Length, top: Length, width: Length | None = None, height: Length | None = None, icon_file: str | IO[bytes] | None = None, icon_width: Length | None = None, icon_height: Length | None = None) -> GraphicFrameReturn newly-created GraphicFrame shape embedding object_file.
The returned graphic-frame shape contains object_file as an embedded OLE object. It is
displayed as an icon at left, top with size width, height. width and height
may be omitted when prog_id is a member of PROG_ID, in which case the default icon
size is used. This is advised for best appearance where applicable because it avoids an
icon with a "stretched" appearance.
object_file may either be a str path to a file or file-like object (such as
io.BytesIO) containing the bytes of the object to be embedded (such as an Excel file).
prog_id can be either a member of pptx.enum.shapes.PROG_ID or a str value like
"Adobe.Exchange.7" determined by inspecting the XML generated by PowerPoint for an
object of the desired type.
icon_file may either be a str path to an image file or a file-like object containing the
image. The image provided will be displayed in lieu of the OLE object; double-clicking on
the image opens the object (subject to operating-system limitations). The image file can
be any supported image file. Those produced by PowerPoint itself are generally EMF and can
be harvested from a PPTX package that embeds such an object. PNG and JPG also work fine.
icon_width and icon_height are Length values (e.g. Emu() or Inches()) that describe
the size of the icon image within the shape. These should be omitted unless a custom
icon_file is provided. The dimensions must be discovered by inspecting the XML.
Automatic resizing of the OLE-object shape can occur when the icon is double-clicked if
these values are not as set by PowerPoint. This behavior may only manifest in the Windows
version of PowerPoint.
paramobject_filestr | IO[bytes]paramprog_idstrparamleftLengthparamtopLengthparamwidthLength | None= NoneparamheightLength | None= Noneparamicon_filestr | IO[bytes] | None= Noneparamicon_widthLength | None= Noneparamicon_heightLength | None= NoneReturns
pptx.shapes.graphfrm.GraphicFrameadd_picture
funcadd_picture(image_file: str | IO[bytes], left: Length, top: Length, width: Length | None = None, height: Length | None = None) -> PictureAdd picture shape displaying image in image_file.
image_file can be either a path to a file (a string) or a file-like object. The picture
is positioned with its top-left corner at (top, left). If width and height are
both None, the native size of the image is used. If only one of width or height is
used, the unspecified dimension is calculated to preserve the aspect ratio of the image.
If both are specified, the picture is stretched to fit, without regard to its native
aspect ratio.
paramimage_filestr | IO[bytes]paramleftLengthparamtopLengthparamwidthLength | None= NoneparamheightLength | None= NoneReturns
pptx.shapes.picture.Pictureadd_shape
funcadd_shape(autoshape_type_id: MSO_SHAPE, left: Length, top: Length, width: Length, height: Length) -> ShapeReturn new Shape object appended to this shape tree.
autoshape_type_id is a member of :ref:MsoAutoShapeType e.g. MSO_SHAPE.RECTANGLE
specifying the type of shape to be added. The remaining arguments specify the new shape's
position and size.
paramautoshape_type_idMSO_SHAPEparamleftLengthparamtopLengthparamwidthLengthparamheightLengthReturns
pptx.shapes.autoshape.Shapeadd_table
funcadd_table(rows: int, cols: int, left: Length, top: Length, width: Length, height: Length) -> GraphicFrameAdd a GraphicFrame object containing a table.
The table has the specified number of rows and cols and the specified position and
size. width is evenly distributed between the columns of the new table. Likewise,
height is evenly distributed between the rows. Note that the .table property on the
returned GraphicFrame shape must be used to access the enclosed Table object.
paramrowsintparamcolsintparamleftLengthparamtopLengthparamwidthLengthparamheightLengthReturns
pptx.shapes.graphfrm.GraphicFrameadd_textbox
funcadd_textbox(left: Length, top: Length, width: Length, height: Length) -> ShapeReturn newly added text box shape appended to this shape tree.
The text box is of the specified size, located at the specified position on the slide.
paramleftLengthparamtopLengthparamwidthLengthparamheightLengthReturns
pptx.shapes.autoshape.Shapebuild_freeform
funcbuild_freeform(start_x: float = 0, start_y: float = 0, scale: tuple[float, float] | float = 1.0) -> FreeformBuilderReturn FreeformBuilder object to specify a freeform shape.
The optional start_x and start_y arguments specify the starting pen position in local
coordinates. They will be rounded to the nearest integer before use and each default to
zero.
The optional scale argument specifies the size of local coordinates proportional to
slide coordinates (EMU). If the vertical scale is different than the horizontal scale
(local coordinate units are "rectangular"), a pair of numeric values can be provided as
the scale argument, e.g. scale=(1.0, 2.0). In this case the first number is
interpreted as the horizontal (X) scale and the second as the vertical (Y) scale.
A convenient method for calculating scale is to divide a Length object by an equivalent
count of local coordinate units, e.g. scale = Inches(1)/1000 for 1000 local units per
inch.
paramstart_xfloat= 0paramstart_yfloat= 0paramscaletuple[float, float] | float= 1.0Returns
pptx.shapes.freeform.FreeformBuilderchart_by_name
funcchart_by_name(name: str)Return the Chart held by the shape on this slide named name.
paper-pptx addition, the chart-addressing half of safe chart-data replacement.
Group-aware: shapes inside groups are found too. Raises
TargetNotFoundError when no shape has that name, or when shapes with the name
exist but none holds a chart (the message says what was found instead). Raises
AmbiguousTargetError when more than one chart-bearing shape has the name — this
API never guesses between them.
paramnamestrclone_layout_placeholders
funcclone_layout_placeholders(slide_layout: SlideLayout) -> NoneAdd placeholder shapes based on those in slide_layout.
Z-order of placeholders is preserved. Latent placeholders (date, slide number, and footer) are not cloned.
paramslide_layoutSlideLayoutReturns
Noneclone_placeholder
funcclone_placeholder(placeholder: LayoutPlaceholder) -> NoneAdd a new placeholder shape based on placeholder.
paramplaceholderLayoutPlaceholderReturns
Nonedelete
funcdelete(shape) -> NoneRemove shape from this slide, with relationship hygiene.
paper-pptx addition. Relationships referenced by the removed
subtree are dropped unless something else in the part still references them (two
pictures can share one image relationship). A shape that is not a direct member of
this collection — including a shape inside a group — raises TargetNotFoundError
(delete the group, or ungroup first).
paramshapeReturns
Noneindex
funcindex(shape: BaseShape) -> intReturn the index of shape in this sequence.
Raises ValueError if shape is not in the collection.
paramshapeBaseShapeReturns
intmove
funcmove(shape, to_index: int) -> NoneMove shape to 0-based to_index in this collection's z-order.
paper-pptx addition. Index 0 is backmost, the last index topmost —
the same order this collection iterates. to_index outside range raises
ValueError; a shape not directly in this collection raises TargetNotFoundError.
paramshapeparamto_indexintReturns
Noneph_basename
funcph_basename(ph_type: PP_PLACEHOLDER) -> strReturn the base name for a placeholder of ph_type in this shape collection.
There is some variance between slide types, for example a notes slide uses a different name for the body placeholder, so this method can be overriden by subclasses.
paramph_typePP_PLACEHOLDERReturns
strpicture_by_name
funcpicture_by_name(name: str)Return the Picture on this slide named name (group-aware).
paper-pptx addition, with the same contract as chart_by_name:
TargetNotFoundError when nothing (or nothing picture-shaped) has the name,
AmbiguousTargetError when several pictures do.
paramnamestrshape_by_name
funcshape_by_name(name: str)Return the single shape on this slide named name (group-aware).
paper-pptx addition: TargetNotFoundError / AmbiguousTargetError,
never first-match.
paramnamestrtable_by_name
functable_by_name(name: str)Return the Table held by the graphic frame on this slide named name.
paper-pptx addition, same contract as chart_by_name.
paramnamestr