You can, and it works fine for simple shapes, but it is complicated by the fact that a shape can have relationships ("links" roughly) to other objects in the presentation and leaving those "dangling" can cause problems.
The basic idea is to delete the shape element using lxml
calls, so something like this:
sp = shape._sp # --- get reference to XML element for shape ---
sp.getparent().remove(sp) # --- remove that shape element from its tree ---
This is the documentation for lxml.etree._Element
, which each XML element in python-pptx
subclasses (and thereby has all these methods).
https://lxml.de/api/lxml.etree._Element-class.html
You'll know something went wrong if you get a "repair" error when trying to load the saved .pptx file. Simple shapes like rectangles and lines should be fine. Pictures, charts, and possibly shapes with hyperlinks may be problematic, but it's easy to try and you can see if it works in your case.