How to Get Started with Aspose.Slides FOSS for Python

How to Get Started with Aspose.Slides FOSS for Python

aspose-slides-foss for Python is a free, MIT-licensed library for creating and editing PowerPoint .pptx files — no Microsoft Office required, pure Python from PyPI.

Step-by-Step Guide

Step 1: Install the Package

Install from PyPI with pip:

pip install aspose-slides-foss>=26.3.2

Verify the install loaded correctly:

from aspose.slides_foss import Presentation
print("aspose-slides-foss is ready.")

Step 2: Import Required Classes

Import the modules you need for loading presentations and saving:

from aspose.slides_foss import Presentation, SaveFormat, ShapeType, FillType

Step 3: Create a Presentation

Construct a Presentation with no arguments to start with one blank slide:

from aspose.slides_foss import Presentation, SaveFormat

prs = Presentation()
slide = prs.slides[0]
print(f"Slides: {len(prs.slides)}")
prs.save("new_presentation.pptx", SaveFormat.PPTX)

Step 4: Add a Shape with Text

Use slide.shapes.add_auto_shape() to insert a rectangle, then call add_text_frame() to add text content:

from aspose.slides_foss import Presentation, SaveFormat, ShapeType

prs = Presentation()
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 400, 150)
tf = shape.add_text_frame("Hello from Aspose.Slides FOSS!")
tf.paragraphs[0].portions[0].portion_format.font_height = 24
prs.save("with_shape.pptx", SaveFormat.PPTX)

Step 5: Apply a Fill and Save

Set a solid fill color on the shape before saving:

from aspose.slides_foss import (
    Presentation, SaveFormat, ShapeType, FillType, Color
)

prs = Presentation()
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 100, 100, 400, 200)
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.color = Color.from_argb(255, 70, 130, 180)
shape.add_text_frame("Styled shape")
prs.save("styled.pptx", SaveFormat.PPTX)

Common Issues and Fixes

ModuleNotFoundError: No module named 'aspose' The package is not installed in the active Python environment. Run pip install aspose-slides-foss in the same virtual environment you are using to run your script. Confirm with pip show aspose-slides-foss.

FileNotFoundError when calling Presentation("path") The path you passed does not exist or uses the wrong separator. Use pathlib.Path to construct paths portably:

from pathlib import Path
from aspose.slides_foss import Presentation

prs = Presentation(str(Path("folder") / "existing.pptx"))

SaveFormat import error Import SaveFormat directly from the aspose.slides_foss package: from aspose.slides_foss import Presentation, SaveFormat

Shape added but not visible in output Ensure coordinates and dimensions are within the slide boundaries. Default slide dimensions are 9144000 EMUs × 6858000 EMUs (approximately 12 × 9 inches). Use reasonable values in EMU or use the x, y, width, height parameters in points (1 pt ≈ 12700 EMU).

Frequently Asked Questions

Does aspose-slides-foss require Microsoft Office?

No. The library creates and reads .pptx files natively in pure Python with no dependency on Microsoft Office, COM automation, or Windows APIs.

Which Python versions are supported?

Python 3.10 or later. The package runs on Windows, macOS, Linux, Docker containers, and serverless functions.

Is the library free for commercial use?

Yes. It is released under the MIT License. You may use, modify, and redistribute it for any purpose, including commercial applications.

Can I load an existing PPTX file?

Yes. Pass the file path to Presentation:

from aspose.slides_foss import Presentation, SaveFormat

prs = Presentation("existing.pptx")
print(f"Loaded {len(prs.slides)} slides")
prs.save("copy.pptx", SaveFormat.PPTX)

Can I add multiple slides?

Yes. Use prs.slides.add_empty_slide(layout) after obtaining a layout from prs.masters[0].layout_slides[0].

See Also