Last modified: Aug 23, 2026

Automate PowerPoint with Python

Creating PowerPoint presentations manually is time-consuming. You often repeat the same steps for every report or update. Automating this process saves hours and reduces errors.

Python offers a powerful library called python-pptx. It lets you create, modify, and read PowerPoint files entirely from code. This guide shows you how to use it effectively.

You will learn to build slides, add text, insert images, and apply styles. By the end, you can generate professional decks in seconds. Let's get started.

Install the Required Library

First, you need to install the library. Open your terminal or command prompt and run this command.


pip install python-pptx

This installs the library and its dependencies. Once installed, you can import it in your Python script. The import statement is simple.


from pptx import Presentation
from pptx.util import Inches, Pt

The Presentation class handles the entire file. The utility modules help with measurements and font sizes. Now you're ready to build your first slide.

Create a Basic Presentation

Start by creating a new presentation object. This object represents an empty PowerPoint file. Then, add a slide layout to it.


# Create a new presentation
prs = Presentation()

# Use the first slide layout (Title Slide)
slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(slide_layout)

# Add a title
slide.shapes.title.text = "Hello, PowerPoint!"

# Add a subtitle
slide.placeholders[1].text = "Created with Python"

# Save the file
prs.save("hello.pptx")

Run this script. It creates a file named hello.pptx in your current directory. Open it to see a title slide with your text.

This basic example shows the core workflow. You create a presentation, add slides, and populate them. The same pattern works for all slide types.

Add Text and Formatting

Text boxes are the most common element. You can add them anywhere on a slide. Use the add_textbox method for full control.


from pptx.enum.text import PP_ALIGN

# Add a text box to the slide
left = Inches(1)
top = Inches(2)
width = Inches(6)
height = Inches(1.5)

textbox = slide.shapes.add_textbox(left, top, width, height)
text_frame = textbox.text_frame

# Clear default paragraph
text_frame.clear()

# Add first paragraph
p = text_frame.paragraphs[0]
p.text = "This is bold text"
p.font.bold = True
p.font.size = Pt(24)

# Add second paragraph
p2 = text_frame.add_paragraph()
p2.text = "This is centered text"
p2.alignment = PP_ALIGN.CENTER
p2.font.italic = True

Formatting is straightforward. You can set bold, italic, size, and alignment. Each paragraph is independent, giving you great flexibility.

Important: Always clear the default paragraph before adding new ones. Otherwise, you might get unexpected empty lines.

Insert Images

Images make presentations visual. The add_picture method handles this easily. You specify the file path and position.


# Add an image to the slide
pic_left = Inches(1)
pic_top = Inches(3)
pic_width = Inches(4)

slide.shapes.add_picture("chart.png", pic_left, pic_top, pic_width)

This adds a picture at the specified location. The width is set, and the height adjusts automatically to maintain aspect ratio. For more details, check our Python PPTX Add Picture Guide.

You can also control height and width explicitly. Just pass both parameters to the method. This is useful for logos or icons where you need exact dimensions.

Work with Tables

Tables are essential for data presentation. The add_table method creates a grid. You can then fill it with data.


# Add a table
rows, cols = 3, 3
left = Inches(0.5)
top = Inches(3)
width = Inches(8)
height = Inches(2)

table_shape = slide.shapes.add_table(rows, cols, left, top, width, height)
table = table_shape.table

# Fill the table with data
table.cell(0, 0).text = "Product"
table.cell(0, 1).text = "Price"
table.cell(0, 2).text = "Stock"

table.cell(1, 0).text = "Laptop"
table.cell(1, 1).text = "$1200"
table.cell(1, 2).text = "15"

table.cell(2, 0).text = "Mouse"
table.cell(2, 1).text = "$25"
table.cell(2, 2).text = "100"

Tables are great for structured data. You can style them further by changing cell colors and fonts. The library gives you full access to every cell property.

Use Templates

Starting from scratch is fine, but templates save time. You can load an existing PowerPoint file and modify it. This preserves the design and branding.


# Load an existing template
prs = Presentation("company_template.pptx")

# Add a new slide using a specific layout
slide_layout = prs.slide_layouts[1]  # Content layout
slide = prs.slides.add_slide(slide_layout)

# Add content
slide.shapes.title.text = "Quarterly Report"
slide.placeholders[1].text = "Revenue increased by 20%"

prs.save("report.pptx")

Templates are ideal for business reports. They keep your slides consistent and professional. Learn more in our Python PPTX: Use Template for Easy Slides guide.

Important: Always save the modified presentation with a new filename. This prevents overwriting your original template.

Apply Styles and Themes

Styling makes slides look good. You can change background colors, font colors, and more. The library supports many styling options.


from pptx.dml.color import RGBColor

