# elapouya/python-docx-template architecture

> Architecture diagram of the GitHub repository elapouya/python-docx-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elapouya/python-docx-template
- Repository: https://github.com/elapouya/python-docx-template

## Overview

docxtpl is a Python library and CLI for generating Word documents from .docx templates and context data. The main workflow validates inputs, loads a template and JSON context, renders the document, and saves the result. The library also provides rich-text, listing, inline-image, and subdocument helpers. The graph distinguishes the CLI orchestration from the template engine and helper features; several helper-to-render relationships are not shown in the excerpts, so they are not asserted.

Main entry points: [`docxtpl/template.py`](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/template.py) (Template engine), [`docxtpl/__main__.py`](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/__main__.py) (CLI workflow), [`docxtpl/subdoc.py`](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/subdoc.py) (Subdocuments), [`docxtpl/inline_image.py`](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/inline_image.py) (Inline images)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI workflow<br/>[__main__.py]"]
  node_json["JSON context"]
  node_template_file["DOCX template"]
  node_output["Generated DOCX"]
end

subgraph group_engine["Template engine"]
  node_docxtpl["Template engine<br/>[template.py]"]
end

subgraph group_content["Content helpers"]
  node_rich_text["Rich text<br/>[richtext.py]"]
  node_listing["Text listing<br/>[listing.py]"]
  node_inline_image["Inline images<br/>[inline_image.py]"]
  node_subdoc["Subdocuments<br/>[subdoc.py]"]
end

subgraph group_deps["Document dependencies"]
  node_jinja["Jinja2 renderer"]
  node_python_docx["python-docx"]
end

node_user(("Developer"))

node_user -->|"runs"| node_cli
node_user -->|"provides"| node_template_file
node_user -->|"provides"| node_json
node_cli -->|"reads"| node_json
node_cli -->|"loads, renders"| node_docxtpl
node_cli -->|"loads"| node_template_file
node_cli -->|"saves via"| node_docxtpl
node_docxtpl -->|"writes"| node_output
node_docxtpl -->|"renders with"| node_jinja
node_docxtpl -->|"uses"| node_python_docx
node_inline_image -->|"uses render part"| node_docxtpl
node_docxtpl -->|"creates"| node_subdoc
node_subdoc -->|"loads document"| node_python_docx

click node_cli "https://github.com/elapouya/python-docx-template/blob/master/docxtpl/__main__.py"
click node_docxtpl "https://github.com/elapouya/python-docx-template/blob/master/docxtpl/template.py"
click node_rich_text "https://github.com/elapouya/python-docx-template/blob/master/docxtpl/richtext.py"
click node_listing "https://github.com/elapouya/python-docx-template/blob/master/docxtpl/listing.py"
click node_inline_image "https://github.com/elapouya/python-docx-template/blob/master/docxtpl/inline_image.py"
click node_subdoc "https://github.com/elapouya/python-docx-template/blob/master/docxtpl/subdoc.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_json,node_template_file,node_output toneBlue
class node_docxtpl toneAmber
class node_rich_text,node_listing,node_inline_image,node_subdoc toneMint
class node_jinja,node_python_docx toneRose
class node_user toneIndigo
```

## Components

### Entry points

- [CLI workflow](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/__main__.py): `docxtpl/__main__.py`
- **JSON context**
- **DOCX template**
- **Generated DOCX**

### Template engine

- [Template engine](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/template.py): `docxtpl/template.py`

### Content helpers

- [Rich text](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/richtext.py): `docxtpl/richtext.py`
- [Text listing](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/listing.py): `docxtpl/listing.py`
- [Inline images](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/inline_image.py): `docxtpl/inline_image.py`
- [Subdocuments](https://github.com/elapouya/python-docx-template/blob/master/docxtpl/subdoc.py): `docxtpl/subdoc.py`

### Document dependencies

- **Jinja2 renderer**
- **python-docx**

### Other components

- **Developer**

## Connections

- Developer → CLI workflow: runs (evidence: `docxtpl/__main__.py`)
- Developer → DOCX template: provides (evidence: `README.rst`)
- Developer → JSON context: provides
- CLI workflow → JSON context: reads (evidence: `docxtpl/__main__.py`)
- CLI workflow → Template engine: loads, renders (evidence: `docxtpl/__main__.py`)
- CLI workflow → DOCX template: loads (evidence: `docxtpl/__main__.py`)
- CLI workflow → Template engine: saves via (evidence: `docxtpl/__main__.py`)
- Template engine → Generated DOCX: writes (evidence: `README.rst`)
- Template engine → Jinja2 renderer: renders with (evidence: `README.rst`)
- Template engine → python-docx: uses (evidence: `README.rst`)
- Inline images → Template engine: uses render part (evidence: `docxtpl/inline_image.py`)
- Template engine → Subdocuments: creates (evidence: `docxtpl/template.py`)
- Subdocuments → python-docx: loads document (evidence: `docxtpl/subdoc.py`)
