Skip to main content

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

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.

  1. Get a free API key from Google AI Studio.
  2. Set it as an environment variable (GOOGLE_API_KEY) or in a .env file in your project root:
GOOGLE_API_KEY=your_key_here

For PDF rendering, also install Playwright:

pip install playwright
playwright install chromium

For DOCX rendering, install docxtpl:

pip install docxtpl

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 behavior
  • keep_together: Group stays on same page
  • can_split: Group can split across pages
  • start_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/reportkit/reportkit
cd reportkit
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

black reportkit
isort reportkit

Architecture

ReportKit follows a clear rendering pipeline:

  1. Template Parsing → Validate JSON template
  2. Data Binding → Resolve variables with Jinja2-style binding
  3. Layout Resolution → Create flow-based document tree
  4. Pagination → Handle page breaks and content splitting
  5. Rendering → Convert to HTML, then PDF/DOCX

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Support

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-0.1.0.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

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

reportkit-0.1.0-py3-none-any.whl (52.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reportkit-0.1.0.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for reportkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d1c365f0f9d4a5436aad0ef82bd822f9d0a369645ff1d2ad7eb8eedff4c0e516
MD5 6ce7c5f240dcc1cdb0ee104d680b400f
BLAKE2b-256 677caf0641a2f89451a4b98f11ddf26a28973cf976aa910320c941bf34009b9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: reportkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 52.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for reportkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6553fde2110e00dddf31d9ac5f4ae9e689defbbb20c186af7fadc4f3cd9f406a
MD5 2353255fd880ec4dffbd8f3c9e8f4265
BLAKE2b-256 cc20bf63e6edf43502f26570f3af0f9d779b3abd668487ae51b18e15f3971894

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