pythonapigetting-started

Overview

Python is one of the most popular languages for data analysis and reporting. The pptx.dev API integrates naturally with Python scripts and applications to turn your data into polished PowerPoint files.

Prerequisites

  • Python 3.8+
  • requests library (pip install requests)
  • A pptx.dev API key (get one free)

Basic Example

import requests
import os

API_KEY = os.environ["PPTX_API_KEY"]
API_URL = "https://api.pptx.dev/v1/presentations"

response = requests.post(
    API_URL,
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    },
    json={
        "title": "Python-Generated Report",
        "theme": "minimal",
        "slides": [
            {
                "layout": "title-center",
                "content": {
                    "heading": "Monthly Report",
                    "subheading": "Generated with Python",
                },
            },
            {
                "layout": "number-3x-title-center",
                "content": {
                    "heading": "Key Metrics",
                    "items": [
                        {"value": "$2.4M", "label": "Revenue"},
                        {"value": "1,200", "label": "New Users"},
                        {"value": "96%", "label": "Uptime"},
                    ],
                },
            },
        ],
    },
)

result = response.json()
print(f"Download: {result['downloadUrl']}")

Data-Driven Slides from Pandas

Generate chart slides from a Pandas DataFrame:

import pandas as pd

# Your data
df = pd.DataFrame({
    "month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
    "revenue": [120, 135, 128, 155, 170, 195],
    "users": [4200, 4800, 5100, 5600, 6200, 7000],
})

slides = [
    {
        "layout": "title-center",
        "content": {"heading": "H1 Performance", "subheading": "Data-driven report"},
    },
    {
        "layout": "chart-1x-title-center",
        "content": {
            "heading": "Revenue Trend",
            "chart": {
                "type": "LINE_WITH_MARKERS",
                "categories": df["month"].tolist(),
                "series": [
                    {"name": "Revenue ($K)", "values": df["revenue"].tolist()},
                ],
            },
        },
    },
    {
        "layout": "chart-1x-title-center",
        "content": {
            "heading": "User Growth",
            "chart": {
                "type": "COLUMN",
                "categories": df["month"].tolist(),
                "series": [
                    {"name": "Active Users", "values": df["users"].tolist()},
                ],
            },
        },
    },
]

response = requests.post(
    API_URL,
    headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
    json={"title": "H1 Performance", "theme": "minimal", "slides": slides},
)

Downloading the File

download_url = response.json()["downloadUrl"]
file_response = requests.get(download_url)

with open("report.pptx", "wb") as f:
    f.write(file_response.content)

print("Saved report.pptx")

Scheduled Report Generation

Combine with a scheduler to generate weekly reports:

import schedule
import time

def generate_weekly_report():
    data = fetch_weekly_data()  # your data source
    slides = build_slides(data)  # your slide builder
    result = call_pptx_api(slides)
    send_email(result["downloadUrl"])  # your email sender

schedule.every().monday.at("08:00").do(generate_weekly_report)

while True:
    schedule.run_pending()
    time.sleep(60)

Error Handling

response = requests.post(API_URL, headers=headers, json=payload)

if response.status_code == 200:
    download_url = response.json()["downloadUrl"]
elif response.status_code == 401:
    print("Invalid API key")
elif response.status_code == 422:
    print(f"Validation error: {response.json()}")
else:
    print(f"Error {response.status_code}: {response.text}")

Next Steps

You came for the design. Leave with the deck.

STORYD turns anything in this catalog into a finished, story-driven presentation. Free to start, no card.

See it in a deck →

5 free presentations. Exports to PPTX.