You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ValueError when loading .dotx Word template – lack of native template support #1532
Attempting to instantiate a Word template (.dotx) using python-docx.Document() fails with a ValueError. The file opens normally in Microsoft Word and conforms to the standard OOXML template structure.
Steps to Reproduce
from docx import Document
doc = Document(".dotx")
Actual Behavior
ValueError: file '.dotx' is not a Word file,
content type is 'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml'
Expected Behavior
The library should be able to load .dotx templates just like .docx documents, allowing developers to:
Read and apply existing style definitions
Retain header/footer content, watermarks, and embedded assets
Save new .docx files that preserve template formatting
Environment
python-docx version: (run pip show python-docx to confirm)
Python version: 3.11+
Platform: Linux/Windows
Use Case
Corporate document generation workflows (e.g., Alignment Guard Labs) depend on .dotx templates for visual standards and branding. The current limitation forces manual template application in Word post-generation.
Proposed Enhancement
Add native .dotx support or a helper API such as Document.from_template(path) to copy all style and part relationships into a new .docx.
Hi! I've reproduced the issue. The error occurs because python-docx doesn't recognize the template content type. I'd like to work on adding .dotx template support. Let me investigate and submit a PR.
Ran into this myself. As a workaround until the PR lands: copy the .dotx to a temp .docx and patch [Content_Types].xml inside the zip to swap wordprocessingml.template.main+xml → wordprocessingml.document.main+xml. That's the only difference. Styles, headers, and numbering all carry over fine.
But it would be nice if python-docx got native support.
What's the status on #1537? And what's needed to move it forward?
.dotx and .dotm open fine as far as the OPC layer is concerned — what trips this is the main part content type, which differs from .docx, and then Document.save() writing the document content type back over it.
That's handled in my fork, python-docx-ng: templates open directly, and save(as_template=...) controls which content type gets written, so a .dotx can be saved out as a document or stay a template (toxicphreAK#83, toxicphreAK/python-docx-ng@6844527). Same import name (docx) if it's useful to you in the meantime, though the two distributions can't be installed side by side.
Activity
coderamaster commentedon Jan 21, 2026
Hi! I've reproduced the issue. The error occurs because python-docx doesn't recognize the template content type. I'd like to work on adding .dotx template support. Let me investigate and submit a PR.
Feature: Add support for .dotx Word templates (python-openxml#1532)
EwoutH commentedon Apr 9, 2026
Ran into this myself. As a workaround until the PR lands: copy the
.dotxto a temp.docxand patch[Content_Types].xmlinside the zip to swapwordprocessingml.template.main+xml→wordprocessingml.document.main+xml. That's the only difference. Styles, headers, and numbering all carry over fine.But it would be nice if python-docx got native support.
What's the status on #1537? And what's needed to move it forward?
toxicphreAK commentedon Aug 6, 2026
.dotxand.dotmopen fine as far as the OPC layer is concerned — what trips this is the main part content type, which differs from.docx, and thenDocument.save()writing the document content type back over it.That's handled in my fork, python-docx-ng: templates open directly, and
save(as_template=...)controls which content type gets written, so a.dotxcan be saved out as a document or stay a template (toxicphreAK#83, toxicphreAK/python-docx-ng@6844527). Same import name (docx) if it's useful to you in the meantime, though the two distributions can't be installed side by side.