python-pptx

1.0.2 · active · verified Sun Mar 29

python-pptx is a Python library for creating, reading, and updating PowerPoint (.pptx) files. A typical use would be generating a PowerPoint presentation from dynamic content such as a database query, analytics output, or a JSON payload. It is currently at version 1.0.2 and aims for industrial-grade reliability with a comprehensive testing regimen.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a new PowerPoint presentation, add a title slide with text, and then add a blank slide with a custom textbox.

from pptx import Presentation
from pptx.util import Inches

# Create a new presentation
prs = Presentation()

# Add a title slide (layout index 0)
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)

# Set title and subtitle
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"

# Add a blank slide (layout index 6) and add a textbox
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
left = top = width = height = Inches(1.0)
textbox = slide.shapes.add_textbox(left, top, width, height)
textbox.text = "This is a custom textbox."

# Save the presentation
prs.save('test.pptx')
print("Presentation 'test.pptx' created successfully.")

view raw JSON →