docx-templates
Template-based Word document generation using Jinja2 syntax. Create reports, contracts, and documents with loops, conditionals, tables, and mail merge capabilities.
Best use case
docx-templates is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Template-based Word document generation using Jinja2 syntax. Create reports, contracts, and documents with loops, conditionals, tables, and mail merge capabilities.
Teams using docx-templates should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/docx-templates/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How docx-templates Compares
| Feature / Agent | docx-templates | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Template-based Word document generation using Jinja2 syntax. Create reports, contracts, and documents with loops, conditionals, tables, and mail merge capabilities.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Docx Templates
## Quick Start
```bash
# Install docxtpl
pip install docxtpl
# Install with image support
pip install docxtpl Pillow
# For Excel data sources
pip install docxtpl openpyxl pandas
# Verify installation
python -c "from docxtpl import DocxTemplate; print('docxtpl ready!')"
```
## When to Use This Skill
**USE when:**
- Generating documents from templates with dynamic data
- Creating mail merge documents from data sources
- Building reports with loops and conditional sections
- Need to maintain consistent formatting across generated documents
- Generating contracts, invoices, letters from templates
- Processing batch document generation from databases or spreadsheets
- Templates need professional formatting preserved
- Non-technical users maintain template design
**DON'T USE when:**
- Building documents programmatically from scratch (use python-docx)
- Need complex document manipulation beyond template filling
- PDF output is the final format (generate docx then convert)
- Templates require complex macros or VBA
- Real-time collaborative editing needed
## Prerequisites
```bash
# Core installation
pip install docxtpl>=0.16.0
# For image handling
pip install docxtpl Pillow>=9.0.0
# For data processing
pip install docxtpl pandas>=2.0.0 openpyxl>=3.1.0
# For database connections
pip install docxtpl sqlalchemy psycopg2-binary
# All dependencies
pip install docxtpl Pillow pandas openpyxl sqlalchemy
```
### Verify Installation
```python
from docxtpl import DocxTemplate, InlineImage
from docx.shared import Mm, Inches
print("docxtpl installed successfully!")
# Quick test
# template = DocxTemplate("template.docx")
# context = {"name": "World"}
# template.render(context)
# template.save("output.docx")
```
## Resources
- **docxtpl Documentation**: https://docxtpl.readthedocs.io/
- **GitHub Repository**: https://github.com/elapouya/python-docx-template
- **Jinja2 Template Syntax**: https://jinja.palletsprojects.com/
- **python-docx (underlying library)**: https://python-docx.readthedocs.io/
## Version History
- **1.0.0** (2026-01-17): Initial release with template rendering, loops, conditionals, tables, images, mail merge
---
*This skill provides comprehensive patterns for template-based document generation with docxtpl, refined from production document automation workflows.*
## Sub-Skills
- [1. Basic Template Rendering](1-basic-template-rendering/SKILL.md)
- [2. Loops and Iterations](2-loops-and-iterations/SKILL.md)
- [3. Conditional Content](3-conditional-content/SKILL.md)
- [4. Table Generation](4-table-generation/SKILL.md)
- [5. Image Insertion](5-image-insertion/SKILL.md)
- [6. Mail Merge and Batch Generation](6-mail-merge-and-batch-generation/SKILL.md)
- [Database Integration](database-integration/SKILL.md)
- [FastAPI Service](fastapi-service/SKILL.md)
- [1. Template Design (+2)](1-template-design/SKILL.md)
- [Template Variables Not Rendering (+2)](template-variables-not-rendering/SKILL.md)Related Skills
pyproject-toml
Configure Python projects with pyproject.toml for modern packaging, tools, and dependency management
python-scientific-computing
Python for engineering analysis, numerical computing, and scientific workflows using NumPy, SciPy, SymPy
pandas-data-processing
Pandas for time series analysis, OrcaFlex results processing, and marine engineering data workflows
numpy-numerical-analysis
NumPy for matrix operations, FFT, linear algebra, and numerical computations in marine engineering
ydata-profiling
Automated data quality reports with comprehensive variable analysis, missing value detection, correlations, and HTML report generation - formerly pandas-profiling
sweetviz
Automated EDA comparison reports with target analysis, feature comparison, and HTML report generation for pandas DataFrames
great-tables
Publication-quality tables in Python with rich styling, formatting, conditional formatting, and export to HTML/images - inspired by R's gt package
bsee-sodir-extraction
Extract and process energy data from BSEE (Gulf of Mexico) and SODIR (Norway) regulatory databases
autoviz
Automatic exploratory data analysis and visualization with a single line of code - generates comprehensive charts, detects patterns, and exports to HTML/notebooks
pandasai
Conversational data analysis using natural language queries on pandas DataFrames. Use when you want to ask plain-English questions about data, generate charts, explain transformations, or build exploratory analysis interfaces — all powered by an LLM backend. Supports OpenAI, Anthropic, Google Gemini, Azure OpenAI, and local models. Handles single DataFrames (SmartDataframe) and multi-table joins (SmartDatalake).
langchain
Build production-ready LLM applications with chains, agents, memory, tools, and RAG pipelines using the LangChain framework
python-docx
Create and manipulate Microsoft Word documents programmatically. Build reports, contracts, and documentation with full control over paragraphs, tables, headers, styles, and images.