Lightweight Word report generation library based on python-docx
Project description
docxspec
English | 简体中文
docxspec is a lightweight Word report generation library built on top of python-docx.
It provides a small, structured API for generating .docx reports from user-supplied templates
and containerized content blocks. It is suitable for automated test reports, simulation reports,
and other document-generation workflows.
Features
- Template-based Word report generation
- Structured content container API
- Text, image, and table insertion
- Rich text style helpers
- Automatic figure and table caption numbering
- PyPI-ready packaging and CI/CD workflows
Installation
Install from PyPI:
pip install docxspec
Or install from source:
git clone https://github.com/Poggi-Tang/docxspec.git
cd docxspec
pip install -e .
Quick Start
from docxspec import BODY_STYLE, WordAPI, make_rich_text
api = WordAPI("your_template.docx")
text = make_rich_text(
"This text is inserted into the template.",
BODY_STYLE,
)
image_container = api.new_container()
image_container.add_image(
"your_image.png",
width_cm=8.0,
align="center",
)
table_container = api.new_container()
table_container.add_table_by_config(
{
"data": [
["Name", "Value"],
["Example", "123"],
]
}
)
api.render(
{
"text": text,
"image": image_container.subdoc,
"table": table_container.subdoc,
},
"report.docx",
)
Demo Directory
The repository includes a runnable demo set in Demo/.
It uses one shared template file:
Demo/template.docx
And provides these example scripts:
Demo/demo1_paragraph.pyDemo/demo2_container_paragraph.pyDemo/demo3_container_image_caption.pyDemo/demo4_container_table_caption.pyDemo/demo5_container_table_image_caption.pyDemo/demo6_header_footer.pyDemo/demo7_styles_in_container.pyDemo/demo8_all_in_one.py
Run them from the repository root, for example:
python Demo/demo1_paragraph.py
python Demo/demo8_all_in_one.py
Generated files are written to Demo/output/.
Note: template and demo assets are repository examples. They are not packaged into the published wheel.
Project Structure
docxspec
├── .github/
│ └── workflows/
├── Demo/
├── src/
│ └── docxspec/
│ ├── __init__.py
│ ├── word_api.py
│ └── word_styles.py
├── tests/
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── README.zh-CN.md
└── pyproject.toml
Release Automation
This repository is prepared for a professional Python package workflow:
- CI runs lint and tests on push and pull request.
- Semantic Release updates the version, changelog, tag, and GitHub Release.
- Trusted Publishing publishes to PyPI from GitHub Actions without a PyPI API token.
- Build artifacts include both source distribution and wheel.
Development
pip install -e .[dev]
pytest
ruff check .
When developing locally, prepare your own .docx template files in the repository or project workspace and pass their paths explicitly to WordAPI.
License
MIT License. See LICENSE.
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
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 docxspec-0.0.3.tar.gz.
File metadata
- Download URL: docxspec-0.0.3.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce83219e424153a95a8da9054b2a4a21ed783e3ff55c9b5008d786085acf298e
|
|
| MD5 |
75b18acce006f5e2c23eabd187f99195
|
|
| BLAKE2b-256 |
636618ae0dac7ab814bcff55f56f755c6039ef2a701782df13585d773d66e6c3
|
Provenance
The following attestation bundles were made for docxspec-0.0.3.tar.gz:
Publisher:
publish.yml on Poggi-Tang/DocxSpec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docxspec-0.0.3.tar.gz -
Subject digest:
ce83219e424153a95a8da9054b2a4a21ed783e3ff55c9b5008d786085acf298e - Sigstore transparency entry: 1356314201
- Sigstore integration time:
-
Permalink:
Poggi-Tang/DocxSpec@553d3f2ee1dba0fa7e09626018b28810c8d5ab3e -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Poggi-Tang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@553d3f2ee1dba0fa7e09626018b28810c8d5ab3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file docxspec-0.0.3-py3-none-any.whl.
File metadata
- Download URL: docxspec-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2ff719ad7eea4667c598a176da9bce26afb7035f24dc77003f1d90a8481fcd3
|
|
| MD5 |
55f04d7849c346bc9756fbc77e2d0b4f
|
|
| BLAKE2b-256 |
5476f46c5022de71b0bbd3f970b899083d4833c130baf809a2be0d650c7a018a
|
Provenance
The following attestation bundles were made for docxspec-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on Poggi-Tang/DocxSpec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docxspec-0.0.3-py3-none-any.whl -
Subject digest:
e2ff719ad7eea4667c598a176da9bce26afb7035f24dc77003f1d90a8481fcd3 - Sigstore transparency entry: 1356314208
- Sigstore integration time:
-
Permalink:
Poggi-Tang/DocxSpec@553d3f2ee1dba0fa7e09626018b28810c8d5ab3e -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/Poggi-Tang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@553d3f2ee1dba0fa7e09626018b28810c8d5ab3e -
Trigger Event:
push
-
Statement type: