Skip to content

ValueError when loading .dotx Word template – lack of native template support #1532

Description

@furrepanther

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.

Activity

  1. coderamaster commented on Jan 21, 2026

    @coderamaster

    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.

  2. EwoutH commented on Apr 9, 2026

    @EwoutH

    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?

  3. added
    dotx/docmAlternate DOCX content types that should parse fine.
    on May 18, 2026
  4. toxicphreAK commented on Aug 6, 2026

    @toxicphreAK

    .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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotx/docmAlternate DOCX content types that should parse fine.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions