Skip to main content

AutoBaseDoc

Automated PDF document generation on top of ReportLab with Matplotlib integration, reusable page templates, and helpers for tables, headers, footers, and table-of-contents handling.

Documentation Status Current Version PyPI Python Version License Test Coverage

Installation

pip install autobasedoc

Development setup:

git clone https://github.com/NuCOS/autobasedoc.git
cd autobasedoc
pip install -e .
pip install -e ".[test]"

Requirements:

  • Python 3.7+
  • ReportLab
  • Matplotlib
  • svglib, pdfrw, img2pdf

Quick Start

import os
from autobasedoc import autorpt as ar

outname = os.path.join(os.getcwd(), "MinimalExample.pdf")

doc = ar.AutoDocTemplate(
    outname,
    onFirstPage=ar.onFirstPage,
    onLaterPages=ar.onLaterPages,
    onLaterSPages=ar.onLaterSPages,
    leftMargin=0.5 * ar.cm,
    rightMargin=0.5 * ar.cm,
    topMargin=0.5 * ar.cm,
    bottomMargin=0.5 * ar.cm,
)

styles = ar.Styles()
styles.registerStyles()

content = []
content.append(ar.Paragraph("Minimal Example Title", styles.title))
content.append(ar.PageBreak())
content.append(ar.Paragraph("Table Of Contents", styles.h1))
content.append(ar.doTableOfContents())

doc.multiBuild(content)

Matplotlib Integration

Use autoPdfImg when a plotting function should return a single ReportLab flowable:

from autobasedoc import autoplot as ap

@ap.autoPdfImg
def create_chart(canvaswidth=5):
    fig, ax = ap.plt.subplots(figsize=(canvaswidth, canvaswidth))
    ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
    ax.set_title("Sample Chart")
    return fig

content.append(create_chart())

Use autoPdfImage when the plot and legend should be placed independently in the document:

@ap.autoPdfImage
def create_chart_with_legend(canvaswidth=5):
    fig, ax = ap.plt.subplots(figsize=(canvaswidth, canvaswidth))
    ax.plot([1, 2, 3, 4], [1, 4, 2, 3], label="series")
    handles, labels = ax.get_legend_handles_labels()
    legend_fig = ap.plt.figure(figsize=(canvaswidth, 0.4))
    legend = legend_fig.legend(handles, labels, loc="center", frameon=False)
    return fig, legend_fig, legend

plot_img, legend_img = create_chart_with_legend()
content.extend([legend_img, plot_img])

Table Layouts

For plain ReportLab tables, the standard ar.Table works well. For AutoBaseDoc-specific layout helpers, use StyledTable and finish with layoutStyledTable():

from autobasedoc.styledtable import StyledTable

styled = StyledTable(gridded=True)
styled.setTableData([
    ["Product", "Q1", "Q2"],
    ["Widget A", "100", "120"],
    ["Widget B", "80", "95"],
])
styled.addTableStyleCommand(("ALIGN", (0, 0), (-1, -1), "CENTER"))

table = styled.layoutStyledTable(colWidths=[4, 3, 3], rowHeights=[1.0, 0.8, 0.8])
content.append(table)

Examples and Documentation

  • Example script: tests/example.py
  • Larger document example: tests/example_document.py
  • Sphinx docs source: sphinx_doc/
  • API docs: Read the generated Sphinx reference or inspect module docstrings

Testing

Install test dependencies and run the suite:

pip install -e ".[test]"
MPLBACKEND=Agg pytest -q

Coverage run:

MPLBACKEND=Agg pytest --cov=autobasedoc --cov-report=term-missing

Release Notes

Version 1.1.11 includes the current packaging cleanup, documentation fixes, and rowHeights forwarding support for styled table layout helpers.

License

This project is licensed under the BSD-3-Clause License. See LICENSE.md.

Links

Release files for autobasedoc 1.1.11

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

Source distribution (sdist)

Source distribution for autobasedoc 1.1.11
File Size Uploaded
autobasedoc-1.1.11.tar.gz 3.4 MB Details

Built distribution (wheel)

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

Total release size: 6.9 MB

Release files / autobasedoc-1.1.11.tar.gz

Download URL autobasedoc-1.1.11.tar.gz
Size 3.4 MB
Tags Source
SHA-256 checksum
How to use checksums
6ae2242c17986b075c246954107d8f64b96b5c48645698623a8a54ce99d20d12
BLAKE2b-256 checksum
How to use checksums
411c8cad56ff4945f8c4653c0101a9eaacae18358ef4a9b406cef5210f138260
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / autobasedoc-1.1.11-py3-none-any.whl

Download URL autobasedoc-1.1.11-py3-none-any.whl
Size 3.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
8552a61469893d013384a57f2cd736f45e1bf84ff128b3af2c7b43823dec6e2c
BLAKE2b-256 checksum
How to use checksums
7f7227225bb73283fe99ac7e5c65be1e8e0ca62eb7975a11bd076cdcef679989
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.1.11 This release

2 release files

1.1.10

1 release file

1.1.9

1 release file

1.1.8

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

0.0.19

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.13

1 release file

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release 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