Skip to content

Add LLM-friendly serialization and animation support#1

Draft
Copilot wants to merge 7 commits into
masterfrom
copilot/improve-llm-support-pptx-library
Draft

Add LLM-friendly serialization and animation support#1
Copilot wants to merge 7 commits into
masterfrom
copilot/improve-llm-support-pptx-library

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 20, 2026

Two enhancements to make python-pptx more useful for LLM-driven presentation generation: structured serialization of presentation content, and programmatic animation of shapes.

Serialization (to_dict() / __repr__())

  • Added to_dict() returning JSON-serializable dicts on Presentation, Slide, BaseShape, TextFrame, _Paragraph, _Run, Font
  • Added descriptive __repr__() on the same objects (defensive against incomplete/mock state in Slide)
  • Font.to_dict() only includes explicitly-set properties to avoid inherited noise
  • 26 tests in tests/test_llm_friendly.py

Animation (Slide.add_animation())

  • src/pptx/enum/animation.pyPP_ANIMATION_TYPE enum: 14 entrance effects (APPEAR, FADE, FLY_IN×4, WIPE×4, SPLIT×2, WHEEL, DISSOLVE)
  • src/pptx/oxml/slide.pyCT_Slide.add_animation() + XML builders (_build_animation_timing_xml, _build_animation_click_par_xml) generating valid OOXML timing trees. Supports first-animation (full scaffold) and subsequent-animation (appended to existing mainSeq) paths. _ANIMATION_FILTER_MAP maps enum xml_values → OOXML filter/transition attrs.
  • src/pptx/slide.pySlide.add_animation(shape, animation_type, duration=500) public API with input validation
  • 21 tests in tests/test_animation.py

Usage

from pptx import Presentation
from pptx.enum.animation import PP_ANIMATION_TYPE
import json

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[1])
title = slide.placeholders[0]
title.text = "Hello"

slide.add_animation(title, PP_ANIMATION_TYPE.FADE, duration=1000)
slide.add_animation(slide.placeholders[1], PP_ANIMATION_TYPE.WIPE_FROM_LEFT, 800)

# Inspect entire presentation as structured data
print(json.dumps(prs.to_dict(), indent=2))

prs.save("output.pptx")

All 2747 tests pass (2700 existing + 47 new).


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Enhance PPTX library for better LLM integration Add to_dict() and __repr__() to core objects for LLM-friendly serialization Feb 20, 2026
Copilot AI requested a review from spranav1998 February 20, 2026 11:47
Copilot AI changed the title Add to_dict() and __repr__() to core objects for LLM-friendly serialization Add LLM-friendly serialization and animation support Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants