Skip to main content

pydocmaker

Icon

A minimal easy to use python document maker to create reports in pdf, md, typst, html, docx, tex and more formats. Written purely in python, but optional features use external non python libraries such as typst or pandoc (if installed). Nearly no code written by AI (some test cases, and some documentation was written by AI tools)

  • NOTE: some functions will try to call pandoc and fall back if not found.
  • NOTE: exporting PDFs by default works using typst. All other engines need optional dependencies, such as either a latex compiler or Microsoft Word, or Libreoffice.

Full documentation at https://pydocmaker.readthedocs.io/en/latest/

For an example of a created PDF document please see README.pdf (located within the root folder of this repository) which is this README.md file converted to pdf via pydocmaker and typst with the report template.

Installation

Install via:

pip install pydocmaker

TL;DR; Code examples

Snippet:

import pydocmaker as pyd

doc = pyd.Doc.get_example()
doc.show()

Minimal Usage Example:

import pydocmaker as pyd

doc = pyd.Doc() # basic doc. Workd like a list, We always append new content to the end
doc.add('dummy text') # adds raw text

# this is how to add parts to the document
doc.add_pre('this will be shown as preformatted') # preformatted
doc.add_md('This is some *fancy* `markdown` **text**') # markdown
doc.add_tex(r'\textbf{Hello, LaTeX!}') # latex
doc.add_table([['John Doe', "30"]], header=['Name', 'Age'], caption='example table') # table

# this is how to add an image from link
doc.add_image("https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png", caption='Github Logo')

# this is how to add matplotlib figures to your report
import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot([1,2,3], [6,5,7])
doc.add_image(fig, caption='Example figure', width=0.7)

# show will render and show a doc when in an iPython
# environment such as jupyter or colab, on the terminal 
# it will fall back to use rich console instead
doc.show()

"Showing" Documents in iPython/Terminal

the Doc class has a method called show which will detect if its running in Ipython. If it does it will render the document and show it. If not it will fallback to a rich consiole and do its best to show the content on the terminal (on a terminal image support is very limited). The desired rendering format can be set with the engine argument. rich, markdown, HTML, or PDF is possible.

Any environment: NOTE: when rendering with "rich" console image support is very limited, since images will be printed on the console as pixels (with the size being scaled down to the console width)

doc.show()
doc.show('rich')
doc.show('rich', embed_images=False)

In Ipython (such as Jupyter or Colab) any of the following:

doc.show('md')

Or:

doc.show('html')

Or:

doc.show('pdf')

NOTE: some IDEs do not support the PDF option and instead open a "save" dialog, but in a browser with jupyter this works

Exporting:

export via:

# returns string
text_html = doc.export('html')
# or write a file
doc.export('path/to/my_file.html')

Or alternatively:

doc.to_html('path/to/my_file.html') # will write a HTML file
doc.to_pdf('path/to/my_file.pdf') # will write a PDF file via typst
doc.to_pdf('path/to/my_file.zip') # will write the whole latex project dir as a pdf file
doc.to_markdown('path/to/my_file.md') # will write a Markdown file
doc.to_docx('path/to/my_file.docx') # will write a docx file
doc.to_textile('path/to/my_file.textile.zip') # will pack all textile files and write them to a zip archive
doc.to_tex('path/to/my_file.tex.zip') # will pack all tex files and write them to a zip archive
doc.to_ipynb('path/to/my_file.ipynb') # will write a ipynb file

doc.to_json('path/to/doc.json') # saves the document

Saving and Loading (Minimal)

A minimal example showing how to save and load Doc objects. Doc.save accepts a file path (string or pathlib.Path) or a file-like object. When no path is provided it returns the rendered content (HTML by default). Doc.load accepts a JSON string/bytes, a path, or a stream.

import pydocmaker as pyd

doc = pyd.get_example()

# save to common formats (case-insensitive suffixes are supported)
doc.save('report.html')      # writes HTML
doc.save('report.json')      # writes JSON
doc.save('report.ipynb')     # writes an ipynb (may depend on environment)

doc2 = pyd.load('report.json') # load back in (should now be same as doc)

json_str = doc.save(format='json') # save as in-memory string in given format
loaded = pyd.load(json_str) # and load back

Supported save/load formats for Doc.save/Doc.load:

  • .html, .pyd, .pydoc — HTML serialization/serialization used by pydocmaker
  • .ipynb — Jupyter notebook (may require additional environment support)
  • .json — Raw document JSON (recommended for round-trip fidelity)

Note: Saving and Loading is fundamentally different from exporting a report (e.G. to_html), since save/load allows round trip loading and saving, while exporting makes nice documents to view in other other software and not load again.

Configuring Options:

All configurable options for this package are in pydocmaker.options. They are always callable functions with "_get", "_set", "*_scan" etc.

import pydocmaker as pyd

pyd.options.pandoc_allowed_set(False)
print(pyd.options.pandoc_allowed_get())

pyd.options.pdf_engine_set('typst') # default
print(pyd.options.pdf_engine_get())

Install Optional Requirements

Optional Requirement pandoc

In order to get all functionality pandoc needs to be available. Please follow the recommended installation steps on the software projects webpage. For convenience the minimal installation is listed here:

On Linux (Debian/Ubuntu) install via:

sudo apt update
sudo apt install pandoc

On MacOS:

brew install pandoc

