Online python-pptx Compiler

Turn Python code into PowerPoint (.pptx) slides in your browser, with bullet points, tables, pictures and charts.

Python
from pptx import Presentation

prs = Presentation()
bullet_slide_layout = prs.slide_layouts[1]

slide = prs.slides.add_slide(bullet_slide_layout)
shapes = slide.shapes

title_shape = shapes.title
body_shape = shapes.placeholders[1]

title_shape.text = 'Adding a Bullet Slide'

tf = body_shape.text_frame
tf.text = 'Find the bullet slide layout'

p = tf.add_paragraph()
p.text = 'Use _TextFrame.text for first bullet'
p.level = 1

p = tf.add_paragraph()
p.text = 'Use _TextFrame.add_paragraph() for subsequent bullets'
p.level = 2

prs.save('test.pptx')
print(f"Saved test.pptx with {len(prs.slides)} slide and {len(tf.paragraphs)} bullets")
Saved test.pptx with 1 slide and 3 bullets

python-pptx builds and edits PowerPoint files from Python code. It can add slides, text, tables, pictures and charts, and it never needs PowerPoint itself. That makes it the usual tool for generating the same deck every week from fresh data. This page is an online python-pptx compiler: the code runs in your browser, so you can try it without installing anything. Run the example first, then paste any snippet below into a new cell to try it.

What the example does

Presentation() starts a new deck from python-pptx's built-in template. prs.slide_layouts[1] is that template's "Title and Content" layout, which has two placeholders: a title and a body. The code writes the slide title, puts the first bullet in the body's text frame, and adds two more paragraphs. Setting p.level indents a paragraph one or two levels, which is how PowerPoint shows sub-bullets. prs.save("test.pptx") writes the file.

Add a chart made with matplotlib

Any image can go on a slide, including a chart you just drew:

import matplotlib.pyplot as plt
from pptx import Presentation
from pptx.util import Inches

plt.plot([1, 3, 2, 4], marker="o")
plt.title("Weekly signups")
plt.savefig("chart.png", dpi=150)

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])  # blank layout
slide.shapes.add_picture("chart.png", Inches(1), Inches(1), width=Inches(8))
prs.save("picture.pptx")

Add a table

from pptx import Presentation
from pptx.util import Inches

rows = [("Quarter", "Sales"), ("Q1", "120"), ("Q2", "135"), ("Q3", "150")]

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])  # title only
slide.shapes.title.text = "Quarterly sales"
shape = slide.shapes.add_table(len(rows), 2, Inches(1), Inches(1.5), Inches(8), Inches(2))
for r, row in enumerate(rows):
    for c, value in enumerate(row):
        shape.table.cell(r, c).text = value
prs.save("table.pptx")

Add a native PowerPoint chart

A picture is fixed. A native chart stays editable in PowerPoint, and whoever opens the deck can change its data:

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

data = CategoryChartData()
data.categories = ["Q1", "Q2", "Q3"]
data.add_series("Sales", (120, 135, 150))

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
slide.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED, Inches(1), Inches(1), Inches(8), Inches(5), data
)
prs.save("chart.pptx")

Read or edit an existing deck

Presentation() also opens a file. This prints the text on every slide of the deck the example saved:

from pptx import Presentation

prs = Presentation("test.pptx")
for number, slide in enumerate(prs.slides, start=1):
    for shape in slide.shapes:
        if shape.has_text_frame and shape.text_frame.text:
            print(number, shape.text_frame.text)

To work on your own deck, click Mount folder in the sidebar's Data tab (Chrome or Edge on a computer), choose the folder it is in, and open it by name. Add files takes only CSV, Excel, SQLite and text files. Change any shape.text_frame.text and call prs.save() to write the edited copy.

Getting the file

Files your code saves, like test.pptx, appear in the sidebar's Data tab. Running code and inspecting the result is free. Downloading the files requires a Premium plan.

Good to know

  • python-pptx writes the file but cannot render it. There is no built-in way to turn a slide into an image or a PDF.
  • To match your company's look, start from your own template: Presentation("template.pptx") gives you its layouts and theme.
  • Layout numbers belong to the template. slide_layouts[1] is "Title and Content" in the default template, but it can be anything in yours. Check layout.name to be sure.