Skip to main content

reportsmith

A small, dependency-free Python library for building reports programmatically and exporting them to Markdown, a standalone styled HTML document, LaTeX, or (optionally) PDF.

Features

  • Fluent builder API with chainable methods and nested sections (with report.section(...))
  • Table of contents in every format: linked lists in Markdown/HTML, \tableofcontents in LaTeX, clickable entries with page numbers in PDF
  • Tables straight from data: lists of dicts, CSV files, or pandas DataFrames, with number formatting, missing-value placeholders, and automatic right-alignment of numeric columns
  • Elements: headings, paragraphs, tables (with alignment and captions), bullet/numbered lists (nestable), code blocks, block quotes, images, horizontal rules, and format-specific raw passthrough
  • Inline formatting helpers: bold(), italic(), code(), link() — render correctly in both formats
  • Correct escaping everywhere: HTML entities, Markdown table pipes, code fences that widen when the source contains ```
  • HTML export ships with a clean embedded stylesheet (light/dark aware) that you can replace with your own CSS
  • LaTeX export: a compilable document (pdfLaTeX/XeLaTeX/LuaLaTeX) with booktabs tables, framed code blocks, hyperlinks, and PDF bookmarks — or a body fragment to \input into your own document
  • Optional PDF export (pip install reportsmith[pdf], via fpdf2): matching styling, PDF bookmarks from sections, clickable links, auto-detected Unicode system fonts
  • No required dependencies; Python 3.9+

Installation

pip install -e .

Or just copy the reportsmith/ package into your project — it has no dependencies.

Quick start

from reportsmith import Report, bold, link

report = Report("Q3 Sales Report", author="Jane Doe", subtitle="Quarterly summary")
report.toc()                         # table of contents

with report.section("Overview") as s:
    s.paragraph(["Revenue was ", bold("up 12%"), " quarter over quarter."])
    s.table(
        ["Region", "Revenue"],
        [["EMEA", "$1.2M"], ["APAC", "$0.9M"]],
        caption="Revenue by region",
        align=["left", "right"],
    )

with report.section("Next steps") as s:
    s.numbered_list([
        "Expand APAC sales team",
        ["Review ", link("pricing proposal", "https://example.com/pricing")],
    ])

print(report.to_markdown())          # Markdown string
print(report.to_html())              # standalone HTML page
report.save_markdown("report.md")
report.save_html("report.html")
report.save_latex("report.tex")    # compile with pdflatex/xelatex/lualatex

Run python example.py for a fuller demo that writes example_report.md, example_report.html, and example_report.tex.

Documentation

  • User Guide — a walkthrough of every feature with examples: sections, inline formatting, tables, lists, raw passthrough, HTML customization, and escaping behavior.
  • API Reference — signatures, parameters, and exceptions for every public class and function (reStructuredText, Sphinx-ready).

The docs are also a buildable Sphinx site:

pip install -e .[docs]
python -m sphinx -b html docs docs/_build/html

Then open docs/_build/html/index.html.

API overview

Report(title, author="", date=None, subtitle="")

date accepts a string, datetime.date, or datetime.datetime; it defaults to today.

Builder methods (all chainable, also available on sections):

Method Adds
section(title) Nested section; heading level tracks nesting depth. Usable as a context manager.
heading(text, level=None) Explicit heading (level defaults to the container's depth + 1)
paragraph(content) Paragraph
quote(content) Block quote
code(source, language="") Fenced/<pre> code block
bullet_list(items) / numbered_list(items) List; items may be text or a nested ListElement
table(headers, rows, caption="", align=None) Table; align entries are "left", "center", "right"
table_from_records(records) / table_from_csv(source) / table_from_dataframe(df) Table built from data; options columns, headers, formats, missing, align, caption
image(src, alt="", title="") Image
horizontal_rule() Rule
raw(content, format="both") Verbatim content for "markdown", "html", "latex", or "both" (Markdown + HTML)
toc(title="Contents", depth=3) Table of contents for the whole report; depth 1–5 sets how many heading levels are listed
add(element) Any pre-built element

Anywhere text is accepted you may pass a plain string or a list mixing strings with bold(), italic(), code(), and link(text, href) spans.

Export

  • report.to_markdown() → GitHub-flavored Markdown string
  • report.to_html(full_document=True, css=None) → HTML string; full_document=False returns just the body fragment, css= replaces the default stylesheet
  • report.to_latex(full_document=True, document_class="article", class_options="11pt,a4paper", preamble="", numbered=False) → LaTeX source; full_document=False returns just the body, preamble= is appended to the built-in preamble
  • report.to_pdf(fonts=None, mono_fonts=None) → PDF bytes (requires the pdf extra); pass TTF path quadruples to control typefaces
  • report.save_markdown(path) / report.save_html(path, ...) / report.save_latex(path, ...) / report.save_pdf(path, ...) → write to a file, return the Path

Running tests

The test suite (256 tests) lives in tests/:

python -m pytest

With a coverage report (requires pytest-cov):

python -m pytest --cov=reportsmith --cov-report=term-missing

Changelog

See CHANGELOG.md — the format follows Keep a Changelog.

License

MIT

Metadata

Release files for reportsmith 0.3.0

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

Source distribution (sdist)

Source distribution for reportsmith 0.3.0
File Size Uploaded
reportsmith-0.3.0.tar.gz 39.8 kB Details

Built distribution (wheel)

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

Total release size: 69.5 kB

Release files / reportsmith-0.3.0.tar.gz

Download URL reportsmith-0.3.0.tar.gz
Size 39.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cff5efb484cd9e2cb1bdb4777c7a5f81f09a42129a71565f042948e34ddbf88b
BLAKE2b-256 checksum
How to use checksums
64b0b400ba80f3a7e4693e5da6b0a18bcf86777f9612a3012728156e3d0567db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 15, 2026.

Transparency log

Release files / reportsmith-0.3.0-py3-none-any.whl

Download URL reportsmith-0.3.0-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
950f953762ced52c93ec7073481e0500f602f169fb322c208f290bb77062e055
BLAKE2b-256 checksum
How to use checksums
aa384cf2de8aec06ff744d22158398845b77b110aba1c57800d8e261ce6d5168
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 15, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.0

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