Skip to main content

Compose .docx documents

Project description

docxcompose is a Python library for concatenating/appending Microsoft Word (.docx) files.

Example usage

Append a document to another document:

from docxcompose.composer import Composer
from docx import Document
master = Document("master.docx")
composer = Composer(master)
doc1 = Document("doc1.docx")
composer.append(doc1)
composer.save("combined.docx")

The docxcompose console script

The docxcompose console script allows to compose docx files from the command line, e.g.:

$ docxcompose files/master.docx files/content.docx -o files/composed.docx

Installation for development

To install docxcompose for development, clone the repository and using a python with poetry:

$ poetry install

Tests can then be run with pytest.

A note about testing

The tests provide helpers for blackbox testing that can compare whole word files. To do so the following files should be provided:

  • a file for the expected output that should be added to the folder docs/composed_fixture

  • multiple files that can be composed into the file above should be added to the folder docs.

The expected output can now be tested as follows:

def test_example():
    fixture = FixtureDocument("expected.docx")
    composed = ComposedDocument("master.docx", "slave1.docx", "slave2.docx")
    assert fixture == composed

Should the assertion fail the output file will be stored in the folder docs/composed_debug with the filename of the fixture file, expected.docx in case of this example.

Headers and footers

The first document is considered as the main template and headers and footers from the other documents are ignored, so that the header and footer of the first document is used throughout the merged file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docxcompose-2.0.2.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docxcompose-2.0.2-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file docxcompose-2.0.2.tar.gz.

File metadata

  • Download URL: docxcompose-2.0.2.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.7 Darwin/24.6.0

File hashes

Hashes for docxcompose-2.0.2.tar.gz
Algorithm Hash digest
SHA256 3799c2a1e581765bd94b97fe5f88c28cf6b3ffbe13b8a35b46f42eabd7318e96
MD5 6067a1f4ff0f95c7e4e404b34d72d94b
BLAKE2b-256 cdc98e50cc5c0cf8725b9542aed3e69e6ccae63623c01a5caa5431fbe8820486

See more details on using hashes here.

File details

Details for the file docxcompose-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: docxcompose-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.7 Darwin/24.6.0

File hashes

Hashes for docxcompose-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7e45cdadbde01181d4479c8cf08c3a148729abe7fe9b774cc08c20bcc0afde9
MD5 f8289d4ea8bc9f7cdafec91407ed03d2
BLAKE2b-256 83ee14a9732d148319e28e54fea2fa7acdb30c321e5e5c2f8ac2904b106cb952

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page