docx-mailmerge2
Performs a Mail Merge on docx (Microsoft Office Word) files
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and solves a real problem (docx templating without Office) with low install friction. It is suitable for production use in document automation workflows, particularly where server-side generation or batch processing is needed.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Merge fields in the docx template must be created using CTRL-F9 (or CMD-F9 on macOS) in Microsoft Word, not as ordinary text.
- Low friction install with a single lightweight dependency (lxml).
- Actively maintained with recent releases; last commit 2026-06-19 and latest release 2025-12-28.
License · maintenance · safety
MIT (permissive) — MIT license (permissive) allows free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
last release 2025-12-28 (229 days) · last repo commit 2026-06-19 · 80 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 133,147 downloads/mo, #11,525 on PyPI
Alternatives
Verify before relying
pip install docx-mailmerge2
from docx_mailmerge2 import MailMerge
with MailMerge('input.docx') as document:
document.merge(field1='value1', field2='value2')
document.write('output.docx')- Whether nested field updates (e.g., INCLUDEPICTURE, IF fields) work without opening the output in Microsoft Word to trigger F9 refresh.
- Performance characteristics when merging large numbers of rows or templates in a single operation.
- Compatibility with docx files created by non-Microsoft tools (LibreOffice, Google Docs).
What it is and what it does
docx-mailmerge2 is a Python library that automates the population of Microsoft Word templates by replacing merge fields with data. It reads docx files, identifies MERGEFIELD placeholders, substitutes them with values you provide, and writes the result to a new docx file—all without needing Microsoft Office installed. The library handles simple field replacement, table row templating (expanding or replacing rows based on data lists), and template duplication with page or section breaks between copies.
The package supports field formatting for numeric, text, conditional, and date values, and can work with nested fields like INCLUDEPICTURE and IF statements (though these may require manual field updates in Word afterward). It offers configuration options to control empty table removal, field preservation, automatic field updates on document open, and conditional field evaluation. The single runtime dependency is lxml, making it lightweight and portable across systems.
Use it for
- Generate personalized letters or invoices by merging customer data into Word templates without manual editing.
- Create bulk reports by duplicating a template for each data record and separating them with page breaks.
- Populate dynamic tables in docx files by expanding template rows with lists of records.
- Automate document generation in server-side applications where Microsoft Office is unavailable.
- Preserve merge fields in output documents for later re-merging or manual updates in Word.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and solves a real problem (docx templating without Office) with low install friction. It is suitable for production use in document automation workflows, particularly where server-side generation or batch processing is needed.
Install
docx-mailmerge2 on PyPI
Before you install
Low friction install with a single lightweight dependency (lxml). Actively maintained with recent releases; last commit 2026-06-19 and latest release 2025-12-28. Supports Python 3.7 through 3.13.
Merge fields in the docx template must be created using CTRL-F9 (or CMD-F9 on macOS) in Microsoft Word, not as ordinary text.
License in practice
MIT license (permissive) allows free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install docx-mailmerge2
from docx_mailmerge2 import MailMerge
with MailMerge('input.docx') as document:
document.merge(field1='value1', field2='value2')
document.write('output.docx')
Verify before relying
- Whether nested field updates (e.g., INCLUDEPICTURE, IF fields) work without opening the output in Microsoft Word to trigger F9 refresh.
- Performance characteristics when merging large numbers of rows or templates in a single operation.
- Compatibility with docx files created by non-Microsoft tools (LibreOffice, Google Docs).
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.7 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagelxml |
| Maintenance | Actively maintained 229 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 133,147 / month, #11,525 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableEnvironment :: ConsoleLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming 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.9Topic :: Text Processing |
Evidence: docx_mailmerge2-1.0.1-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 › “office open xml merge fields”
- docx-mailmerge2Performs mail merge operations on docx files by replacing merge…
- docx-mailmergePerforms mail merge operations on docx files by replacing merge…
- openpyxlopenpyxl reads and writes Excel 2010 xlsx/xlsm/xltx/xltm files…
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-mailmerge · docxtpl · docxcompose · docx · doc2docx · python-docx-ml6 · python-docx · html-for-docx · aspose-words · docx2pdf