# pip install python-pptxRevamp 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
prs = Presentation("report_template.pptx") # Load an existing PowerPoint file
# prs = Presentation() # (Alternative) Create a new empty presentationStep 2: Add a New Slide
slide_layout = prs.slide_layouts[1] # Use layout with title and content
slide = prs.slides.add_slide(slide_layout) # Add a new slide to the presentation
title = slide.shapes.title # Access the title placeholder
content = slide.placeholders[1] # Access the content box
title.text = "Weekly Sales Overview" # Set the title text
content.text = "This slide summarizes the sales data for the week." # Set the content textStep 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
plt.figure(figsize=(6, 4))
plt.plot([1, 2, 3], [10, 20, 15], marker='o') # Sample line plot
plt.title("Weekly Revenue Trend")
plt.xlabel("Week")
plt.ylabel("Revenue")
plt.tight_layout()
plt.savefig("revenue_trend.png") # Save the chart as a PNG image
plt.close()
# Step 4b: Insert the image into the slide
slide = prs.slides.add_slide(prs.slide_layouts[5]) # Add a blank slide
slide.shapes.add_picture("revenue_trend.png", Inches(1), Inches(2), width=Inches(6))
# 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)
rows, cols = 3, 2 # Define number of rows and columns
left = Inches(1)
top = Inches(2)
width = Inches(6)
height = Inches(1.5)
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# Add a table shape to the slide
table.cell(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%'Step 6: Save the Presentation
prs.save("report_template.pptx") # Save the modified or new fileCan 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.