# Change slide background color
background = slide.background
fill = background.fill
fill.solid()
fill.fore_color.rgb = RGBColor(0x2E, 0x86, 0xAB)  # Blue color

# Change font color of a text box
for paragraph in text_frame.paragraphs:
    for run in paragraph.runs:
        run.font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF)  # White

Colors are specified as RGB values. You can create any color by combining red, green, and blue components. This gives you complete design control.

The RGBColor class is your friend. Use it to match your brand colors exactly. This is perfect for client presentations.

Add Charts

Charts visualize data effectively. The library supports common chart types like bar, line, and pie. You create a chart and add data to it.


from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE

# Create chart data
chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Sales', (100, 150, 200, 180))

# Add chart to slide
left = Inches(1)
top = Inches(2)
width = Inches(6)
height = Inches(4)

chart = slide.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED,
    left, top, width, height,
    chart_data
)

Charts update dynamically with your data. You can customize colors, labels, and titles. This is excellent for dashboards and reports.

You can also create line charts or pie charts by changing the chart type constant. The API is consistent across all types.

Loop Through Multiple Slides

Automation shines when you need many slides. Loops let you generate dozens of slides from a data list. This is perfect for batch reports.


# Data for slides
products = ["Laptop", "Mouse", "Keyboard", "Monitor"]
prices = [1200, 25, 80, 350]

# Create a new presentation
prs = Presentation()

# Use a blank layout
slide_layout = prs.slide_layouts[6]

for i, product in enumerate(products):
    slide = prs.slides.add_slide(slide_layout)
    
    # Add title
    slide.shapes.title.text = f"Product: {product}"
    
    # Add price
    left = Inches(1)
    top = Inches(2)
    width = Inches(4)
    height = Inches(1)
    
    textbox = slide.shapes.add_textbox(left, top, width, height)
    textbox.text_frame.text = f"Price: ${prices[i]}"

prs.save("products.pptx")

This loop creates four slides, one for each product. The enumerate function gives you the index to access price data. This pattern scales to thousands of slides.

You can read data from CSV files or databases. The loop structure remains the same. This makes your presentations data-driven and always up-to-date.

Practical Example: Sales Report

Let's combine everything into a real-world example. We'll generate a sales report with a title slide, a data table, and a chart.


from pptx import Presentation
from pptx.util import Inches
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE

# Create presentation
prs = Presentation()

# Slide 1: Title
slide1 = prs.slides.add_slide(prs.slide_layouts[0])
slide1.shapes.title.text = "Annual Sales Report 2024"
slide1.placeholders[1].text = "Prepared by Data Team"

# Slide 2: Table
slide2 = prs.slides.add_slide(prs.slide_layouts[5])  # Title and Content
slide2.shapes.title.text = "Quarterly Breakdown"

# Add table
rows, cols = 3, 5
left = Inches(0.5)
top = Inches(1.5)
width = Inches(9)
height = Inches(1.5)
table_shape = slide2.shapes.add_table(rows, cols, left, top, width, height)
table = table_shape.table

# Headers
headers = ["Quarter", "Revenue", "Expenses", "Profit", "Growth"]
for col, header in enumerate(headers):
    table.cell(0, col).text = header

# Data
data = [
    ["Q1", "$100K", "$60K", "$40K", "10%"],
    ["Q2", "$120K", "$65K", "$55K", "15%"],
]

for row, row_data in enumerate(data, start=1):
    for col, value in enumerate(row_data):
        table.cell(row, col).text = value

# Slide 3: Chart
slide3 = prs.slides.add_slide(prs.slide_layouts[5])
slide3.shapes.title.text = "Revenue Trend"

chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Revenue', (100, 120, 150, 180))

slide3.shapes.add_chart(
    XL_CHART_TYPE.LINE,
    Inches(1), Inches(1.5), Inches(8), Inches(4),
    chart_data
)

# Save
prs.save("sales_report.pptx")
print("Report generated successfully!")

Run this script. It creates a three-slide presentation with a title, a table, and a chart. Open the file to see your professional report.

This example demonstrates the full power of automation. You can easily modify the data or add more slides. The code is clean and reusable.

Conclusion

Automating PowerPoint with Python is a game-changer. You save hours of manual work and ensure consistency across presentations. The python-pptx library handles all common tasks.

You learned to create slides, add text, insert images, build tables, and generate charts. You also saw how to use templates and loops for large-scale projects. These skills apply directly to real-world tasks.

Start small with a simple script, then expand. Automate your weekly reports or client decks. The possibilities are endless. Your future self will thank you.

Remember to explore the library's documentation for advanced features. Combine it with other Python libraries like pandas for data analysis. This makes your automation even more powerful.

Now go ahead and automate your next presentation. It's easier than you think.