# pip install python-pptx
Revamp your PowerPoint slides in Python using python-pptx
Introduction: Why should Data Scientists care about PowerPoint Automation?
As data scientists, our job doesn’t end at building models or analyzing data, we need to communicate our insights effectively. PowerPoint remains one of the most widely used formats for reporting to business and non-technical teams.
But let’s face it: manually updating slides every week is time-consuming and repetitive. Whether it’s weekly dashboards, model performance reports, or project updates, we can benefit greatly from automating this part of our workflow.
This is where the python-pptx library becomes incredibly useful. It helps us:
Automatically generate presentation decks from our scripts
Update existing slides with fresh results or visuals
Maintain consistent branding and formatting
Build data pipelines that end with a presentation, not just a spreadsheet
Save valuable time and avoid manual errors
Start with installling the library
Must-Know Functions and Examples
Let’s explore some core features of the python-pptx library with simple code examples:
Step 1: Open or create a presentation
from pptx import Presentation
= Presentation("report_template.pptx") # Load an existing PowerPoint file
prs # prs = Presentation() # (Alternative) Create a new empty presentation
Step 2: Add a New Slide
= prs.slide_layouts[1] # Use layout with title and content
slide_layout = prs.slides.add_slide(slide_layout) # Add a new slide to the presentation
slide
= slide.shapes.title # Access the title placeholder
title = slide.placeholders[1] # Access the content box
content
= "Weekly Sales Overview" # Set the title text
title.text = "This slide summarizes the sales data for the week." # Set the content text content.text
Step 3: Modify text in existing slides
for slide in prs.slides: # Loop through all slides
for shape in slide.shapes: # Loop through shapes on the slide
if shape.has_text_frame: # Check if shape has text
for para in shape.text_frame.paragraphs: # Loop through paragraphs
for run in para.runs: # Loop through text runs (formatting chunks)
print(run.text) # Print existing text (can be updated as needed)
SANATICS - Analytics Lab
Revamp
Your PowerPoint Slides with Python — A Demo Using
python-
pptx
.
This
presentation showcases how we can automate and update slide content using Python.
Weekly Sales Overview
This slide summarizes the sales data for the week.
Step 4: Add an Image (e.g., a chart or plot)
import matplotlib.pyplot as plt
from pptx.util import Inches
# Step 4a: Create and save the plot
=(6, 4))
plt.figure(figsize1, 2, 3], [10, 20, 15], marker='o') # Sample line plot
plt.plot(["Weekly Revenue Trend")
plt.title("Week")
plt.xlabel("Revenue")
plt.ylabel(
plt.tight_layout()"revenue_trend.png") # Save the chart as a PNG image
plt.savefig(
plt.close()
# Step 4b: Insert the image into the slide
= prs.slides.add_slide(prs.slide_layouts[5]) # Add a blank slide
slide "revenue_trend.png", Inches(1), Inches(2), width=Inches(6))
slide.shapes.add_picture(# Add the saved image to slide at position (1", 2") with width 6"
<pptx.shapes.picture.Picture at 0x20372019070>
Step 5: Add a Table (e.g., model metrics)
= 3, 2 # Define number of rows and columns
rows, cols = Inches(1)
left = Inches(2)
top = Inches(6)
width = Inches(1.5)
height
= slide.shapes.add_table(rows, cols, left, top, width, height).table
table # Add a table shape to the slide
0, 0).text = 'Metric' # Set header cell
table.cell(0, 1).text = 'Value'
table.cell(
1, 0).text = 'Accuracy' # Fill in first data row
table.cell(1, 1).text = '92%'
table.cell(
2, 0).text = 'Precision' # Fill in second data row
table.cell(2, 1).text = '89%' table.cell(
Step 6: Save the Presentation
"report_template.pptx") # Save the modified or new file prs.save(
Can python-pptx fetch online information and update content based on prompts or existing slide data?
Not on its own — python-pptx is only for reading and editing PowerPoint files. It can’t fetch data online or respond to prompts by itself.
✅ But with other Python tools, it can: 📡 Fetch online data using requests, BeautifulSoup, newsapi, etc.
🧠 Generate or summarize content using AI (e.g., openai, langchain)
📊 Combine this with python-pptx to auto-update slides with charts, summaries, or KPIs
Together, they can create powerful, automated, and intelligent presentations—updated dynamically based on live data and prompts.
Conclusion: Smarter Presentations, Automated
While python-pptx takes some setup initially, it’s ideal for automating recurring, data-driven presentations—something visual tools like Beautiful.ai can’t fully offer.
It lets us turn raw analysis into ready-to-present slides, right from our scripts—saving time and ensuring consistency.
For data scientists, it’s not just about slides—it’s about automating insight delivery at scale.