Last modified: Aug 23, 2026

Python PPTX: Use Template for Easy Slides

Creating presentations from scratch with code can be tedious. You must style every text box, set fonts, and position elements manually. This process eats up your time and often leads to inconsistent designs.

Fortunately, the python-pptx library offers a smarter way. You can load an existing PowerPoint file as a template. This lets you reuse its layouts, themes, and placeholders. You simply fill in the content. This method is fast, clean, and perfect for reports or automated decks.

This guide shows you how to use a template with python-pptx. You will learn to modify slides, add text, and handle placeholders correctly. No complex styling is required.

Why Use a Template?

Templates save you from reinventing the wheel. They contain pre-designed slide masters and layouts. Your organization's branding, colors, and fonts are already set. You just insert your data.

This approach ensures every generated file looks professional. It also reduces the risk of layout errors. Your code becomes shorter and easier to maintain. Instead of specifying every coordinate, you target named placeholders.

For a deeper understanding of the library's core functions, you might explore other resources. But this guide covers everything you need to start.

Setting Up Your Environment

First, install the library. Use pip in your terminal or command prompt.


pip install python-pptx

Next, you need a template file. Create one manually in PowerPoint. Save it as .pptx. For this example, we will use a simple template with a title slide and a content slide.

Make sure your template has clear placeholders. Go to "View" and "Slide Master" to edit them. Give each placeholder a unique name or index. This helps you identify them later in your code.

Loading the Template

The core task is to load the file. The Presentation function accepts a file path. This is your starting point.


from pptx import Presentation

# Load the existing template file
prs = Presentation("my_template.pptx")
print("Template loaded successfully.")

When you load a file this way, python-pptx does not create a new blank presentation. It uses the existing slides, layouts, and theme. This is the key to using a template effectively.

All your edits will be saved to a new file later. The original template remains untouched. This is great for repeated use.

Understanding Slide Layouts

A template contains multiple layouts. Each layout has a specific purpose. For instance, a "Title Slide" layout differs from a "Content Slide" layout.

To add a new slide, you must choose a layout. The slide_layouts property gives you access to them. You can select one by its index or name.


# Access the slide layouts from the template
layout = prs.slide_layouts[0]  # Usually the title slide layout
print("Selected layout:", layout.name)

Using the template's layouts ensures your new slides match the existing design. You do not need to define shapes or positions manually. The layout handles that.

Adding and Filling Slides

Now, let's add a slide using a layout. Then, we will fill its placeholders with text. The placeholders property is your friend here.


# Add a new slide using the title layout
slide = prs.slides.add_slide(layout)

# Find the title placeholder (usually index 0)
title_placeholder = slide.shapes.title
title_placeholder.text = "Quarterly Report"

# Find the subtitle placeholder (usually index 1)
subtitle_placeholder = slide.placeholders[1]
subtitle_placeholder.text = "Prepared by Data Team"

Notice how we used slide.shapes.title. This is a shortcut for the title placeholder. For other placeholders, we use the placeholders collection with an index.

This method works because the template defines the placeholder's position and style. Your text inherits the template's font, size, and color. This is the main advantage of using a template.

Working with Content Slides

For a content slide, you might have a title and a body placeholder. The body can contain bullet points. Let's see how to handle that.


# Get the content slide layout (often index 1)
content_layout = prs.slide_layouts[1]

# Add a new slide
slide2 = prs.slides.add_slide(content_layout)

# Set the title
slide2.shapes.title.text = "Key Findings"

# Get the body placeholder (index 1)
body_placeholder = slide2.placeholders[1]

# Access the text frame
text_frame = body_placeholder.text_frame

# Add the first bullet point
text_frame.text = "Revenue increased by 20%"

# Add more bullet points
p = text_frame.add_paragraph()
p.text = "Customer satisfaction is high"

p2 = text_frame.add_paragraph()
p2.text = "New features are on track"

Here, we cleared the placeholder's initial text by setting text_frame.text. Then, we added paragraphs. Each paragraph becomes a new bullet point in the template's style.

This is efficient. You do not need to worry about indentation or bullet symbols. The template provides them.

Modifying Existing Slides

Sometimes, you might not want to add new slides. You may want to edit slides that are already in the template. This is common for creating a final report from a draft.

You can iterate through the slides in the presentation. Then, you can access their shapes and change text.


# Loop through all slides in the presentation
for slide in prs.slides:
    # Loop through all shapes on the slide
    for shape in slide.shapes:
        # Check if the shape has a text frame
        if shape.has_text_frame:
            # Get the text frame
            text_frame = shape.text_frame
            # Replace specific text
            for paragraph in text_frame.paragraphs:
                for run in paragraph.runs:
                    if "OLD_TEXT" in run.text:
                        run.text = run.text.replace("OLD_TEXT", "NEW_TEXT")

This code scans every shape. It looks for text frames and then checks the runs. Runs are the smallest unit of text with similar formatting. This is useful for global replacements.

Be careful with this approach. It changes every matching instance. Ensure your search text is unique to avoid unwanted changes.

Adding Images and Charts

Templates are not just for text. You can also add pictures and charts. The template's layout will position them if you use placeholders. But you can also add shapes freely.

To add a picture, you use the add_picture method. You need to provide the image path and optional position.


# Add a picture to a slide
from pptx.util import Inches

# Assuming 'slide' is a slide object
pic = slide.shapes.add_picture("chart.png", Inches(1), Inches(2), width=Inches(4))
print("Picture added at:", pic.left, pic.top)

The Inches class helps you specify dimensions. You can also use Pt for points or Cm for centimeters. This gives you control over placement if needed.

For charts, the process is more complex. You would need to use the add_chart method. However, using a template with a chart placeholder is easier. You can just insert data into the existing chart.

Saving Your Work

After making all your changes, you must save the file. Use the save method. Give it a new filename to keep the original template clean.


# Save the modified presentation to a new file
prs.save("final_presentation.pptx")
print("Presentation saved as final_presentation.pptx")

The output is a standard .pptx file. You can open it in PowerPoint or Google Slides. The formatting from your template will be intact.

This is the final step. Your automated presentation is ready for distribution.

Conclusion

Using a template with python-pptx is a powerful technique. It simplifies your code and ensures consistent design. You focus on content, not on styling.

We covered loading a template, selecting layouts, adding slides, and filling placeholders. You also learned to modify existing slides and add images. The key is to leverage the template's predefined structure.

Start by creating a solid template in PowerPoint. Then, use the methods shown here to populate it. This will save you hours of manual work and reduce errors. Your presentations will look professional every single time.