Skip to main content
PyPI

Udpates the MAILMERGE fields in Office Open XML (docx) files. Can be used on any system without having to install Microsoft Office Word. Supports Python 3.7 and up. For the moment only the INCLUDEPICTURE fields are supported.

It supports local images, URLs and base64 image encoded strings. Also, it allows the resize of the image both in width and height.

The fields are replaced so afterwards they cannot be updated anymore.

This library uses the excellent python-docx library.

Also, it is better used after mailmerging the INCLUDEPICTURE fields using the docx-mailmerge2 library.

Installation

Installation with pip:

$ pip install docx-mergefields

Usage

Open the file.

from mergefields import MergeFieldsDocument
with MergeFieldsDocument("../documents/mailmerge_doc.docx") as doc:
  doc.transform_fields()
  doc.doc.save("../documents/merged_doc.docx")

Examples

From local file, original size:

{ INCLUDEPICTURE "./filename.jpg" }

From a URL, resize width to the given size, resize height to preserving the aspect ratio:

{ INCLUDEPICTURE "https://www.pngall.com/wp-content/uploads/8/Sample-Watermark-PNG-Image.png" \w 200 }

From a base64 URI, resize both width and height to the given value (aspect ratio is not preserved):

{ INCLUDEPICTURE "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQMAAADCCAMAAAB6zFdcAAAAtFBMVEX///9QUU/yX1xKS0mKiopNTkxCQ0FGR0VpamjS0tJHSEa9vbyvr67yXFlSU1FDRELyWVaoqKjc3N3xU1D19fXDxMNWV1XxUU797Ovv7+/j4+P3pKP5vLv+8/O3t7b71NP1i4nzc3D4rqz1hYPzZ2WCgoGUlJN3eHf0e3lgYV/83t2enp76xsXMzcyQkY/1k5H6ysn2k5L3qqg3ODX2m5rzb21lZmT5t7Xr39/su7rmqana4+QStYMYAAAEt0lEQVR4nO3ab3eiOBQGcGkkWFoEBUVtpbXV+qdqZ9S2uzvf/3stuQkQQNvdOT2j1Of3Yk9NMJhLckkyW6sBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAICwWN7eLhfDA7VBuxNF0ar/R3/Sl3ObzaZ9daDy7t4Jfc/zQ2+23FPdmTLuWpbFefd5UKycG3HLTSPIFTbiQnb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ca7st9PPG7BLNzDtBmzaDnxZpfudgIxmNSLJslTvCj8+8Ki+N0gmpqWy127u17pzRUTf0TNihzxVL7boeXmabjLzQZ/s/ei/mAwOHySUH07bTY4r59f/y2Ns9lQ2kGdi0U6G/z3Y/+Wo9n4aibMPr/22xo55z0ThB7NhvD22L/jqMQholc6WjwzM4fOEM9X0O//5Yd/9/vfeRn0kX5b+PXP4y/64wQ2+n9c0C6o+P+B93uC/iDp/2BwlhEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAID/61/qyEpXq0NhcQAAAABJRU5ErkJggg==" \w 200 \h 200 }

Todo / Wish List

  • Include other fields

  • Update the fields instead of replacing them

Contributing

  • Fork the repository on GitHub and start hacking

  • Create / fix the unit tests

  • Send a pull request with your changes

Unit tests

In order to make sure that the library performs the way it was designed, unit tests are used. When providing new features, or fixing bugs, there should be a unit test that demonstrates it. Run the test suite:

python -m unittest discover

Credits

This repository is written and maintained by Iulian Ciorăscu.

Metadata

Release files for docx-mergefields 0.1.5

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-mergefields 0.1.5
File Size Uploaded
docx_mergefields-0.1.5.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docx-mergefields 0.1.5
File Interpreter ABI Platform
docx_mergefields-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 16.8 kB

Release files / docx_mergefields-0.1.5.tar.gz

Download URL docx_mergefields-0.1.5.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
93ea6c9b9d6347fbdf39697ff3d402042cfc5f5df8f04ce39da6cd2cfb90ab3d
BLAKE2b-256 checksum
How to use checksums
b685a1d7585bf5e7cd1e4f4f99acc8ef759d0765d0a09cc276fd60b7b934dc7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 13, 2026.

Transparency log

Release files / docx_mergefields-0.1.5-py3-none-any.whl

Download URL docx_mergefields-0.1.5-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28eca0cd02d69b3e166302289653175a9ab7bf4a00e5db7242c1a23a9611d735
BLAKE2b-256 checksum
How to use checksums
b7d050dc3d8e18d9f7066eeffec311aa7e3137e089c2266a87528ac5bc247fff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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