Skip to main content

pptx-templatex

A PowerPoint template engine for Python that provides slide copying and placeholder replacement functionality.

日本語README

Features

  • Copy slides from a source PowerPoint file (.pptx)
  • Replace placeholders enclosed in {{ }}
  • Support for nested object access (e.g., {{ user.name }}, {{ company.department.name }})
  • Support for array element access (e.g., {{ items[0].name }}, {{ users.[0].email }})
  • Batch processing with JSON configuration files
  • Table support: placeholder replacement in cells and variable-length row expansion (replace_table_rows)
  • Image embedding: {{ img:key }} marker shapes replaced by images with contain/cover fitting (replace_images); SVG sources are embedded natively as vectors with a PNG fallback

Installation

pip install -e .

For development with testing dependencies:

pip install -e ".[dev]"

Quick Start

  1. Create a PowerPoint template file with placeholders:

    • Open PowerPoint and create a presentation
    • Add text boxes with placeholders like {{ name }}, {{ user.email }}, {{ items[0].title }}
    • Save as template.pptx
  2. Create a JSON configuration file (config.json):

{
  "slides": [
    {
      "src_page": 1,
      "replace_texts": {
        "name": "John Doe",
        "user": {
          "email": "john@example.com"
        },
        "items": [
          {"title": "First Item"}
        ]
      }
    }
  ]
}
  1. Run the command:
pptx-templatex template.pptx config.json output.pptx

Usage

Command Line Interface

After installation, you can use the pptx-templatex command:

# Basic usage
pptx-templatex template.pptx config.json output.pptx

# View help
pptx-templatex --help

# View version
pptx-templatex --version

Python API

from pptx_templatex import TemplateEngine

# Load template file
engine = TemplateEngine("template.pptx")

# Define configuration
config = {
    "slides": [
        {
            "src_page": 1,
            "replace_texts": {
                "name": "John Doe",
                "title": "Software Engineer"
            }
        }
    ]
}

# Process and output
engine.process(config, "output.pptx")

Nested Object Access

config = {
    "slides": [
        {
            "src_page": 1,
            "replace_texts": {
                "user": {
                    "name": "John Doe",
                    "email": "john@example.com"
                }
            }
        }
    ]
}

In the template:

Name: {{ user.name }}
Email: {{ user.email }}

Array Element Access

config = {
    "slides": [
        {
            "src_page": 1,
            "replace_texts": {
                "items": [
                    {"name": "Product A", "price": "1000"},
                    {"name": "Product B", "price": "2000"}
                ]
            }
        }
    ]
}

In the template:

First item: {{ items[0].name }} - ${{ items[0].price }}
Second item: {{ items[1].name }} - ${{ items[1].price }}

Creating Multiple Slides

config = {
    "slides": [
        {"src_page": 1, "replace_texts": {"title": "Introduction"}},
        {"src_page": 2, "replace_texts": {"content": "Main Content"}},
        {"src_page": 1, "replace_texts": {"title": "Conclusion"}},
    ]
}

Using JSON Configuration File

Create a config.json file:

{
  "slides": [
    {
      "src_page": 1,
      "replace_texts": {
        "name": "John Doe",
        "items": [{"key": "value"}]
      }
    }
  ]
}

Use with CLI:

pptx-templatex template.pptx config.json output.pptx

Or use with Python API:

engine = TemplateEngine("template.pptx")
engine.process("config.json", "output.pptx")

Real-World Example

Scenario: Generate personalized presentation for multiple users

  1. Create template.pptx with:

    • Slide 1: Title slide with {{ name }} and {{ title }}
    • Slide 2: Content slide with {{ company.name }} and {{ company.address }}
    • Slide 3: List slide with {{ items[0].description }}
  2. Create config.json:

{
  "slides": [
    {
      "src_page": 1,
      "replace_texts": {
        "name": "Alice Smith",
        "title": "Senior Developer"
      }
    },
    {
      "src_page": 2,
      "replace_texts": {
        "company": {
          "name": "Tech Corp",
          "address": "123 Main St"
        }
      }
    },
    {
      "src_page": 3,
      "replace_texts": {
        "items": [
          {"description": "Improved performance by 50%"},
          {"description": "Reduced bugs by 30%"}
        ]
      }
    }
  ]
}
  1. Generate:
pptx-templatex template.pptx config.json alice_presentation.pptx

This creates a 3-slide presentation with all placeholders replaced.

Configuration Format

Configuration Object Structure

{
  "slides": [
    {
      "src_page": 1,
      "replace_texts": {
        "key": "value"
      }
    }
  ]
}
  • slides (required): Array of slide configurations
    • src_page (required): Source slide number to copy (1-based index)
    • replace_texts (optional): Mapping of text to replace
    • replace_table_rows (optional): Mapping of row-set key to a list of row dicts for variable-length table expansion (see below)
    • replace_images (optional): Mapping of {{ img:key }} marker key to an image spec (see below)

Tables

Placeholders inside native table cells are replaced the same way as text boxes (via replace_texts, rich text supported).

For variable-length rows, put a single template row in the table whose cells contain {{ <key>.<field> }} placeholders, and pass the row data via replace_table_rows:

{
  "slides": [
    {
      "src_page": 1,
      "replace_table_rows": {
        "rows": [
          {"c1": "Typhoon approach", "c2": "Moved schedule up", "c3": "Completed"},
          {"c1": "Speaker absent", "c2": "Switched to video", "c3": "Completed"}
        ]
      }
    }
  ]
}

The template row (cells containing {{ rows.c1 }}, {{ rows.c2 }}, ...) is duplicated once per item — inheriting the row's borders, fill and fonts — and then removed. An empty list removes the template row without inserting anything. Rows whose key is not present in replace_table_rows are left untouched.

Images

Put a text shape containing {{ img:key }} in the template (the marker). The image is placed at the marker shape's position/size and the marker is removed:

{
  "slides": [
    {
      "src_page": 1,
      "replace_images": {
        "photo1": {"path": "photos/cover.png", "fit": "cover"},
        "photo2": {"path": "photos/page.png", "fit": "contain"}
      }
    }
  ]
}
  • Image source: path (file path) or data (bytes, programmatic use only)
  • fit: "contain" (default) letterboxes inside the marker bounds without cropping; "cover" fills the bounds with a centered crop
  • Markers whose key is not present in replace_images are removed (no marker text leaks into the output). Keys are resolved per slide, so copying the same template page multiple times with different images just works

SVG images

SVG sources (a path ending in .svg or data containing an SVG document) are embedded natively as vectors using the asvg:svgBlip extension, together with a high-resolution PNG fallback rasterized at 3x the marker bounds. PowerPoint 2019 / Microsoft 365 render the crisp vector; older viewers (and converters such as Keynote or Google Slides) fall back to the PNG.

SVG support requires the optional resvg-py dependency:

pip install 'pptx-templatex[svg]'

Placeholder Syntax

  • Simple replacement: {{ key }}
  • Nested keys: {{ user.name }}, {{ company.department.name }}
  • Array access: {{ items[0] }}, {{ users[0].name }}
  • Complex paths: {{ company.departments[0].teams[1].name }}

Testing

pytest

With coverage report:

pytest --cov=pptx_templatex --cov-report=html

Project Structure

pptx-templatex/
├── pptx_templatex/
│   ├── __init__.py
│   ├── template_engine.py       # Main template engine
│   ├── placeholder_replacer.py  # Placeholder replacement logic
│   └── exceptions.py            # Custom exceptions
├── tests/
│   ├── __init__.py
│   ├── test_template_engine.py
│   └── test_placeholder_replacer.py
├── examples/
│   ├── example_usage.py
│   └── config.json
├── pyproject.toml
└── README.md

License

MIT

Author

SpringMT

Metadata

Release files for pptx-templatex 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pptx-templatex 0.4.0
File Size Uploaded Provenance Actions
pptx_templatex-0.4.0.tar.gz 34.0 kB Without provenance Details for pptx_templatex-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pptx-templatex 0.4.0
File Interpreter ABI Platform Actions
pptx_templatex-0.4.0-py3-none-any.whl Python 3 none any Details for pptx_templatex-0.4.0-py3-none-any.whl

Total release size: 52.3 kB

Release files / pptx_templatex-0.4.0.tar.gz

Download URL pptx_templatex-0.4.0.tar.gz
Size 34.0 kB
Tags Source
SHA-256 checksum
How to use checksums
94e4e1370a7a2fece9aa2fc98df8085dfb1fd2c7a65149945a2bcbdc3a69db07
BLAKE2b-256 checksum
How to use checksums
cb622412906c13d7aa940aec1a0275cbc91bd286b83cbb811210b6b0ce519f44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / pptx_templatex-0.4.0-py3-none-any.whl

Download URL pptx_templatex-0.4.0-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e017b120a7f6d29eed7ada8de1c607ff91ad0a5d81f821754ecf07845f3ff77
BLAKE2b-256 checksum
How to use checksums
b9aa7cad554afedf69e96c3a6a226218c245679dbd4036fa8eb87857290bb467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for pptx-templatex 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page