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.0.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.0-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reportkit_py-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 83d14c981c7333a19181cbebd9db9a4539ea7aa884f78da9d5fbc482f7c9811e
MD5 29dffb50227f1e9493de020e5d9087ae
BLAKE2b-256 c3625f39a57ed1febff686b307abc841776f243557594e70e0f3a806d9ec849f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reportkit_py-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a77bebbbff6bc1317e01a414138edf6f52b87dc2eeb72f9c1e88a7796b979c4
MD5 d0931c4f960a7e57b488fc4abdec12fb
BLAKE2b-256 70ac0435ecfac353220f8ae8ce916f79ab118ea9326ae31885ae441a55d27da7

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