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())

Command Line Interface (CLI)

pydocmaker also ships with a command-line interface that covers the most common workflows without writing any Python code. It is registered as the pydocmaker console script and can also be run as a module::

pydocmaker <command> [arguments]
python -m pydocmaker.cli <command> [arguments]

Commands:

Command Description
example Write the built-in example document
show Display a document on the terminal
build/convert Convert document(s) into another format (default: PDF)
check Validate the syntax of a document or template
extract Print a template's parameters as JSON
template Copy a registered document template

Output formats: pdf, md/markdown, html, typ/typst, tex/latex, json, docx/word, ipynb, textile, pydoc/pyd.

Quick examples:

# Generate the example document as PDF
pydocmaker example pdf -o example.pdf

# Convert markdown to PDF (output: README.pdf)
pydocmaker build README.md

# Convert markdown to HTML with a custom template
pydocmaker build README.md -f html -t base.tex --pTitle "My Report"

# Show a saved document in the terminal
pydocmaker show rich doc.json
pydocmaker show html doc.json

# Validate a block template and see its parameters
pydocmaker check base.tex
pydocmaker extract base.typ

# Copy a template for editing
pydocmaker template base.tex -o my_custom_template.tex

Template parameters can be supplied via -p/--parameters (a JSON string or file path), or as unknown --name value arguments that pydocmaker collects automatically::

# Using --name value arguments
pydocmaker example pdf -t base --pAuthor "Jane Doe" --pTitle "My Report"

# Using a JSON file
pydocmaker build doc.md -p params.json

# Using a JSON string
pydocmaker build doc.md -p '{"pTitle": "From JSON"}'

Attachments for templates (images, logos, bibliography files) can be given explicitly with -a/--assets::

pydocmaker build README.md -t report.tex -a ./assets -a logo.png

For the full CLI reference see the documentation: CLI Reference.

Block Templates (comment-delimited, standalone-compilable)

Besides the classic Jinja2 templates (.j2 files), pydocmaker supports block templates: plain .html, .tex and .typ files that carry pydocmaker: markers inside comments. These files stay valid and compilable standalone (the native compilers ignore the parameter constructs and show the body placeholder) while pydocmaker can render, scaffold and update them without ever modifying the file on disk during render.

% pydocmaker:parameters:begin
% pydocmaker:param:title
\providecommand{\title}{My Report}
% pydocmaker:param:acronyms
\newcommand{\acronyms}{%
\begin{description}
\item{SNR}{Signal-to-Noise Ratio}
\end{description}
}
% pydocmaker:parameters:end

\begin{document}
% pydocmaker:body:begin
placeholder text
% pydocmaker:body:end
\end{document}
// pydocmaker:parameters:begin
// pydocmaker:param:title
#let title = "My Report"
// pydocmaker:param:acronyms
#let acronyms = (SNR: "Signal-to-Noise Ratio")
// pydocmaker:parameters:end

// pydocmaker:body:begin
placeholder text
// pydocmaker:body:end
<!-- pydocmaker:parameters:begin -->
<!-- pydocmaker:param:title -->
<meta name="pydocmaker:param:title" content="My Report">
<!-- pydocmaker:parameters:end -->
<body>
<!-- pydocmaker:body:begin -->
placeholder text
<!-- pydocmaker:body:end -->
</body>

Engine selection is automatic (markers in the template source select the block engine) and can be forced with the template_engine argument ('auto' (default), 'jinja2' or 'blocks') on Doc.to_html, Doc.to_typst and Doc.to_pdf:

import pydocmaker as pyd

doc = pyd.Doc().add_text('Hello Block Templates')

# auto-detection: marked sources render through the block engine
out = doc.to_typst(template='my_template.typ', template_params={'title': 'Rendered'})

# explicit override
out = doc.to_typst(template='my_template.typ', template_engine='blocks')
out = doc.to_typst(template='my_template.typ', template_engine='jinja2')

The pydocmaker.blocktmpl subpackage exposes the engine directly:

from pydocmaker import blocktmpl

blocktmpl.detect(source)                    # True if block markers are present
blocktmpl.parse(source, tformat='typ')      # parse into a BlockDocument
blocktmpl.scaffold(source, tformat='typ', params={'title': 'V1'})   # insert missing blocks
blocktmpl.update_params(source, {'title': 'V2'})                    # write values back (idempotent)
blocktmpl.render(source, body='...', params={'title': 'V2'})        # replace body + apply params

When resolved from a template directory, an exact file name ('base.tex') resolves to the block file even when a base.tex.j2 twin exists; short IDs ('base') keep preferring the .j2 file for backward compatibility. Shipped examples: base.tex, base.html, base.typ in src/pydocmaker/templates/.

NOTE for LaTeX templates: parameter names that collide with LaTeX kernel macros (title, author, date) produce inert \providecommand definitions; use names such as reporttitle when the value shall be displayed in the document body.

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)

Metadata

Release files for pydocmaker 2.8.1

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

Source distribution (sdist)

Source distribution for pydocmaker 2.8.1
File Size Uploaded Provenance Actions
pydocmaker-2.8.1.tar.gz 281.6 kB With provenance Details for pydocmaker-2.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydocmaker 2.8.1
File Interpreter ABI Platform Actions
pydocmaker-2.8.1-py3-none-any.whl Python 3 none any Details for pydocmaker-2.8.1-py3-none-any.whl

Total release size: 525.8 kB

Release files / pydocmaker-2.8.1.tar.gz

Download URL pydocmaker-2.8.1.tar.gz
Size 281.6 kB
Tags Source
SHA-256 checksum
How to use checksums
54fb7898de021945e839b17cbb94ba0ef41e45bfc8a37785c47e9e5b06a58584
BLAKE2b-256 checksum
How to use checksums
57e55bc9fc6a7307d3f1f9eb3db8340e6364bd6f2a8735d20bc89442c8beef53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 27, 2026.

Transparency log

Release files / pydocmaker-2.8.1-py3-none-any.whl

Download URL pydocmaker-2.8.1-py3-none-any.whl
Size 244.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5b2f592e2e853feaea202a3b20f833ef80e4342e52df88b493d3e5b58953193
BLAKE2b-256 checksum
How to use checksums
41c9791c00bd289aa26eb7f195a30ed1f6fb57e9784b121f947175eadb133b9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 27, 2026.

Transparency log

Security for pydocmaker 2.8.1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydocmaker-2.8.1.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 Nov 27, 2026.

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.

Release history Release notifications | RSS feed

This release

2.8.1 This release

2 release files Full provenance

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