Last modified: Aug 23, 2026
Create PowerPoint with Python: A Simple Guide
Creating presentations manually is repetitive and time-consuming. You can automate this entire process using Python. This guide shows you how to create a PowerPoint presentation using Python with the python-pptx library.
This approach is perfect for generating reports, dashboards, or bulk slide decks. You can build a presentation in seconds with just a few lines of code. Let’s get started.
Setting Up Your Environment
First, you need to install the library. Open your terminal or command prompt and run the following command. This will install the python-pptx package.
pip install python-pptx
Once installed, you can import it in your script. The main module is Presentation. This module handles the entire lifecycle of your PowerPoint file.
Creating Your First Slide
Start by creating a new presentation object. This object represents your entire .pptx file. Then, you can add slides to it using the default layout.
Here is the basic code to create a presentation with a single blank slide.
from pptx import Presentation
from pptx.util import Inches
# Create a new presentation object
prs = Presentation()
# Use the first layout (usually Title Slide)
slide_layout = prs.slide_layouts[0]
# Add a slide with that layout
slide = prs.slides.add_slide(slide_layout)
# Save the presentation
prs.save('my_first_presentation.pptx')
print("Presentation created successfully!")
Run this script. You will see a new file named my_first_presentation.pptx in your directory. Open it, and you will see a blank title slide.
Adding Text and Titles
Adding text is straightforward. Each slide has placeholders. You can access these placeholders by their index. For a title slide, index 0 is usually the title, and index 1 is the subtitle.
Let's add a title and a subtitle to our slide. We will use the text_frame property to set the text.
from pptx import Presentation
prs = Presentation()
slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(slide_layout)
# Access the title placeholder (index 0)
title = slide.shapes.title
title.text = "Hello, Python!"
# Access the subtitle placeholder (index 1)
subtitle = slide.placeholders[1]
subtitle.text = "This presentation was created with code."
prs.save('my_text_presentation.pptx')
You can also add a new text box if you need more control. Use the add_textbox method. This is helpful for custom positioning.
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
blank_layout = prs.slide_layouts[6] # Blank layout
slide = prs.slides.add_slide(blank_layout)
# Add a text box at specific coordinates
left = Inches(1)
top = Inches(1)
width = Inches(5)
height = Inches(1)
textbox = slide.shapes.add_textbox(left, top, width, height)
textbox.text = "Custom Text Box"
# Change font size
for paragraph in textbox.text_frame.paragraphs:
for run in paragraph.runs:
run.font.size = Pt(24)
prs.save('custom_textbox.pptx')
Using custom text boxes gives you full control over layout. You can place content anywhere on the slide.
Adding Pictures and Images
Visuals make presentations better. You can easily add images to your slides. Use the add_picture method. This method requires the path to your image file.
Here is an example of adding a picture to a slide. You can also adjust its size and position. For a more detailed guide on this topic, check out our Python PPTX Add Picture Guide.
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
blank_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_layout)
# Add a picture
left = Inches(2)
top = Inches(2)
width = Inches(4) # Height auto-adjusts if not specified
pic = slide.shapes.add_picture('path/to/your/image.png', left, top, width=width)
prs.save('picture_presentation.pptx')
Make sure your image file exists in the specified path. You can use absolute paths or relative paths. This method makes it easy to create image-heavy decks programmatically.
Using Templates for Consistency
Starting from scratch is fine, but using a template can save time. Templates have predefined styles, fonts, and layouts. You can load an existing template and modify it.
This is a powerful feature. You can create a branded template once and then use Python to fill in the data. To learn how to do this effectively, read our guide on Python PPTX: Use Template for Easy Slides.
Here is a quick example of using a template. You load the template like a regular presentation.
from pptx import Presentation
# Load an existing template file
prs = Presentation('my_template.pptx')
# Now you can add slides or modify existing ones
slide_layout = prs.slide_layouts[1] # Use a specific layout from the template
slide = prs.slides.add_slide(slide_layout)
# Add content to the slide
title = slide.shapes.title
title.text = "Report for Q3"
prs.save('report_from_template.pptx')
Using templates ensures your automated presentations look professional. It also reduces the amount of code you need to write.
Adding Charts and Graphs
Data is more impactful when visualized. The python-pptx library supports adding charts directly. You can add bar charts, line charts, and more.
Here is an example of adding a simple bar chart to a slide. You need to provide the chart data.
from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Define chart data
chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Sales', (250, 300, 275, 350))
# Add chart to slide
left = Inches(1)
top = Inches(1)
width = Inches(6)
height = Inches(4)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED, left, top, width, height, chart_data
)
prs.save('chart_presentation.pptx')
This creates a clustered column chart. You can change the chart type by modifying the XL_CHART_TYPE constant. This feature is excellent for automated reporting.
Conclusion
Creating a PowerPoint presentation using Python is efficient and powerful. You can automate slide creation, add text, images, and even charts. This saves you hours of manual work.
We covered the basics: creating slides, adding text, inserting pictures, and using templates. You can now build simple presentations. As you practice, explore more advanced features like adding tables and animations.
Remember to experiment with different layouts and styles. The python-pptx library is robust. It handles most of your presentation needs. Start automating your next slide deck today.