Creating PowerPoint presentations manually can be time-consuming, especially when you’re working with repetitive content like reports, sales decks, or training materials. Python can help automate this process, letting you generate presentations right from the command line. In this post, I’ll show you how to create PowerPoint slides using Python with the help of a handy library called python-pptx
.
What You’ll Need
Before we get started, make sure you have the following:
- Python 3 installed
- pip installed
- A terminal or command prompt you’re comfortable using
Step 1: Install the Required Package
The core library we’ll use is python-pptx
. Open your terminal and run:
pip install python-pptx
This package gives you full control over slide creation, formatting, images, tables, and more.
Step 2: Create a Basic Python Script
Let’s write a simple script that creates a PowerPoint file with one title slide and one content slide.
Create a file called create_ppt.py
and paste this in:
from pptx import Presentation
from pptx.util import Inches
# Create a presentation object
prs = Presentation()
# Add a title slide
slide_title = prs.slides.add_slide(prs.slide_layouts[0])
title = slide_title.shapes.title
subtitle = slide_title.placeholders[1]
title.text = "Automated Presentation"
subtitle.text = "Created with Python"
# Add a content slide
slide_content = prs.slides.add_slide(prs.slide_layouts[1])
title, content = slide_content.shapes.title, slide_content.placeholders[1]
title.text = "Why Automate Presentations?"
content.text = "• Save time\n• Reduce errors\n• Easy to update\n• Great for bulk content"
# Save the presentation
prs.save("auto_presentation.pptx")
Step 3: Run the Script from the Command Line
In the terminal, navigate to the folder where your script is saved, then run:
python create_ppt.py
You’ll see a new file named auto_presentation.pptx
appear in the same directory. Open it in PowerPoint, and you’ll find two formatted slides ready to go.
Going Further
Once you get the basics down, you can expand this script to:
- Pull data from Excel or CSV files
- Generate charts and tables
- Insert images and logos
- Create slides in bulk using loops
- Use command-line arguments for flexible input
Example with command-line input:
import sys
slide_title = sys.argv[1] if len(sys.argv) > 1 else "Default Title"
# Use the slide_title variable in your presentation
Now you can run:
python create_ppt.py "Quarterly Sales Update"
Final Thoughts
Using Python to create PowerPoint presentations isn’t just a cool trick—it’s a smart way to streamline your workflow, especially when dealing with repetitive or data-driven content. With a few lines of code, you can standardize and scale your presentation-building process.
Got questions or want to take this further? Drop a comment or reach out—I’m happy to help.
Leave a Reply