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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d12e7092a9079b79995491f5acfd3c3d62f801ce6c189892b7bbab05a3254eff
|
|
| MD5 |
f0c4d0a49d2607921e80c216df66251b
|
|
| BLAKE2b-256 |
a7951ce1977821d3bca0b010865867ac6589866be176c8a6e92901fca250482b
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46f9981a544784467f144549ce6ec18c71327b62cacfb732217311cafffaf937
|
|
| MD5 |
b300276fd8667f983391c392aaf6d0fc
|
|
| BLAKE2b-256 |
6c00e8faa1257e94d4d2134d99769fbe01973d6cf5c0c2eea34890078f5be6ea
|