A developer-first document generation engine with flow-based layout
Project description
ReportKit
A developer-first document generation engine with flow-based layout system for PDF and DOCX documents.
Features
- Flow-based Layout: Stream-based document layout (no absolute positioning)
- Dynamic Pagination: Automatic page breaks and content splitting
- JSON Templates: Declarative template system with v1 standard
- AI Design Importer: [NEW] Automatically generate templates from Figma screenshots
- Data Binding: Jinja2-style variable binding
- Multiple Formats: PDF, DOCX, and HTML output
- Plugin System: Extensible block architecture
- Production Ready: Pip-installable Python package
- Visual Designer: Professional drafting tool for creating templates
Quick Start
Installation
pip install reportkit
To enable AI-powered design importing:
pip install "reportkit[ai]"
AI Setup (Bring Your Own Key): The AI importer requires a Google AI API key.
- Get a free API key from Google AI Studio.
- Set it as an environment variable (
GOOGLE_API_KEY) or in a.envfile in your project root:
GOOGLE_API_KEY=your_key_here
Note: The AI Design Importer (Phase A) currently requires the designer to be run locally as it utilizes a local AI server for the BYOK (Bring Your Own Key) method.
For PDF rendering, also install Playwright:
pip install playwright
playwright install chromium
For DOCX rendering, install docxtpl:
pip install docxtpl
ReportKit Designer
Create templates visually using our professional drafting tool.
- Live Demo: report-builder-designer.vercel.app
- Source Code: github.com/uju11/report-builder-designer
The designer features a Photoshop-like environment with millimeter-precision rulers, a grid system, and real-time multi-column pagination preview.
Basic Usage
from reportkit import ReportEngine
# Create engine
engine = ReportEngine()
# Register template
engine.register_template("sales_report", "templates/sales.json")
# Render report
report = engine.render(
"sales_report",
data={
"client": {"name": "ABC Corporation"},
"sales": [
{"product": "Widget A", "amount": 1500},
{"product": "Widget B", "amount": 2300},
],
"total": 3800
}
)
# Export to different formats
report.to_pdf("sales_report.pdf")
report.to_docx("sales_report.docx")
report.to_html("sales_report.html")
Template System
ReportKit uses JSON-based templates with a flow-based layout system:
{
"version": "1.0",
"name": "Sales Report",
"page_config": {
"size": "A4",
"orientation": "portrait",
"margins": {
"top": 72,
"right": 72,
"bottom": 72,
"left": 72
}
},
"groups": [
{
"id": "header",
"flow": "block",
"page_behavior": "keep_together",
"blocks": [
{
"type": "text",
"data": {
"content": "Sales Report for {{client.name}}"
},
"style": {
"font_size": 18,
"font_weight": "bold",
"alignment": "center"
}
}
]
},
{
"id": "content",
"flow": "block",
"page_behavior": "can_split",
"blocks": [
{
"type": "table",
"data": {
"headers": ["Product", "Amount"],
"data": "{{sales}}"
}
},
{
"type": "text",
"data": {
"content": "Total: ${{total}}"
},
"style": {
"font_weight": "bold"
}
}
]
}
]
}
Block Types
Text Block
{
"type": "text",
"data": {
"content": "Hello {{name}}!"
},
"style": {
"font_family": "Arial",
"font_size": 12,
"color": "#000000",
"alignment": "left"
}
}
Image Block
{
"type": "image",
"data": {
"source": "logo.png",
"width": 200,
"height": 100,
"alt_text": "Company Logo"
}
}
Table Block
{
"type": "table",
"data": {
"headers": ["Name", "Age", "City"],
"data": [
["John", 30, "New York"],
["Jane", 25, "Boston"]
]
},
"options": {
"show_headers": true,
"border": true,
"striped": false
}
}
Chart Block
{
"type": "chart",
"data": {
"chart_type": "bar",
"title": "Sales by Month",
"labels": ["Jan", "Feb", "Mar"],
"datasets": [
{
"label": "Sales",
"data": [1000, 1500, 1200],
"color": "#007bff"
}
]
},
"options": {
"width": 400,
"height": 300,
"legend": true
}
}
Page Behavior
Groups can have different page break behaviors:
normal_flow: Default flow behaviorkeep_together: Group stays on same pagecan_split: Group can split across pagesstart_new_page: Group always starts on new page
Custom Blocks
Create custom block types by extending BaseBlock:
from reportkit.blocks import BaseBlock, BlockContext
class CustomBlock(BaseBlock):
type = "custom"
def validate(self, data):
# Validate block data
pass
def render(self, data, context: BlockContext):
# Render block to intermediate format
return {
"type": "custom",
"content": "...",
"style": {}
}
# Register custom block
engine.register_block(CustomBlock)
Development
Setup
git clone https://github.com/uju11/reportkit
cd reportkit
pip install -e ".[dev]"
Running Tests
pytest
Code Formatting
black reportkit
isort reportkit
Architecture
ReportKit follows a clear rendering pipeline:
- Template Parsing → Validate JSON template
- Data Binding → Resolve variables with Jinja2-style binding
- Layout Resolution → Create flow-based document tree
- Pagination → Handle page breaks and content splitting
- Rendering → Convert to HTML, then PDF/DOCX
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Support
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-0.1.2.tar.gz.
File metadata
- Download URL: reportkit-0.1.2.tar.gz
- Upload date:
- Size: 43.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
160651c99cfddcc5957fa78d12b345eb903731f8b411d2595f0d1fe49e3cb2e8
|
|
| MD5 |
745ed50bc71ea0bef86ff14cb01dddd6
|
|
| BLAKE2b-256 |
f92ffbeef4b1ade81ccda655a1010896f7223939d924c39ce6b02e0c5360d9f0
|
File details
Details for the file reportkit-0.1.2-py3-none-any.whl.
File metadata
- Download URL: reportkit-0.1.2-py3-none-any.whl
- Upload date:
- Size: 52.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11cd2554b161e4a95e406a28d8233fa9723ab7f796b200fb05d493d262ebf295
|
|
| MD5 |
4612fdc282657f394e0a00f31a639f9c
|
|
| BLAKE2b-256 |
83ee5a9ebf7438455ba206369b7214130f3380ad521557a650a70ed914dc8dc2
|