# docxtpl

> Use a docx as a jinja2 template

Source: https://talira.ai/catalog/docxtpl-yhjaa0ty
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library, Command-line tool
- Categories: [documents / generation / word templates](https://talira.ai/categories/documents/generation/word-templates), [languages / python](https://talira.ai/categories/languages/python)
- Licence: LGPL-2.1-only[^2][^3]
- Pricing: Free and open source[^2]
- Pricing notes: LGPL-2.1 and free.
- Free tier: yes[^2]
- Self-hostable: yes[^1]
- Creator: Eric Lapouyade

docxtpl ([python-docx](https://talira.ai/catalog/python-docx-tj4sn5d1.md)-template) is a Python library that renders a Word document you design in Word as a Jinja2 template, using python-docx to read and write it. Besides `{{ }}` and `{% %}` tags it has paragraph, table row, table column and run forms (`{%p %}`, `{%tr %}`, `{%tc %}`, `{%r %}`) so loops and conditions can repeat or remove whole rows and paragraphs, plus RichText, inline images, subdocuments, merged cells and replacing pictures or embedded files in headers and footers. It's LGPL-2.1 and can also render from the command line (`python -m docxtpl`).

## Links

- GitHub: https://github.com/elapouya/python-docx-template
- Docs: https://docxtpl.readthedocs.io/en/latest/

## Problems it solves

- write Word templates with Jinja2 syntax and fill them from a Python dict
- repeat a table row in a .docx for each item in a Python list
- add a table column per month in a generated Word report from Python
- insert a chart PNG at a fixed size into a Word document generated by a Django app
- swap the logo picture in a Word template's header for each client
- merge another .docx into a generated document as a subdocument
- find which variables a Word template still needs before rendering it
- colour table cells and merge them dynamically in a Word report from Python

## Features

- Jinja2 tags, filters and variables inside a Word document
- {%p %}, {%tr %}, {%tc %} and {%r %} tags for paragraphs, table rows, table columns and runs
- RichText and RichTextParagraph for styled text and hyperlinks
- InlineImage (JPEG, PNG) with sizes in mm, inches or points
- subdocuments, including merging existing .docx files
- replace pictures, media and embedded objects, including in headers and footers
- table helpers: colspan, horizontal and vertical merge, cell background
- get_undeclared_template_variables()
- custom Jinja2 environments and filters
- command line: python -m docxtpl renders a template from JSON

## Limitations

- Doesn't let a Jinja2 tag span several paragraphs, table rows or runs: loops and conditions over them use the {%p %}, {%tr %}, {%tc %} and {%r %} forms[^1]

## Capabilities

- Has a command line tool: plan not known

## Trust

Overall: 0.28 out of 1.
Signals: backing 0.20, extensibility 0.20.

- created by Eric Lapouyade

Warnings:

- GitHub activity not fetched yet

## Related

- Based on [python-docx](https://talira.ai/catalog/python-docx-tj4sn5d1.md)

## Alternatives

- [Sablon](https://talira.ai/catalog/sablon-5bjabghv.md): Ruby document template processor based on docx templates and Mail Merge fields
- [docxtemplater](https://talira.ai/catalog/docxtemplater-gjcbyhm2.md): Powerful Word, PowerPoint and Excel generation
- [docx-templates](https://talira.ai/catalog/docx-templates-w28fxj7t.md): Template-based docx report creation for both Node and the browser
- [Carbone](https://talira.ai/catalog/carbone-hz5gt655.md): Generates PDF, DOCX and other documents from JSON data and Office templates
- [docx4j](https://talira.ai/catalog/docx4j-mcywg4m2.md): JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files
- [Docmosis](https://talira.ai/catalog/docmosis-xet3917k.md): API-first, template-based document generation

## Sources

[^1]: https://docxtpl.readthedocs.io/en/latest/ (checked 20 Nov 2026)
[^2]: https://github.com/elapouya/python-docx-template/blob/master/LICENSE.txt (checked 20 Nov 2026)
[^3]: https://pypi.org/project/docxtpl/ (checked 20 Nov 2026)
