# airmang/python-hwpx architecture

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

- Interactive diagram: https://gitdiagram.com/airmang/python-hwpx
- Repository: https://github.com/airmang/python-hwpx

## Overview

python-hwpx is a pure-Python library for reading, editing, creating, and validating HWPX documents, with HWP 5.0 conversion support. The main workflow is to open or create a document, edit its content or structure, then save it; optional patch saving preserves untouched package parts. The graph also shows major documented capabilities—form filling, extraction, layout, equations, and batch tools—and the internal OXML and OPC layers. Some subsystem links are based on README capability descriptions because their source was not sampled; those links are dashed and unverified.

Main entry points: [`src/hwpx/document.py`](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/document.py) (Document API), [`src/hwpx/quality/save_pipeline.py`](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/quality/save_pipeline.py) (Safe save gate), [`src/hwpx/oxml/section.py`](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/section.py) (Sections and stories), [`src/hwpx/form_fit/engine.py`](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/form_fit/engine.py) (Form fitting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Document API"]
  node_document["Document API<br/>[document.py]"]
end

subgraph group_content["Content and Layout"]
  node_paragraph["Paragraph editing<br/>[paragraph.py]"]
  node_table["Table editing<br/>[table.py]"]
  node_section["Sections and stories<br/>[section.py]"]
  node_sectionformat["Page formatting<br/>[section_format.py]"]
  node_formfit["Form fitting<br/>[engine.py]"]
  node_fitmeasure["Text measurement<br/>[measure.py]"]
  node_equations["Equation authoring<br/>[authoring.py]"]
  node_layout["Page layout<br/>[pages.py]"]
end

subgraph group_formats["Format Handling"]
  node_oxml["OXML model<br/>[document.py]"]
  node_primitives["XML primitives"]
  node_package["OPC package<br/>[package.py]"]
  node_hwp5reader["HWP5 reader<br/>[reader.py]"]
  node_hwp5writer["HWP5 writer<br/>[writer.py]"]
end

subgraph group_safety["Validation and Safety"]
  node_validator["Package validation"]
  node_savegate["Safe save gate<br/>[save_pipeline.py]"]
  node_security["Package security<br/>[security.py]"]
  node_report["Save report<br/>[report.py]"]
end

subgraph group_tools["Document Tools"]
  node_extract["Text extraction<br/>[text_extractor.py]"]
  node_export["Document export<br/>[exporter.py]"]
  node_merge["Mail merge<br/>[mail_merge.py]"]
  node_toc["TOC authoring<br/>[toc_author.py]"]
end

node_user(("Python caller"))

node_user -->|"opens or creates"| node_document
node_document -.->|"edits document"| node_oxml
node_oxml -->|"uses primitives"| node_primitives
node_document -->|"loads and saves"| node_package
node_document -.->|"edits paragraphs"| node_paragraph
node_document -.->|"edits tables"| node_table
node_document -.->|"manages sections"| node_section
node_section -->|"configures pages"| node_sectionformat
node_document -.->|"fills form fields"| node_formfit
node_formfit -->|"measures slots"| node_fitmeasure
node_user -.->|"authors equations"| node_equations
node_user -.->|"requests layout"| node_layout
node_user -.->|"extracts text"| node_extract
node_user -.->|"exports formats"| node_export
node_user -.->|"runs mail merge"| node_merge
node_user -.->|"authors contents"| node_toc
node_user -.->|"opens HWP5"| node_hwp5reader
node_hwp5reader -.->|"converts to model"| node_document
node_document -.->|"saves HWP5"| node_hwp5writer
node_user -.->|"requests safe save"| node_savegate
node_savegate -->|"validates package"| node_validator
node_savegate -->|"checks safety"| node_security
node_savegate -->|"composes report"| node_report
node_savegate -.->|"publishes bytes"| node_package

click node_document "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/document.py"
click node_oxml "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/document.py"
click node_primitives "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/_document_primitives.py"
click node_package "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/opc/package.py"
click node_hwp5reader "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/hwp5/reader.py"
click node_hwp5writer "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/hwp5/writer.py"
click node_paragraph "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/paragraph.py"
click node_table "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/table.py"
click node_section "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/section.py"
click node_sectionformat "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/section_format.py"
click node_formfit "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/form_fit/engine.py"
click node_fitmeasure "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/form_fit/measure.py"
click node_equations "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/equation/authoring.py"
click node_layout "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/layout/pages.py"
click node_extract "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/text_extractor.py"
click node_export "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/exporter.py"
click node_merge "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/mail_merge.py"
click node_toc "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/toc_author.py"
click node_validator "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/package_validator.py"
click node_savegate "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/quality/save_pipeline.py"
click node_security "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/opc/security.py"
click node_report "https://github.com/airmang/python-hwpx/blob/main/src/hwpx/quality/report.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_document toneBlue
class node_paragraph,node_table,node_section,node_sectionformat,node_formfit,node_fitmeasure,node_equations,node_layout toneAmber
class node_oxml,node_primitives,node_package,node_hwp5reader,node_hwp5writer toneMint
class node_validator,node_savegate,node_security,node_report toneRose
class node_extract,node_export,node_merge,node_toc,node_user toneIndigo
```

## Components

### Document API

- [Document API](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/document.py): `src/hwpx/document.py`

### Content and Layout

- [Paragraph editing](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/paragraph.py): `src/hwpx/oxml/paragraph.py`
- [Table editing](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/table.py): `src/hwpx/oxml/table.py`
- [Sections and stories](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/section.py): `src/hwpx/oxml/section.py`
- [Page formatting](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/section_format.py): `src/hwpx/oxml/section_format.py`
- [Form fitting](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/form_fit/engine.py): `src/hwpx/form_fit/engine.py`
- [Text measurement](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/form_fit/measure.py): `src/hwpx/form_fit/measure.py`
- [Equation authoring](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/equation/authoring.py): `src/hwpx/equation/authoring.py`
- [Page layout](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/layout/pages.py): `src/hwpx/layout/pages.py`

### Format Handling

- [OXML model](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/document.py): `src/hwpx/oxml/document.py`
- [XML primitives](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/oxml/_document_primitives.py): `src/hwpx/oxml/_document_primitives.py`
- [OPC package](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/opc/package.py): `src/hwpx/opc/package.py`
- [HWP5 reader](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/hwp5/reader.py): `src/hwpx/hwp5/reader.py`
- [HWP5 writer](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/hwp5/writer.py): `src/hwpx/hwp5/writer.py`

### Validation and Safety

- [Package validation](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/package_validator.py): `src/hwpx/tools/package_validator.py`
- [Safe save gate](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/quality/save_pipeline.py): `src/hwpx/quality/save_pipeline.py`
- [Package security](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/opc/security.py): `src/hwpx/opc/security.py`
- [Save report](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/quality/report.py): `src/hwpx/quality/report.py`

### Document Tools

- [Text extraction](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/text_extractor.py): `src/hwpx/tools/text_extractor.py`
- [Document export](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/exporter.py): `src/hwpx/tools/exporter.py`
- [Mail merge](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/mail_merge.py): `src/hwpx/tools/mail_merge.py`
- [TOC authoring](https://github.com/airmang/python-hwpx/blob/main/src/hwpx/tools/toc_author.py): `src/hwpx/tools/toc_author.py`

### Other components

- **Python caller**

## Connections

- Python caller → Document API: opens or creates (evidence: `README.md`)
- Document API → OXML model: edits document
- OXML model → XML primitives: uses primitives (evidence: `src/hwpx/oxml/_document_primitives.py`)
- Document API → OPC package: loads and saves (evidence: `src/hwpx/document.py`)
- Document API → Paragraph editing: edits paragraphs
- Document API → Table editing: edits tables
- Document API → Sections and stories: manages sections
- Sections and stories → Page formatting: configures pages (evidence: `src/hwpx/oxml/section.py`)
- Document API → Form fitting: fills form fields
- Form fitting → Text measurement: measures slots (evidence: `src/hwpx/form_fit/engine.py`)
- Python caller → Equation authoring: authors equations (evidence: `README.md`)
- Python caller → Page layout: requests layout (evidence: `README.md`)
- Python caller → Text extraction: extracts text (evidence: `README.md`)
- Python caller → Document export: exports formats (evidence: `README.md`)
- Python caller → Mail merge: runs mail merge (evidence: `README.md`)
- Python caller → TOC authoring: authors contents (evidence: `README.md`)
- Python caller → HWP5 reader: opens HWP5 (evidence: `README.md`)
- HWP5 reader → Document API: converts to model
- Document API → HWP5 writer: saves HWP5 (evidence: `README.md`)
- Python caller → Safe save gate: requests safe save (evidence: `README.md`)
- Safe save gate → Package validation: validates package (evidence: `src/hwpx/quality/save_pipeline.py`)
- Safe save gate → Package security: checks safety (evidence: `src/hwpx/quality/save_pipeline.py`)
- Safe save gate → Save report: composes report (evidence: `src/hwpx/quality/save_pipeline.py`)
- Safe save gate → OPC package: publishes bytes
