Skip to main content

Slides

Sequence of slides belonging to a presentation. Has list semantics for access to individual slides. Supports indexed access, len(), and iteration. Accessed via the slides property of a Presentation object.
from pptx import Presentation

prs = Presentation()
slides = prs.slides

print(len(slides))  # Number of slides
first_slide = slides[0]  # Access by index

Methods

add_slide()

Return a newly added slide that inherits layout from the specified slide layout.
slide_layout
SlideLayout
required
The slide layout to use for the new slide
return
Slide
The newly created slide object
from pptx import Presentation

prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)

get()

Return the slide identified by integer slide_id in this presentation.
slide_id
int
required
The unique slide ID to search for
default
Slide | None
default:"None"
Value to return if slide is not found
return
Slide | None
The slide with the specified ID, or default if not found
slide = prs.slides.get(256)
if slide:
    print(f"Found slide: {slide.slide_id}")

index()

Return the zero-based position of the specified slide in this slide sequence.
slide
Slide
required
The slide to locate in the collection
return
int
Zero-based index of the slide
Raises ValueError if the slide is not in the collection.
slide = prs.slides[2]
position = prs.slides.index(slide)  # Returns 2

Slide

Slide object providing access to shapes and slide-level properties.

Properties

background

_Background - Background object providing slide background properties. This property returns a _Background object whether or not the slide has an explicitly defined background. The same object is returned on every call.

follow_master_background

bool - True if this slide inherits the slide master background. Read/write. Assigning False interrupts background inheritance from the master; if there is no custom background for this slide, a default background is added. If a custom background already exists, assigning False has no effect. Assigning True causes any custom background for this slide to be deleted and inheritance from the master restored.
slide.follow_master_background = False  # Use custom background

has_notes_slide

bool - True if this slide has a notes slide, False otherwise. Use this property to test for a notes slide without the side effect of creating one.

name

str - String representing the internal name of this slide. Read/write. Returns an empty string ('') if no name is assigned. Assigning an empty string or None causes any name to be removed.

notes_slide

NotesSlide - The notes slide instance for this slide. If the slide does not have a notes slide, one is created. The same single instance is returned on each call.
notes_slide = slide.notes_slide
notes_text_frame = notes_slide.notes_text_frame
notes_text_frame.text = "These are speaker notes"

placeholders

SlidePlaceholders - Sequence of placeholder shapes in this slide.
for placeholder in slide.placeholders:
    print(placeholder.placeholder_format.idx)

shapes

SlideShapes - Sequence of shape objects appearing on this slide.
for shape in slide.shapes:
    if shape.has_text_frame:
        print(shape.text)

slide_id

int - Integer value that uniquely identifies this slide within this presentation. The slide id does not change if the position of this slide in the slide sequence is changed by adding, rearranging, or deleting slides.

slide_layout

SlideLayout - Slide layout object this slide inherits appearance from.

SlideLayout

Slide layout object providing access to placeholders, regular shapes, and slide layout-level properties.

Properties

background

_Background - Background object providing slide layout background properties.

name

str - String representing the internal name of this slide layout. Read/write.

placeholders

LayoutPlaceholders - Sequence of placeholder shapes in this slide layout. Placeholders appear in idx order.

shapes

LayoutShapes - Sequence of shapes appearing on this slide layout.

slide_master

SlideMaster - Slide master from which this slide layout inherits properties.

used_by_slides

tuple[Slide, ...] - Tuple of slide objects based on this slide layout.
layout = prs.slide_layouts[1]
slides_using_layout = layout.used_by_slides
print(f"This layout is used by {len(slides_using_layout)} slides")

SlideLayouts

Sequence of slide layouts belonging to a slide master. Supports indexed access, len(), iteration, index() and remove().

Methods

get_by_name()

Return the slide layout object having the specified name.
name
str
required
Name of the slide layout to find
default
SlideLayout | None
default:"None"
Value to return if layout is not found
return
SlideLayout | None
The layout with the specified name, or default if not found
title_layout = prs.slide_layouts.get_by_name("Title Slide")
if title_layout:
    slide = prs.slides.add_slide(title_layout)

index()

Return the zero-based index of the specified slide layout in this collection.
slide_layout
SlideLayout
required
The slide layout to locate
return
int
Zero-based index of the layout
Raises ValueError if the slide layout is not in the collection.

remove()

Remove the specified slide layout from the collection.
slide_layout
SlideLayout
required
The slide layout to remove
Raises ValueError when the slide layout is in use. A slide layout which is the basis for one or more slides cannot be removed.
layout = prs.slide_layouts[5]
if not layout.used_by_slides:
    prs.slide_layouts.remove(layout)

SlideMaster

Slide master object providing access to slide layouts, placeholders, regular shapes, and slide master-level properties.

Properties

background

_Background - Background object providing slide master background properties.

name

str - String representing the internal name of this slide master. Read/write.

placeholders

MasterPlaceholders - Collection of placeholder shapes in this master, sorted in idx order.

shapes

MasterShapes - Sequence of shape objects appearing on this slide master.

slide_layouts

SlideLayouts - Collection of slide layouts belonging to this slide master.
master = prs.slide_master
for layout in master.slide_layouts:
    print(layout.name)

SlideMasters

Sequence of slide master objects belonging to a presentation. Has list semantics supporting indexed access, len(), and iteration.
for master in prs.slide_masters:
    print(f"Master has {len(master.slide_layouts)} layouts")

NotesSlide

Notes slide object providing access to slide notes placeholder and other shapes on the notes page.

Properties

background

_Background - Background object providing notes slide background properties.

name

str - String representing the internal name of this notes slide. Read/write.

notes_placeholder

NotesSlidePlaceholder | None - The notes placeholder on this notes slide. This is the shape that contains the actual notes text. Returns None if no notes placeholder is present (uncommon).

notes_text_frame

TextFrame | None - The text frame of the notes placeholder on this notes slide. Returns None if there is no notes placeholder. This is a shortcut for the common case of simply adding notes text to the notes page.
slide = prs.slides[0]
notes_slide = slide.notes_slide
text_frame = notes_slide.notes_text_frame
if text_frame:
    text_frame.text = "Remember to mention the Q4 results"

placeholders

NotesSlidePlaceholders - Sequence of placeholder shapes in this notes slide.

shapes

NotesSlideShapes - Sequence of shape objects appearing on this notes slide.

Build docs developers (and LLMs) love