Generate and manipulate Open XML PowerPoint (.pptx) files
python-pptx is a Python library for creating, reading, and updating PowerPoint (.pptx) files.
A typical use would be generating a PowerPoint presentation from dynamic content such as a database query, analytics output, or a JSON payload, perhaps in response to an HTTP request and downloading the generated PPTX file in response. It runs on any Python capable platform, including macOS and Linux, and does not require the PowerPoint application to be installed or licensed.
It can also be used to analyze PowerPoint files from a corpus, perhaps to extract search indexing text and images.
In can also be used to simply automate the production of a slide or two that would be tedious to get right by hand, which is how this all got started.
More information is available in the python-pptx documentation
_.
Browse examples with screenshots
_ to get a quick idea what you can do with
python-pptx.
.. _python-pptx documentation
:
https://python-pptx.readthedocs.org/en/latest/
.. _examples with screenshots
:
https://python-pptx.readthedocs.org/en/latest/user/quickstart.html
.. :changelog:
0.6.23 (2023-11-02) +++++++++++++++++++
0.6.22 (2023-08-28) +++++++++++++++++++
shapes.add_ole_object()
license
should be short string0.6.21 (2021-09-20) +++++++++++++++++++
0.6.20 (2021-09-14) +++++++++++++++++++
0.6.19 (2021-05-17) +++++++++++++++++++
0.6.18 (2019-05-02) +++++++++++++++++++
.text property getters encode line-break as a vertical-tab (VT, '\v', ASCII 11/x0B). This is consistent with PowerPoint's copy/paste behavior and allows like-breaks (soft carriage-return) to be distinguished from paragraph boundary. Previously, a line-break was encoded as a newline ('\n') and was not distinguishable from a paragraph boundary.
.text properties include Shape.text, _Cell.text, TextFrame.text, _Paragraph.text and _Run.text.
.text property setters accept vertical-tab character and place a line-break element in that location. All other control characters other than horizontal-tab ('\t') and newline ('\n') in range \x00-\x1F are accepted and escaped with plain-text like "_x001B" for ESC (ASCII 27).
Previously a control character other than tab or newline in an assigned string would trigger an exception related to invalid XML character.
0.6.17 (2018-12-16) +++++++++++++++++++
0.6.16 (2018-11-09) +++++++++++++++++++
0.6.15 (2018-09-24) +++++++++++++++++++
0.6.14 (2018-09-24) +++++++++++++++++++
0.6.13 (2018-09-10) +++++++++++++++++++
0.6.12 (2018-08-11) +++++++++++++++++++
0.6.11 (2018-07-25) +++++++++++++++++++
0.6.10 (2018-06-11) +++++++++++++++++++
shape.shadow
property to autoshape, connector, picture, and group
shape, returning a ShadowFormat
object.ShadowFormat
object with read/write (boolean) .inherit
property.0.6.9 (2018-05-08) ++++++++++++++++++
Picture.crop_x
setters, allowing picture cropping values to be set,
in addition to interrogated.Slide.background
and SlideMaster.background
, allowing the
background fill to be set for an individual slide or for all slides based
on a slide master.shapes
parameter to Shapes.add_group_shape
, allowing a group
shape to be formed from a number of existing shapes.Shapes._next_shape_id
property to improve
performance on high shape-count slides.0.6.8 (2018-04-18) ++++++++++++++++++
GroupShape
, providing properties specific to a group shape, including
its shapes
property.GroupShapes
, providing access to shapes contained in a group shape.SlideShapes.add_group_shape()
, allowing a group shape to be added to
a slide.GroupShapes.add_group_shape()
, allowing a group shape to be added to
a group shape, enabling recursive, multi-level groups.0.6.7 (2017-10-30) ++++++++++++++++++
SlideShapes.build_freeform()
, allowing freeform shapes (such as maps)
to be specified and added to a slide.LineFormat.dash_style
to allow interrogation and setting of dashed
line styles.0.6.6 (2017-06-17) ++++++++++++++++++
Add SlideShapes.add_movie()
, allowing video media to be added to a slide.
fix #190 Accommodate non-conforming part names having '00' index segment.
fix #273 Accommodate non-conforming part names having no index segment.
fix #277 ASCII/Unicode error on non-ASCII multi-level category names
fix #279 BaseShape.id warning appearing on placeholder access.
0.6.5 (2017-03-21) ++++++++++++++++++
#267 compensate for non-conforming PowerPoint behavior on c:overlay element
compensate for non-conforming (to spec) PowerPoint behavior related to c:dLbl/c:tx that results in "can't save" error when explicit data labels are added to bubbles on a bubble chart.
0.6.4 (2017-03-17) ++++++++++++++++++
0.6.3 (2017-02-28) ++++++++++++++++++
0.6.2 (2017-01-03) ++++++++++++++++++
BACKWARD INCOMPATIBILITIES:
Some changes were made to the boilerplate XML used to create new charts. This was done to more closely adhere to the settings PowerPoint uses when creating a chart using the UI. This may result in some appearance changes in charts after upgrading. In particular:
0.6.1 (2016-10-09) ++++++++++++++++++
0.6.0 (2016-08-18) ++++++++++++++++++
0.5.8 (2015-11-27) ++++++++++++++++++
0.5.7 (2015-01-17) ++++++++++++++++++
BACKWARD INCOMPATIBILITIES:
Shape.shape_type is now unconditionally MSO_SHAPE_TYPE.PLACEHOLDER
for all
placeholder shapes. Previously, some placeholder shapes reported
MSO_SHAPE_TYPE.AUTO_SHAPE
, MSO_SHAPE_TYPE.CHART
,
MSO_SHAPE_TYPE.PICTURE
, or MSO_SHAPE_TYPE.TABLE
for that property.
0.5.6 (2014-12-06) ++++++++++++++++++
0.5.5 (2014-11-17) ++++++++++++++++++
0.5.4 (2014-11-15) ++++++++++++++++++
0.5.3 (2014-11-09) ++++++++++++++++++
0.5.2 (2014-10-26) ++++++++++++++++++
0.5.1 (2014-09-22) ++++++++++++++++++
feature #120 - add Shape.rotation
feature #97 - add Font.underline
issue #117 - add BMP image support
issue #95 - add BaseShape.name setter
issue #107 - all .text properties should return unicode, not str
feature #106 - add .text getters to Shape, TextFrame, and Paragraph
Rename Shape.textframe to Shape.text_frame. Shape.textframe property (by that name) is deprecated.
0.5.0 (2014-09-13) ++++++++++++++++++
BACKWARD INCOMPATIBILITIES:
A table is no longer treated as a shape. Rather it is a graphical object contained in a GraphicFrame shape, as are Chart and SmartArt objects.
Example::
table = shapes.add_table(...)
# becomes
graphic_frame = shapes.add_table(...)
table = graphic_frame.table
# or
table = shapes.add_table(...).table
As the enclosing shape, the id, name, shape type, position, and size are attributes of the enclosing GraphicFrame object.
The contents of a GraphicFrame shape can be identified using three available properties on a shape: has_table, has_chart, and has_smart_art. The enclosed graphical object is obtained using the properties GraphicFrame.table and GraphicFrame.chart. SmartArt is not yet supported. Accessing one of these properties on a GraphicFrame not containing the corresponding object raises an exception.
0.4.2 (2014-04-29) ++++++++++++++++++
0.4.1 (2014-04-29) ++++++++++++++++++
Rename Presentation.slidemasters to Presentation.slide_masters. Presentation.slidemasters property is deprecated.
Rename Presentation.slidelayouts to Presentation.slide_layouts. Presentation.slidelayouts property is deprecated.
Rename SlideMaster.slidelayouts to SlideMaster.slide_layouts. SlideMaster.slidelayouts property is deprecated.
Rename SlideLayout.slidemaster to SlideLayout.slide_master. SlideLayout.slidemaster property is deprecated.
Rename Slide.slidelayout to Slide.slide_layout. Slide.slidelayout property is deprecated.
Add SlideMaster.shapes to access shapes on slide master.
Add SlideMaster.placeholders to access placeholder shapes on slide master.
Add _MasterPlaceholder class.
Add _LayoutPlaceholder class with position and size inheritable from master placeholder.
Add _SlidePlaceholder class with position and size inheritable from layout placeholder.
Add Table.left, top, width, and height read/write properties.
Add rudimentary GroupShape with left, top, width, and height properties.
Add rudimentary Connector with left, top, width, and height properties.
Add TextFrame.auto_size property.
Add Presentation.slide_width and .slide_height read/write properties.
Add LineFormat class providing access to read and change line color and width.
Add AutoShape.line
Add Picture.line
Rationalize enumerations. Note backward incompatibilities below
BACKWARD INCOMPATIBILITIES:
The following enumerations were moved/renamed during the rationalization of enumerations:
pptx.enum.MSO_COLOR_TYPE
--> pptx.enum.dml.MSO_COLOR_TYPE
pptx.enum.MSO_FILL
--> pptx.enum.dml.MSO_FILL
pptx.enum.MSO_THEME_COLOR
--> pptx.enum.dml.MSO_THEME_COLOR
pptx.constants.MSO.ANCHOR_*
--> pptx.enum.text.MSO_ANCHOR.*
pptx.constants.MSO_SHAPE
--> pptx.enum.shapes.MSO_SHAPE
pptx.constants.PP.ALIGN_*
--> pptx.enum.text.PP_ALIGN.*
pptx.constants.MSO.{SHAPE_TYPES}
-->
pptx.enum.shapes.MSO_SHAPE_TYPE.*
Documentation for all enumerations is available in the Enumerations section of the User Guide.
0.3.2 (2014-02-07) ++++++++++++++++++
0.3.1 (2014-01-10) ++++++++++++++++++
0.3.0 (2013-12-12) ++++++++++++++++++
0.2.6 (2013-06-22) ++++++++++++++++++
0.2.5 (2013-06-11) ++++++++++++++++++
0.2.4 (2013-05-16) ++++++++++++++++++
0.2.3 (2013-05-05) ++++++++++++++++++
0.2.2 (2013-03-25) ++++++++++++++++++
0.2.1 (2013-02-25) ++++++++++++++++++
__version__
from
package __init__.py
file.0.2.0 (2013-02-10) ++++++++++++++++++
First non-alpha release with basic capabilities: