Skip to main content

Python library for adding basic geometric shapes directly to PowerPoint (.pptx) slides by editing the XML structure.

Project description

pptx-shapes

PyPI version License: MIT Documentation Status CI tests

Python library for adding basic geometric shapes directly to PowerPoint (.pptx) slides by editing the XML structure.

Example

Features

  • Add basic shapes (ellipse, line, polygon, etc.) to existing slides
  • Control position, size, fill, stroke, and other styles
  • Simple, expressive API with smart defaults
  • Supports minimalistic charts like donut diagrams
  • Work directly with slides XML structure
  • Save result as .pptx

Installation

pip install pptx-shapes

Quick Start

from pptx_shapes import Presentation
from pptx_shapes.shapes import Ellipse, Rectangle, TextBox
from pptx_shapes.style import FillStyle, FontFormat, FontStyle, StrokeStyle

with Presentation(presentation_path="empty.pptx") as presentation:
    presentation.add(shape=TextBox(
        x=23, y=4, width=12, height=2, angle=45,
        text="Hello from pptx-shapes!",
        style=FontStyle(size=32),
        formatting=FontFormat(bold=True)
    ))

    presentation.add(shape=Ellipse(
        x=20, y=2, width=4, height=4,
        fill=FillStyle(color="#7699d4")
    ))

    presentation.add(shape=Rectangle(
        x=18, y=8, width=4, height=8.5, radius=0.25, angle=30,
        fill=FillStyle(color="#dd7373"),
        stroke=StrokeStyle(color="magenta", thickness=3)
    ))

    presentation.save("result.pptx")

How it works

This library modifies .pptx files by directly editing the underlying XML structure.

A .pptx presentation is essentially a ZIP archive containing XML files that describe slides, layouts, and content. This library works by:

  • Unzipping the .pptx file.
  • Locating and parsing the target slide file (e.g., ppt/slides/slide1.xml).
  • Inserting new shape elements into the slide's XML tree, using tags like <p:sp>, <p:cxnSp>, and <a:prstGeom>.
  • Saving the modified XML.
  • Repacking all files into a .pptx archive.

This low-level approach is ideal for automated slide generation, data visualizations, and geometric illustrations – especially when you need to create many shapes or apply programmatic styles.

Supported Shapes

Currently, pptx-shapes supports the following geometric shapes:

Shape Class Description
Line Line Straight line between two points
Arrow Arrow Straight arrow between two points
Arc Arc Curved segment defined by the bounding box and start/end angles
Arch Arch Ring-shaped arc defined by the bounding box, thickness and start/end angles
Ellipse Ellipse Ellipse defined by top-left corner, size, and rotation angle
Rectangle Rectangle Rectangle defined by top-left corner, size, corner radius and rotation angle
Pie Pie Filled sector of a circle, defined by the bounding box and start/end angles
Polygon Polygon Arbitrary polygon defined by a list of points and rotation angle
TextBox TextBox Text container with position, size, rotation, and font style
Group Group A group of multiple shapes

Documentation

Full documentation and examples are available at pptx-shapes.readthedocs.io

Examples

The following examples illustrate how to generate PowerPoint slides with various geometric shapes using python-shapes. All examples include screenshots, downloadable .pptx files, and links to the corresponding source code.

Example 1. Basic shapes

A simple demonstration of how to draw basic geometric elements – lines, ellipses, rectangles, polygons, arrows and text – on a blank slide (examples/basic.py).

Basic slide

Download .pptx: examples/basic.pptx

Example 2. Scatter plots

This example shows how to render a scatter plot using ellipses as data points, demonstrating precise positioning and styling (examples/scatter.py).

Slide example

Download .pptx: examples/scatter.pptx

Example 3. Histograms

Bar-style visualizations built using rectangles – this example illustrates how to construct a histogram layout with custom colors (examples/histogram.py).

Slide example

Download .pptx: examples/histogram.pptx

Example 4. Polygons split

A more advanced use case – splitting polygonal shapes by lines. Useful for illustrating partitions or segmentations (examples/polygons.py).

Slide example

Download .pptx: examples/polygons.pptx

Example 5. Font families and text styles

This example demonstrates how to use different font families and styles in TextBox shapes. It shows how to customize font size, alignment, color, and the font family. (examples/text_boxes.py).

Slide example

Download .pptx: examples/text_boxes.pptx

Example 6. Donut charts example

This example demonstrates how to use DonutChart from charts module (examples/charts/donut_chart.py).

Slide example

Download .pptx: examples/charts/donut_chart.pptx

Changelog

See CHANGELOG.md for version history.

License

Licensed under the MIT License. Feel free to use it in your projects.

Contributing

Pull requests, issues, and feature ideas are very welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pptx_shapes-0.2.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pptx_shapes-0.2.1-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file pptx_shapes-0.2.1.tar.gz.

File metadata

  • Download URL: pptx_shapes-0.2.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for pptx_shapes-0.2.1.tar.gz
Algorithm Hash digest
SHA256 aa3f3becfd4c80031d42040e377e0f13e7beab9f932c0aee3910c0fae9f7f4d8
MD5 bcf56319dbc298aaaeb04001798ea9bf
BLAKE2b-256 5086daf7c94e40ff1b7be56e816e8fb8a969191fe7d863b5b69bc18125aa2b96

See more details on using hashes here.

File details

Details for the file pptx_shapes-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pptx_shapes-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for pptx_shapes-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef70e431f1a83870c0dfbe6757923ece591f6600e08ca1978d58cb199ca5d4d3
MD5 192abdf325cc4701eb536fd994c20e22
BLAKE2b-256 eaff76fc883bd2f9058848ba6fdfe38682d0723b8c379fa7a1bbeb71d6e9a55f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page