docxtpl
Python docx template engine
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has low install friction, supports modern Python versions, and solves a real gap in Word document automation. The LGPL-2.1-only license is permissive for most use cases but requires attention if you plan to distribute modified versions. No known vulnerabilities. Install it if you need to generate Word documents from templates with dynamic content.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires a .docx template file with embedded Jinja2 tags; the template must be created in Microsoft Word or compatible editor before use.
- Low install friction with three stable runtime dependencies (python-docx, jinja2, lxml).
- Active maintenance with a recent release on 2025-11-13 and last commit on 2026-07-07; supports Python 3.7 through 3.13.
License · maintenance · safety
LGPL-2.1-only (copyleft) — Licensed under LGPL-2.1-only (copyleft). Any derivative work or modification must be distributed under the same license; proprietary use requires careful review of your distribution model.
last release 2025-11-13 (274 days) · last repo commit 2026-07-07 · 2,690 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 3,387,086 downloads/mo, #2,639 on PyPI
Alternatives
Verify before relying
pip install docxtpl
from docxtpl import DocxTemplate
doc = DocxTemplate('template.docx')
context = {'name': 'John'}
doc.render(context)
doc.save('output.docx')- Whether complex nested Jinja2 constructs (loops, conditionals) are fully supported within Word document structure constraints.
- Performance characteristics when rendering large documents or templates with many variables.
- Compatibility with Word features like tracked changes, comments, or form fields in templates.
What it is and what it does
docxtpl bridges the gap between python-docx (which excels at creating documents from scratch) and the need to modify or populate existing Word documents. You design your document layout in Microsoft Word—complete with formatting, images, headers, footers, and tables—then insert Jinja2 template tags directly into the document text. Save it as a .docx file, and docxtpl reads that template, processes the Jinja2 tags with your context variables, and generates a new Word document with the populated content.
The package is built on three core dependencies: python-docx handles the underlying .docx file manipulation, jinja2 provides the templating engine for tag processing, and lxml handles the XML parsing that Word documents rely on. This makes it well-suited for mail-merge workflows, report generation, and document automation where you want fine-grained control over the final document's appearance without writing complex layout code.
Use it for
- Generate personalized letters or contracts by inserting recipient data into a pre-formatted Word template.
- Create dynamic reports with tables, charts, and formatted sections populated from database queries or API responses.
- Automate invoice or receipt generation with company branding and variable line items.
- Produce batch documents (certificates, labels, forms) with consistent styling and variable content.
- Build document workflows where non-technical users design templates in Word and developers populate them programmatically.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has low install friction, supports modern Python versions, and solves a real gap in Word document automation. The LGPL-2.1-only license is permissive for most use cases but requires attention if you plan to distribute modified versions. No known vulnerabilities. Install it if you need to generate Word documents from templates with dynamic content.
Install
docxtpl on PyPI
Before you install
Low install friction with three stable runtime dependencies (python-docx, jinja2, lxml). Active maintenance with a recent release on 2025-11-13 and last commit on 2026-07-07; supports Python 3.7 through 3.13.
Requires a .docx template file with embedded Jinja2 tags; the template must be created in Microsoft Word or compatible editor before use.
License in practice
Licensed under LGPL-2.1-only (copyleft). Any derivative work or modification must be distributed under the same license; proprietary use requires careful review of your distribution model.
Quickstart
pip install docxtpl
from docxtpl import DocxTemplate
doc = DocxTemplate('template.docx')
context = {'name': 'John'}
doc.render(context)
doc.save('output.docx')
Verify before relying
- Whether complex nested Jinja2 constructs (loops, conditionals) are fully supported within Word document structure constraints.
- Performance characteristics when rendering large documents or templates with many variables.
- Compatibility with Word features like tracked changes, comments, or form fields in templates.
Package facts
| License | LGPL-2.1-only copyleft |
| Python support | Supports the current Python release >=3.7 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagespython-docxjinja2lxml |
| Maintenance | Actively maintained 274 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,387,086 / month, #2,639 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaIntended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: docxtpl-0.20.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “docx template engine”
- docxtplGenerates Word documents (.docx) from templates by embedding Jinja2…
- docx-mailmergePerforms mail merge operations on docx files by replacing merge…
- docx-mailmerge2Performs mail merge operations on docx files by replacing merge…
Give your agent the search over MCP, or paste the wish link into any chat.
More Text Processing packages
A drop-in replacement for Python's standard `re` module that adds advanced regex features like nested sets, fuzzy matching, lookaround in conditionals, and full Unicode case-folding while maintaining backward compatibility.
pyparsing provides a library for building text parsers directly in Python code using composable grammar classes, handling quoted strings, whitespace variation, and embedded comments without regex or lex/yacc.
Install it if you need to parse text or define grammars programmatically.
fonttools manipulates font files in multiple formats (TrueType, OpenType, AFM, Type 1, Mac-specific) and includes TTX, a tool to convert fonts to and from XML text format.
Install it if you need to read, write, or manipulate fonts programmatically or via the TTX command-line tool.
Docutils converts plaintext documentation in reStructuredText format into multiple output formats including HTML, XML, and LaTeX using a modular processing system.
RapidFuzz provides fast fuzzy string matching using Levenshtein Distance and related metrics, implemented mostly in C++ with Python bindings for rapid similarity scoring and approximate string matching.
Install it if you need fuzzy string matching; it's a solid replacement for FuzzyWuzzy with better licensing and performance.
tinycss2 parses CSS strings into token and block objects, and generates CSS strings from those objects, following the CSS Syntax Level 3 specification without enforcing specific properties or values.
Install it if your project requires CSS tokenization or syntax manipulation.
See also docx · htmldocx · html-for-docx · python-docx-ml6 · docx-mailmerge · docx-mailmerge2 · docx2txt · python-docx · jinja2-simple-tags · mammoth