Validate Jinja2 template syntax inside .docx files (docxtpl compatible)
Project description
docx-jinja2-validator
Validate Jinja2 template syntax inside .docx files — built for use with docxtpl.
Install
pip install docxlint
Usage
# single file
docxlint template.docx
# entire folder
docxlint ./templates/
# recursive (includes subfolders)
docxlint ./templates/ --recursive
# verbose (show all block tags)
docxlint ./templates/ --verbose
Or via Python module:
python -m docxlint template.docx
What it checks
| # | Check | Example error caught |
|---|---|---|
| 1 | Valid ZIP / DOCX structure | Corrupt file |
| 2 | XML well-formedness | word/document.xml broken |
| 3 | {{ }} balance |
Missing } in variable |
| 4 | {% %} balance |
Missing %} in block tag |
| 5 | Split tags | Word splits {{var}} across XML runs |
| 6 | Common typos | {{{, }}}, { %, % }, end for |
| 7 | Block pairing | {% for %} without {% endfor %} |
| 8 | Table row tags | {%tr for %} without {%tr endfor %} |
| 9 | Variable inventory | Lists all {{ ... }} found |
Example output
Validating: template.docx (42 KB)
────────────────────────────────────────────────────────────
1. DOCX structure
✓ Valid ZIP with 17 entries
✓ word/document.xml present
2. XML well-formedness
✓ word/document.xml
3. Jinja2 syntax
✓ word/document.xml: 6 variables, 4 block tags
4. Block tag pairing
✓ All for/if blocks properly closed
5. Table row tags {%tr %}
✓ word/document.xml: 1 table row loop(s) matched
6. Variable inventory
→ Found 6 unique variable expression(s):
{{ objects.customer_id.name }}
{{ objects.total_overdue_amount }}
...
Result
✓ PASSED
Exit codes
| Code | Meaning |
|---|---|
0 |
All files passed |
1 |
One or more files have issues |
Useful for CI/CD pipelines:
docxlint ./templates/ && echo "Templates OK" || echo "Fix templates!"
Use as a library
from docxlint import validate_one
from pathlib import Path
result = validate_one(Path("template.docx"), verbose=False)
print(result.passed) # True / False
print(result.issues) # number of failed checks
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
docxlint-0.1.0.tar.gz
(8.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docxlint-0.1.0.tar.gz.
File metadata
- Download URL: docxlint-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e76174029bdba11e7ed75f9e2730ef9ec0a4c2d67d66eb3c11e821067a2159
|
|
| MD5 |
af5f9de67d83ec3e1cab5a926ffd48f4
|
|
| BLAKE2b-256 |
56a07e3fe96d48310d3fa0e6ffffdfc19408c06c596cd8bae5bfaa298ce12b6a
|
File details
Details for the file docxlint-0.1.0-py3-none-any.whl.
File metadata
- Download URL: docxlint-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aecf01cd295589640f4b2ed73a0875ab9969014b6e2b754b61622f61a6c8d1f6
|
|
| MD5 |
b638c5902e6787c13282af830826475b
|
|
| BLAKE2b-256 |
cf49603c4d66a787f2b01dba9235c00584cec0773f876efbbd4e63cc23f50f2d
|