Skip to main content

Convert HTML content with tables and charts to production-quality DOCX and PDF documents with native editable charts.

Project description

reportkit

Convert HTML content with tables and charts to production-quality DOCX and PDF documents with native editable charts.

CI Python 3.11+ License: MIT

Overview

reportkit transforms HTML content โ€” including headings, paragraphs, tables, and interactive charts โ€” into native Microsoft Word (.docx) and PDF documents.

Charts are injected as native Office charts in DOCX (editable in Word) and as high-quality matplotlib renders in PDF.

Key Features

  • ๐Ÿ“„ Dual output: Generate both DOCX and PDF from the same HTML
  • ๐Ÿ“Š Native Office charts: Bar, line, pie, doughnut, and area charts โ€” editable in Word
  • ๐Ÿ“‹ HTML table support: Full header/row parsing with styled output
  • ๐Ÿ”Œ Chart.js integration: Pass Chart.js configs directly from your frontend
  • ๐ŸŒ REST API: Optional Flask-based API for service deployment
  • ๐Ÿ“ฆ Library-first: Use as a Python library or as a web service
  • ๐Ÿ”’ Production-ready: Type-safe, tested, with proper error handling

Installation

Library only (no web server)

pip install reportkit

With Flask API

pip install reportkit[api]

Development

git clone https://github.com/Akay24/reportkit.git
cd reportkit
pip install -e ".[dev]"

Quick Start

As a Python Library

from reportkit import convert_html_to_docx, convert_html_to_pdf

html = """
<h1>Quarterly Report</h1>
<p>Performance summary for Q1-Q3.</p>
<table>
  <thead>
    <tr><th>Quarter</th><th>Revenue</th></tr>
  </thead>
  <tbody>
    <tr><td>Q1</td><td>$120M</td></tr>
    <tr><td>Q2</td><td>$150M</td></tr>
  </tbody>
</table>
"""

# Generate DOCX (charts are editable in Word!)
convert_html_to_docx(html, "report.docx")

# Generate PDF
convert_html_to_pdf(html, "report.pdf")

With Charts

from reportkit import convert_html_to_docx

html = """
<h1>Sales Report</h1>
<div data-chart-id="sales" data-chart-type="bar" data-chart-title="Sales by Region"></div>
"""

charts = {
    "sales": {
        "chart_id": "sales",
        "chart_type": "bar",
        "title": "Sales by Region",
        "categories": ["North", "South", "East", "West"],
        "series": [
            {"name": "2025", "values": [120, 90, 150, 80]},
            {"name": "2026", "values": [140, 110, 170, 95]},
        ],
    }
}

convert_html_to_docx(html, "sales_report.docx", charts_data=charts)

With Chart.js Payloads

from reportkit import ChartJsAdapter, convert_html_to_docx

# Adapt a Chart.js config from your frontend
chart = ChartJsAdapter.adapt({
    "chartId": "revenue",
    "chartConfig": {
        "type": "bar",
        "data": {
            "labels": ["Q1", "Q2", "Q3"],
            "datasets": [
                {"label": "Revenue", "data": [120, 150, 180]}
            ]
        }
    }
})

print(chart.chart_id)    # "revenue"
print(chart.chart_type)  # "bar"

As a REST API

# Start the server
REPORTKIT_DEBUG=1 python -m reportkit.app
# Convert to DOCX
curl -X POST http://localhost:5000/convert/docx \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Hello World</h1>"}' \
  --output report.docx

# Convert to PDF
curl -X POST http://localhost:5000/convert/pdf \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Hello World</h1>"}' \
  --output report.pdf

API Reference

Top-Level Functions

Function Description
convert_html_to_docx(html, path, charts_data=None) Convert HTML to DOCX (editable charts)
convert_html_to_pdf(html, path, charts_data=None) Convert HTML to PDF
convert(html, path, format, charts_data=None) Convert to any format

Models

Class Description
Chart Chart with categories and series
Series A single data series (name + values)
Document Ordered collection of elements
Paragraph Text block or heading
Table Structured table (headers + rows)

REST Endpoints

Method Path Description
POST /convert/docx Convert HTML to DOCX (returns file)
POST /convert/pdf Convert HTML to PDF (returns file)

Request Body

{
  "html": "<h1>Title</h1><p>Content</p>",
  "charts": [
    {
      "chart_id": "myChart",
      "chart_type": "bar",
      "title": "My Chart",
      "categories": ["A", "B"],
      "series": [{"name": "Data", "values": [10, 20]}]
    }
  ]
}

Configuration

Environment Variable Default Description
REPORTKIT_DEBUG false Enable debug mode
REPORTKIT_MAX_CONTENT_MB 16 Max request body size (MB)

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=reportkit --cov-report=term-missing

# Lint
ruff check src/ tests/

# Type check
mypy src/

# Build package
python -m build

Project Structure

reportkit/
โ”œโ”€โ”€ src/reportkit/
โ”‚   โ”œโ”€โ”€ __init__.py          # Public API
โ”‚   โ”œโ”€โ”€ app.py               # Flask factory
โ”‚   โ”œโ”€โ”€ exceptions.py        # Custom exceptions
โ”‚   โ”œโ”€โ”€ api/                 # REST endpoints
โ”‚   โ”œโ”€โ”€ models/              # Data models
โ”‚   โ”œโ”€โ”€ parsers/             # HTML & chart parsers
โ”‚   โ”œโ”€โ”€ renderers/           # DOCX & PDF renderers
โ”‚   โ””โ”€โ”€ services/            # Conversion orchestration
โ”œโ”€โ”€ tests/                   # Test suite
โ”œโ”€โ”€ pyproject.toml           # Package configuration
โ””โ”€โ”€ README.md

License

MIT โ€” see LICENSE for details.

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

reportkit_py-0.1.1.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

reportkit_py-0.1.1-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file reportkit_py-0.1.1.tar.gz.

File metadata

  • Download URL: reportkit_py-0.1.1.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for reportkit_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d12e7092a9079b79995491f5acfd3c3d62f801ce6c189892b7bbab05a3254eff
MD5 f0c4d0a49d2607921e80c216df66251b
BLAKE2b-256 a7951ce1977821d3bca0b010865867ac6589866be176c8a6e92901fca250482b

See more details on using hashes here.

File details

Details for the file reportkit_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: reportkit_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for reportkit_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46f9981a544784467f144549ce6ec18c71327b62cacfb732217311cafffaf937
MD5 b300276fd8667f983391c392aaf6d0fc
BLAKE2b-256 6c00e8faa1257e94d4d2134d99769fbe01973d6cf5c0c2eea34890078f5be6ea

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