Skip to main content

DOCX Renderer

This package lets you run your Microsoft Word documents like a script. You can insert placeholders in the document and use either a Python function or an equivalent command-line tool to convert it into an output rendered document.

Documentation

Installation

pip install docx-renderer

Usage

Below is a simple example.

from docx_renderer import DOCXRenderer
p = DOCXRenderer("template.docx")

someval = "world!"
def mymethod(abc):
    return f"{abc} " * 5

p.render(
    "output.docx", 
    {
        "variable": someval, "mymethod": mymethod, "myimage": "is_it_worth.png"
    }
)

This will replace placeholders in the template document with the provided values.

Before

Before

After

After

You can define some functions within the document itself by writing Python code in the comments section. The variables and functions in this code can be used in the main document.

For example: write the following in one of the comments in the document.

```python
def myfunc(input):
    return input * 42
```

Now you can, for example, add the placeholder {{{myfunc(42)}}} in your document.

If the template document is a self-contained Python script (i.e., it does not require variable values and function definitions to be passed from outside), you can generate the output document directly from the command line using the following command.

docx-renderer input_template.docx output_file.docx

Placeholders

You can have placeholders for text, images, or tables. Placeholders can be added as regular text. All placeholders should be enclosed within a pair of triple braces ({{{ and }}}).

Text

Any placeholder which can be evaluated into a string can act as a text placeholder.

For example: {{{"hello " * 10/2}}} or {{{abs(-2)}}}

Image

If you have added :image() as a suffix to the Python statement, the renderer will try to convert the value of the Python statement to a file location and insert an image from that file location.

For example: {{{"c:\\temp\\myimage.png":image()}}}

Table

Tables are similar to images, but instead of a string, the Python statement should evaluate to a list of lists. Then you can add :table() as a suffix, and it will be converted to a table inside the document.

For example: {{{[["col1", "col2", "col3"],[1, 2, 3]]:table()}}} will render to

col1 col2 col3
1 2 3

You can create nested tables as well (if you put a variable placeholder inside an existing table which evaluates to a list of lists with :table() plugin)

Hyperlinks

You can use placeholders with hyperlinks. These hyperlinks inturn can contain other placeholders which should evaluate to an external link. Please note that target placeholders dont support any plugins.

Metadata

Release files for docx-renderer 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docx-renderer 0.3.0
File Size Uploaded Provenance
docx_renderer-0.3.0.tar.gz 10.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for docx-renderer 0.3.0
File Interpreter ABI Platform
docx_renderer-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / docx_renderer-0.3.0.tar.gz

Download URL docx_renderer-0.3.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e06ffe8c96be9bcd14621016465624b23d9b73fae0b6f9a6c800571e7aae7a35
BLAKE2b-256 checksum
How to use checksums
fffc6b96f059771bff91609cd51ab9535f89bcf319392f5f7869b357efce81bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 13, 2025.

Transparency log

Release files / docx_renderer-0.3.0-py3-none-any.whl

Download URL docx_renderer-0.3.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ed6553db1b7963052561916f63e1575a43b5c95d2700ff5c3cdbe87177c7c09
BLAKE2b-256 checksum
How to use checksums
69f997aca0fc9c12275ff82aa3638c709f982707823dada45baceeffe0535975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 13, 2025.

Transparency log

Security for docx-renderer 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for docx_renderer-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 13, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page