--- id: docxtpl version: "0.20.2" license: LGPL-2.1-only license_treatment: copyleft maintenance: active --- # docxtpl — Python docx template engine License: copyleft · Maintenance: active · Downloads: 3.4M/mo ## 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 above — verify before relying. Generates Word documents (.docx) from templates by embedding Jinja2 tags into a Word document and populating them with context variables at runtime. 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 pip install docxtpl uv add docxtpl poetry add docxtpl ## Installing docxtpl 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. 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') Requires a .docx template file with embedded Jinja2 tags; the template must be created in Microsoft Word or compatible editor before use. 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_current - Install friction: low - Maintenance: active - Downloads: 3.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags docx template engine, word document generation, jinja2 docx templating, dynamic word documents, docx mail merge, python word automation, generate docx from template, document-generation, template-engine, office-automation [View on SkillFed](https://skillfed.io/packages/docxtpl) · [View on PyPI](https://pypi.org/project/docxtpl/)