This tutorial demonstrates the core DocxFactory pipeline using Python:
- Compile a DOCX template into
.dfw - Merge XML data
- Save a final DOCX
The provided executable sample is in examples/python/hello_world.
The example uses input_test_template.docx from the repository root. That template contains these fields:
{first_name}{last_name}
Use this structure:
<Header>
<first_name>John</first_name>
<last_name>Smith</last_name>
</Header>From repository root:
python3 examples/python/hello_world/run_hello_world.pyDefault output:
examples/python/hello_world/out/hello_world.docx
WordProcessingCompiler.get_instance()compiles the DOCX template once into.dfw.WordProcessingMerger.get_instance()loads.dfw, merges XML, and saves output.merger.close()releases resources.
- Compile templates during deployment or startup, not on every request.
- Keep template files versioned and immutable.
- Validate incoming XML against expected schema/shape.
- Always call
close()infinallyblocks in long-running services. - Use absolute paths in server processes.
- Generate outputs in per-request temp directories to avoid collisions.
- Create a DOCX with your own placeholders (for example
{customer_name}). - Change template path in the example script.
- Update payload XML to include matching element names.
- Re-run script and inspect generated DOCX.