Skip to content

docxtpl-ng

PyPI Downloads

Use a .docx file as a Jinja2 template.

Design the document in Word — styles, tables, headers, page layout, the lot — write {{ customer.name }} where the data goes, and render it from Python.

from docxtpl import Template

tpl = Template("invoice.docx")
tpl.render({"customer": customer, "lines": lines, "total": total})
tpl.save("invoice-2026-0042.docx")
pip install docxtpl-ng

Alpha

The whole feature set is implemented and tested — rendered documents are validated against the ISO/IEC 29500 schemas, and compared against what docxtpl itself produces — but it has not been run against a large corpus of real templates or used in anger. The 0. major says the same: expect to find things, and expect the odd rough edge to be filed off in a way that changes behaviour.

Where to start

By feature

Part of the -ng suite

docxtpl-ng builds on python-docx-ng, which provides the document model. Anything the template cannot express, you can reach for directly: Template.document is an ordinary python-docx-ng Document, and a Fragment lets you build content with that API and drop it into the template at a tag.