On Windows:

winget install JohnMacFarlane.Pandoc

Optional Requirement Latex

In order to get all functionality a latex compiler needs to be available. Please follow the recommended installation steps on the webpage. For convenience the minimal installation is listed here:

On Linux (Debian/Ubuntu) install via:

sudo apt update
sudo apt install texlive-full

On MacOS:

brew install --cask mactex

On Windows:

winget install MiKTeX.MiKTeX

Optional Requirement for DOCX either libreoffice or win32com

Some DOCX functionality need either Microsoft Windows and Microsoft Word and the win32com library or libreoffice available.

Installing pywin32 (Windows only)

Install via:

pip install pywin32

Installing libreoffice

On a Linux (Debian/Ubuntu) system insall via:

sudo apt update
sudo apt-get install libreoffice

On MacOS:

brew install --cask libreoffice

On Windows:

winget install TheDocumentFoundation.LibreOffice

NOTE: You need to add the folder with the libreoffice executeables to PATH in windows.

Writing Word docx Documents with templates and fields

Below is an example on how to use pydocmaker to write word docx documents from format templates and also automatically "replace" fields (MergeFields in Word or plain text) to be filled out in the docx document with text from python.

(NOTE: some of the code below utilized the win32com api and only works on windows)

prepare a report, a template and some fields in the template:

import pydocmaker as pyd

metadata = {
    'repno': "1234",
    "summary": "This is a nice workflow for automatically creating docx documents",
    "date": "2025-12-13",
    "comment": f"this works!",
    "author": "Me"
}

# HOWTO: 
#  Adding MergeFields In Word to replace them later: 
#    Go to Insert → Quick Parts → Field → MergeField.
templatepath = 'my/path/template.docx'
outpath = 'my/path/outfile.docx'

# get a pyd example document to show the concept
doc = pyd.get_example()

this is the quick and easy way using the common pydocmaker api:

# three different examples below
docx_bts = doc.to_docx("my/path/outfile.docx", template=templatepath, template_params=metadata, use_w32=False)
docx_bts = doc.to_docx("my/path/outfile_w32.docx", template=templatepath, template_params=metadata, use_w32=True)
docx_bts = doc.to_docx("my/path/outfile_w32_comp.pdf", template=templatepath, template_params=metadata, use_w32=True, as_pdf=True, compress_images=True)

Download files

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

Source Distribution

pydocmaker-2.7.0.tar.gz (162.2 kB view details)

Uploaded Source

Built Distribution

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

pydocmaker-2.7.0-py3-none-any.whl (156.6 kB view details)

Uploaded Python 3

File details

Details for the file pydocmaker-2.7.0.tar.gz.

File metadata

  • Download URL: pydocmaker-2.7.0.tar.gz
  • Upload date:
  • Size: 162.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pydocmaker-2.7.0.tar.gz
Algorithm Hash digest
SHA256 334b07a02a5d79b0a1f7aeecde967f1b6f048e71830b425c07ebd41d727f5353
MD5 8bd18705cc5f917b6a244624e728bf19
BLAKE2b-256 e456bf785c39fc0680a53890230cf8a335cf30f2bf050c06ac6983df51a8e807

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydocmaker-2.7.0.tar.gz:

Publisher: pypi-publish.yml on TobiasGlaubach/pydocmaker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydocmaker-2.7.0-py3-none-any.whl.

File metadata

  • Download URL: pydocmaker-2.7.0-py3-none-any.whl
  • Upload date:
  • Size: 156.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pydocmaker-2.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f772f3f10280d93ed5734f4b420ce76705512370646b9fea1808235b8de3967
MD5 e64c247ebe7ca30689a5f671479e5dcd
BLAKE2b-256 26c48357703145ae4d96ff4833d2d0f9fadce3772439781e7c7ff173661775c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydocmaker-2.7.0-py3-none-any.whl:

Publisher: pypi-publish.yml on TobiasGlaubach/pydocmaker

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.7.0 This release

2 files

2.6.13

2 files

2.6.12

2 files

2.6.11

2 files

2.6.10

2 files

2.6.9

2 files

2.6.8

2 files

2.6.7

2 files

2.6.6

2 files

2.6.5

2 files

2.6.4

2 files

2.6.3

2 files

2.6.2

2 files

2.5.5

1 file

2.5.4

1 file

2.5.3

1 file

2.5.2

2 files

2.5.1

2 files

2.5.0

2 files

2.4.1

1 file

2.4.0

1 file

2.3.4

1 file

2.3.3

1 file

2.3.2

1 file

2.3.1

1 file

2.3.0

1 file

2.2.8

1 file

2.2.7

1 file

2.2.6

1 file

2.2.5

1 file

2.2.3

1 file

2.2.2

1 file

2.2.1

1 file

2.2.0

1 file

2.1.7

1 file

2.1.6

1 file

2.1.5

1 file

2.1.4

1 file

2.1.3

1 file

2.1.2

1 file

2.1.1

1 file

2.1.0

1 file

2.0.0

1 file

1.4.3

1 file

1.4.2

1 file

1.4.1

1 file

1.4.0

1 file

1.3.9

1 file

1.3.8

1 file

1.3.7

1 file

1.3.6

1 file

1.3.5

1 file

1.3.4

1 file

1.3.3

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.0

1 file

1.1.4

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

1 file

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