There are three ways to generate PowerPoint files from Python in 2026: the python-pptx library (free, full control), the SlideForge API ($0.03/slide, consulting-quality), and PptxGenJS via a Node.js subprocess. This tutorial covers all three with working code, so you can pick the right approach for your use case.
1. python-pptx: The Standard Library
python-pptxis the de facto Python library for creating and modifying PowerPoint files. It's free, open source (MIT license), and gives you full programmatic control over every element in a .pptx file.
Install and create a basic slide
pip install python-pptxfrom pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor
# Create presentation
prs = Presentation()
prs.slide_width = Inches(13.333)
prs.slide_height = Inches(7.5)
# Add a blank slide
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Add a title
title = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(12), Inches(0.6))
tf = title.text_frame
tf.text = "Q1 2026 Performance"
tf.paragraphs[0].font.size = Pt(28)
tf.paragraphs[0].font.bold = True
# Save
prs.save("basic_slide.pptx")This works. But the output looks like it was made by a developer, not a designer. No color harmony, no spacing system, no visual hierarchy beyond font size.
Building a real slide: KPI Dashboard
Here's what it takes to build a consulting-quality KPI dashboard with python-pptx:
from pptx import Presentation
from pptx.util import Inches, Pt, Emu
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN
prs = Presentation()
prs.slide_width = Inches(13.333)
prs.slide_height = Inches(7.5)
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Title
title = slide.shapes.add_textbox(
Inches(0.5), Inches(0.3), Inches(12), Inches(0.6)
)
tf = title.text_frame
tf.text = "Q1 2026 Performance Summary"
tf.paragraphs[0].font.size = Pt(28)
tf.paragraphs[0].font.bold = True
# KPI metrics — repeat for each one
metrics = [
("$12.4M", "Revenue", "+18% YoY"),
("847", "New Clients", "+23%"),
("94.2%", "Retention Rate", ""),
("4.7", "NPS Score", "+0.3"),
]
for i, (value, label, trend) in enumerate(metrics):
left = Inches(0.5 + i * 3.1)
top = Inches(1.5)
width = Inches(2.8)
height = Inches(2.0)
# Background box
box = slide.shapes.add_shape(1, left, top, width, height)
box.fill.solid()
box.fill.fore_color.rgb = RGBColor(0xF5, 0xF5, 0xF5)
box.line.fill.background()
# Value text
val_box = slide.shapes.add_textbox(left, Inches(1.7), width, Inches(0.8))
val_tf = val_box.text_frame
val_tf.text = value
val_tf.paragraphs[0].font.size = Pt(36)
val_tf.paragraphs[0].font.bold = True
val_tf.paragraphs[0].alignment = PP_ALIGN.CENTER
# Label text
lbl_box = slide.shapes.add_textbox(left, Inches(2.5), width, Inches(0.4))
lbl_tf = lbl_box.text_frame
lbl_tf.text = label.upper()
lbl_tf.paragraphs[0].font.size = Pt(9)
lbl_tf.paragraphs[0].font.color.rgb = RGBColor(0x99, 0x99, 0x99)
lbl_tf.paragraphs[0].alignment = PP_ALIGN.CENTER
# ... and trend text, accent lines, spacing adjustments...
prs.save("kpi_dashboard.pptx")
# ~60 lines for a basic version. A polished version is 100+.That's ~60 lines for a basic KPI dashboard. A polished version with accent lines, trend arrows, tinted backgrounds, and a takeaway banner runs 100+ lines. And this is one slide type — a consulting deck needs 10-15 different layouts.
The pain points
- Alignment is manual. Every coordinate is hardcoded in inches. Move one element and everything else needs adjusting.
- No design system. Colors, fonts, and spacing are ad-hoc. Consistency across slides requires discipline and shared constants.
- Limited chart support. No waterfall, treemap, or sunburst charts. Combo charts can corrupt files.
- No animations. The #1 requested feature (GitHub issue #1106) — still unsupported.
- Maintenance burden. Every new slide type is a multi-day project. Bug fixes in one template can break another.
2. SlideForge API: Consulting-Quality in 5 Lines
SlideForge generates the same KPI dashboard — with monochromatic color harmony, typographic hierarchy, accent lines, and proper spacing — from a single API call:
import requests
response = requests.post(
"https://api.slideforge.dev/v1/render",
headers={"Authorization": "Bearer sf_live_..."},
json={
"template": "kpi_dashboard",
"params": {
"title": "Q1 2026 Performance Summary",
"metrics": [
{"value": "$12.4M", "label": "Revenue", "trend": "+18% YoY"},
{"value": "847", "label": "New Clients", "trend": "+23%"},
{"value": "94.2%", "label": "Retention Rate"},
{"value": "4.7", "label": "NPS Score", "trend": "+0.3"},
],
"takeaway": "On track for $50M full-year target",
},
},
)
result = response.json()
print(result["pptx_url"]) # Download the .pptx
print(result["preview_url"]) # PNG previewThat's it. The output is a native .pptx file with editable shapes — open it in PowerPoint and change anything. Template render completes in under 1 second at $0.03/slide.
For slides that don't fit a template, describe what you want in plain English:
response = requests.post(
"https://api.slideforge.dev/v1/generate",
headers={"Authorization": "Bearer sf_live_..."},
json={
"brief": "2x2 matrix: effort vs impact. Quick wins top-left, "
"strategic bets top-right. Label each quadrant with "
"3-4 example initiatives.",
},
)
# AI generates a custom layout in ~30 seconds, $0.203. When to Use Which
| Criteria | python-pptx | SlideForge API |
|---|---|---|
| Cost | Free | $0.03-$0.20/slide |
| Setup time | Days-weeks | Minutes |
| Visual quality | DIY (your layout code) | Consulting-grade (9/10) |
| Template library | Build your own | 50+ built-in |
| AI generation | No | Yes ($0.20/slide) |
| Offline use | Yes | No (API) |
| Full control | Yes (any XML) | Template params or AI brief |
| Maintenance | You maintain it | Managed service |
Use python-pptx if you need full programmatic control, work in air-gapped environments, or have zero budget and unlimited time.
Use SlideForge if you want consulting-quality output without writing layout code, need an API for automation or AI agents, or want to ship in minutes instead of weeks.
They're also compatible: SlideForge uses python-pptx under the hood, and the output is a standard .pptx that python-pptx can open and modify for post-processing.
Getting Started
Sign up for free ($3 credit, no card) and follow the quickstart guide to generate your first slide. Or read the detailed comparison of SlideForge vs python-pptx.