patrakit

Describe a report once in Python, JSON, or Markdown. Save it as Word, PDF, PowerPoint, Excel, or HTML.
Install
Python 3.11 or later.
pip install patrakit
For pandas DataFrames:
pip install "patrakit[pandas]"
PDF output uses Typst through its Python package. You do not need Microsoft Office,
LibreOffice or a web browser to create files.
Quickstart
Save this as quickstart.py and run python quickstart.py.
from patrakit import Report, Heading, Text, KPIRow, Table, Chart
sales = [
{"region": "North", "revenue": 1250000, "growth": 0.12},
{"region": "South", "revenue": 980000, "growth": 0.07},
{"region": "East", "revenue": 1120000, "growth": 0.09},
{"region": "West", "revenue": 850000, "growth": -0.03},
]
report = Report(
title="Quarterly Sales Review",
subtitle="Synthetic demo data",
theme="modern",
blocks=[
Heading("Summary"),
Text("Revenue grew in three of four regions."),
KPIRow({"Revenue": "$4.2M", "New accounts": 128}),
Heading("Revenue by region", level=2),
Chart.bar(
sales,
x="region",
y="revenue",
title="Revenue by region",
alt_text="Bar chart comparing revenue in four regions",
),
Table(sales, formats={"revenue": "currency:USD", "growth": "percent:1"}),
],
)
for extension in ("docx", "pdf", "pptx", "xlsx", "html"):
result = report.save(f"review.{extension}")
print(result.path)
for warning in result.warnings:
print(f" {warning.code}: {warning.message}")
You get five files from one report definition. Each format follows its own layout rules,
so the files share content and style but do not look identical.
Gallery
Each image must come from the code beside it. scripts/build_gallery.py runs the files in
gallery/snippets/ and creates the images. All data is synthetic.
Word, PowerPoint and Excel pages are rendered for these images with LibreOffice.
They can look slightly different in Microsoft Office.
PDF
from patrakit import Report, KPIRow, Chart
sales = [
{"region": "North", "revenue": 1250000},
{"region": "South", "revenue": 980000},
]
Report(
title="Sales Review",
blocks=[
KPIRow({"Revenue": "$2.23M"}),
Chart.bar(sales, x="region",
y="revenue"),
],
).save("sales.pdf")
Word
from patrakit import (
Report, Heading, BulletList)
Report(
title="Weekly Status",
blocks=[
Heading("Done this week"),
BulletList([
"Login flow shipped",
"12 bugs closed",
]),
],
).save("status.docx")
PowerPoint
from patrakit import Report, Heading, Chart
mrr = [
{"month": "Sep", "mrr": 41000},
{"month": "Oct", "mrr": 44500},
{"month": "Nov", "mrr": 47200},
]
Report(
title="SaaS Monthly Review",
blocks=[
Heading("MRR trend"),
Chart.line(mrr, x="month", y="mrr"),
],
).save("saas.pptx")
Excel
from patrakit import Report, Heading, Table
runs = [
{"model": "model-a", "pass_rate": 0.91},
{"model": "model-b", "pass_rate": 0.87},
]
Report(
title="Evaluation Results",
blocks=[
Heading("Pass rate"),
Table(runs, formats={
"pass_rate": "percent:1"}),
],
).save("evals.xlsx")
Template gallery
Ready-to-use templates you can download and run. Each generates real output files from
synthetic data.
patrakit templates list
patrakit templates download sales-report ./demo
python ./demo/annual_sales_report.py
| Template |
Category |
Formats |
Download |
| Academic Performance Report |
Education |
PDF, Word |
patrakit templates download academic-performance |
| Weekly Project Status Report |
Business |
PDF, Word |
patrakit templates download project-status-report |
| Six Years Financial Report |
Finance |
PDF, Excel |
patrakit templates download financial-report |
| Commercial Invoice |
Business |
PDF, Excel |
patrakit templates download commercial-invoice |
| Annual Sales Report |
Business |
PDF, PowerPoint |
patrakit templates download sales-report |
You can also search templates by keyword:
patrakit templates search invoice
patrakit templates list --category finance
All templates use made-up data and need no API key.
Five runnable examples
The examples are included in the package, so you do not need to clone the repository.
patrakit examples list
patrakit examples copy invoice ./demo
python ./demo/invoice.py
| Name |
Script |
Creates |
Needs |
Guide |
saas-monthly-review |
saas_monthly_review.py |
PowerPoint, PDF |
patrakit |
[Create a SaaS monthly review in PowerPoint and PDF with Python][g1] |
invoice |
invoice.py |
PDF, Excel |
patrakit |
[Generate an invoice PDF and Excel file in Python][g2] |
project-status |
project_status.py |
Word, PDF |
patrakit |
[Automate a weekly project status report in Word with Python][g3] |
analytics |
analytics_report.py |
Word, PDF |
patrakit[pandas] |
[Pandas DataFrame to a Word and PDF report][g4] |
ai-evaluation |
ai_evaluation_report.py |
PDF, Excel |
patrakit |
[Turn LLM evaluation results into a PDF and Excel report in Python][g5] |
All examples use made-up data and need no API key. The invoice is a layout example. It does
not claim to meet the tax or legal invoice rules of any country.
What is free
Every feature in this section is in the free package. There are no watermarks, page limits,
accounts or licence keys.
Content blocks
| Block |
Example |
| Heading, levels 1 to 3 |
Heading("Summary", level=1) |
| Text; a blank line starts a new paragraph |
Text("Revenue grew.") |
| Bullet list |
BulletList(["One", "Two"]) |
| KPI row |
KPIRow({"Revenue": "$4.2M"}) |
| Table |
Table(rows, formats={"amount": "currency:INR"}) |
| Bar, line and pie charts |
Chart.bar(rows, x="month", y="sales") |
| Image |
Image("logo.png", alt_text="Company logo", width=0.4) |
| Page or slide break |
Break() |
Tables and charts accept a list of dictionaries. With the pandas extra, they also accept
a DataFrame. Image width is a share of the content width, from 0 to 1.
Value formats
| Format |
Input |
Shown as |
text |
North |
North |
integer |
1250000 |
1,250,000 |
number:2 |
3.14159 |
3.14 |
percent:1 |
0.12 |
12.0% |
currency:USD |
1250000 |
$1,250,000.00 |
currency:INR |
1250000 |
₹12,50,000.00 |
date |
datetime.date(2026, 11, 29) |
29 Nov 2026 |
patrakit formats values. It does not convert currencies or calculate totals.
Themes
Three themes are built in: classic, modern and minimal. You can also load your own
theme file.
# acme.yaml
base: modern
fonts:
heading: Montserrat
body: Source Sans 3
table: Source Sans 3
code: JetBrains Mono
fallback: [Noto Sans]
font_dirs: [./fonts]
colors:
primary: "#1F4E79"
accent: "#C55A11"
text: "#1F2328"
logo: assets/logo.png
header: "Acme Pvt Ltd"
footer: "Confidential"
from patrakit import Report, Text, Theme
report = Report(
title="Board Update",
theme=Theme.load("acme.yaml"),
blocks=[Text("All milestones are on track.")],
)
report.save("update.pdf")
Paths in a theme file are relative to that file. The code font role is reserved because
version 1 has no code block.
Custom fonts
Set one font family for everything, or set each role:
from patrakit import Report, Text, Theme, Fonts
theme = Theme(base="classic", fonts=Fonts(family="Noto Sans", font_dirs=["./fonts"]))
report = Report(title="Notes", theme=theme, blocks=[Text("Hello")])
report.save("notes.pdf", strict_fonts=True)
- Fonts come from your computer or your
font_dirs. patrakit does not download fonts.
- A missing font produces a warning and uses a fallback. With
strict_fonts=True,
saving fails instead.
- Word, PowerPoint and Excel files store font names, not the fonts. The reader's
computer needs the same fonts. Use
Fonts.office_safe() when you share these files.
PDF creation may need those fonts on your own computer too.
- Built-in themes use Office-safe names in Office files and bundled open fonts in PDF.
A font that you choose applies to all four formats.
- Support for a writing system is claimed only after it is tested. Check your output.
- You are responsible for the licences of fonts you add.
Run patrakit fonts to list the font families that patrakit can find.
JSON input and command line
You can describe the same report in JSON. This is useful for other programming languages
and AI agents.
{
"schema_version": "1.0",
"title": "Quarterly Sales Review",
"theme": "modern",
"blocks": [
{"type": "heading", "level": 1, "text": "Summary"},
{"type": "text", "text": "Revenue grew in three of four regions."},
{"type": "kpi_row", "items": [{"label": "Revenue", "value": "$4.2M"}]},
{"type": "bullet_list", "items": ["North grew 12%", "West fell 3%"]},
{
"type": "chart",
"chart_type": "bar",
"title": "Revenue by region",
"alt_text": "Bar chart comparing revenue in four regions",
"categories": ["North", "South", "East", "West"],
"series": [{"name": "Revenue", "values": [1250000, 980000, 1120000, 850000]}]
},
{
"type": "table",
"columns": [
{"key": "region", "label": "Region", "format": "text"},
{"key": "revenue", "label": "Revenue", "format": "currency:USD"}
],
"rows": [
{"region": "North", "revenue": 1250000},
{"region": "South", "revenue": 980000}
]
}
]
}
patrakit validate report.json
patrakit render report.json -o report.pdf
patrakit render report.json -o report.pptx --theme acme.yaml --strict-fonts
patrakit schema -o report.schema.json
From Python, use Report.from_file("report.json") for a file, or Report.from_json(data)
for a JSON string or dictionary.
Image paths must stay inside the report's asset folder. For a JSON file, that is the
folder that contains it. patrakit does not load images from web addresses.
HTML output
patrakit also renders to self-contained HTML files — useful for email, web previews,
chatbot responses, and Streamlit/Gradio apps.
report.save("review.html")
The HTML file is a single file with inline CSS, embedded chart SVGs, and base64 images.
It is responsive, prints cleanly, and needs no external resources.
Markdown input
LLMs generate Markdown naturally. patrakit accepts it directly:
from patrakit import Report
md = """
# Monthly Report
Revenue grew 9% year over year.
| Region | Revenue | Growth |
|--------|---------|--------|
| North | $1.25M | 12% |
| South | $980K | 7% |
- Launched mobile app
- Closed 128 accounts
"""
report = Report.from_markdown(md)
report.save("report.pdf")
report.save("report.docx")
Headings, paragraphs, bullet lists, tables, images, and horizontal rules are all
converted to patrakit blocks. Markdown files (.md) are also accepted by
Report.from_file() and the CLI.
Natural-language report generation
Generate a report from a plain-English description using your own LLM account:
from patrakit import Report
report = Report.from_prompt(
"Create a quarterly sales report with revenue $4.2M across 4 regions, "
"include a bar chart and summary table",
provider="openai", # or "anthropic", "google"
)
report.save("sales.pdf")
Set your API key via environment variable (OPENAI_API_KEY, ANTHROPIC_API_KEY,
or GOOGLE_API_KEY) or pass api_key= explicitly. The LLM generates valid patrakit
JSON; patrakit validates and auto-retries once if the output is invalid.
pip install "patrakit[ai-openai]" # for OpenAI
pip install "patrakit[ai-anthropic]" # for Anthropic
pip install "patrakit[ai-google]" # for Google
pip install "patrakit[ai]" # all three
patrakit sends your prompt to the LLM provider you choose. It never sends your
report data to any service.
ReportBuilder — incremental construction
Build reports block by block, useful for streaming LLM output or step-by-step
construction:
from patrakit import ReportBuilder, Heading, Text, KPIRow
builder = ReportBuilder(title="Q4 Review", theme="modern")
builder.add(Heading("Summary"))
builder.add(Text("Revenue grew 9% year over year."))
builder.add(KPIRow({"Revenue": "$4.2M"}))
# Validate at any point
errors = builder.validate()
# Save when done
builder.save("report.pdf")
MCP server (Model Context Protocol)
patrakit includes an MCP server so any MCP-compatible AI agent (Claude, Cursor,
Windsurf, Cline, etc.) can generate documents as a tool call — no code generation
needed.
pip install "patrakit[mcp]"
patrakit mcp-server
Add to your MCP client configuration:
{
"mcpServers": {
"patrakit": {
"command": "patrakit",
"args": ["mcp-server"]
}
}
}
The server exposes five tools: