Back to Hub
Word automation

docxtpl

Generate Word docs from a Python dict. Same idea as a mail merge, driven by Python.

requirements.txt
xlwings
pandas
docxtpl

Restart xlwings Lite after saving

Template with placeholders
Python dict matching keys
Finished doc personalised .docx
Docs docxtpl.readthedocs.io

Dict keys = placeholders

Template (.docx)
May 8, 2026
Commission Statement
Dear {{ distributor_name }},
Your commission for this period is {{ commission_amount }}.
Thank you for your continued partnership.
Best regards,
The Team
Python
# load the template
doc = DocxTemplate("template.docx")

# keys must match placeholders
doc.render({
  "distributor_name":   "Anna Schmidt",
  "commission_amount": "$1,234",
})

# save
doc.save("statement.docx")

One template, many docs

template.docx
One file with placeholders
for row in data
statement_anna.docx
statement_joao.docx
statement_yumi.docx
statement_mateus.docx