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
It would be useful to support Word's document protection features, such as Restrict Editing → No Changes (Read Only).
Currently, enabling document protection requires manually modifying the underlying Open XML contained within the DOCX file. This involves extracting the document package, updating word/settings.xml to add a w:documentProtection element, and then rebuilding the DOCX archive.
While this approach works, it requires low-level knowledge of the DOCX format and direct XML manipulation. A high-level API would make it significantly easier to create documents that can be viewed and printed but are protected against accidental modification.
Possible API examples:
document.protection.read_only = True
or
document.protection.restrict_editing()
This would provide a more convenient and discoverable way to configure document protection without requiring users to work directly with Open XML internals.
For a new document created with python-docx's default template, this low-level workaround sets the read-only OOXML flag without manually extracting/repacking the DOCX archive:
I tested this with python-docx 1.2.0: the element and both attributes survive save/reopen, and calling the helper twice does not add a duplicate. This uses private XML internals and the default template's settings order; a public API would still be preferable. I verified the package round-trip, but not the editing UI behavior in Word/LibreOffice. Microsoft's Open XML reference says document protection is intended to prevent unintentional changes, not to encrypt or secure the file: https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.documentprotection?view=openxml-3.0.1
Activity
bactiar291 commentedon Dec 4, 2026
For a new document created with python-docx's default template, this low-level workaround sets the read-only OOXML flag without manually extracting/repacking the DOCX archive:
I tested this with python-docx 1.2.0: the element and both attributes survive save/reopen, and calling the helper twice does not add a duplicate. This uses private XML internals and the default template's settings order; a public API would still be preferable. I verified the package round-trip, but not the editing UI behavior in Word/LibreOffice. Microsoft's Open XML reference says document protection is intended to prevent unintentional changes, not to encrypt or secure the file: https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.documentprotection?view=openxml-3.0.1