Metadata-Version: 2.5
Name: patrakit
Version: 0.1.1
Summary: Describe a report once in Python or JSON. Save it as Word, PDF, PowerPoint or Excel.
Project-URL: Homepage, https://github.com/bengalaiswaraj-sketch/patrakit
Project-URL: Documentation, https://github.com/bengalaiswaraj-sketch/patrakit#readme
Project-URL: Repository, https://github.com/bengalaiswaraj-sketch/patrakit
Project-URL: Issues, https://github.com/bengalaiswaraj-sketch/patrakit/issues
Project-URL: Changelog, https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/CHANGELOG.md
Author: patrakit contributors
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: chart,document,docx,excel,generation,pdf,powerpoint,pptx,report,word,xlsx
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: fonttools<5,>=4.40.0
Requires-Dist: matplotlib<4,>=3.8.0
Requires-Dist: openpyxl<4,>=3.1.0
Requires-Dist: pydantic<3,>=2.0
Requires-Dist: python-docx<2,>=1.1.0
Requires-Dist: python-pptx<2,>=1.0.0
Requires-Dist: pyyaml<7,>=6.0
Requires-Dist: typst<1,>=0.11.0
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: mypy>=1.8; extra == 'dev'
Requires-Dist: pypdf>=4.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Requires-Dist: twine>=5.0; extra == 'dev'
Provides-Extra: mcp
Requires-Dist: mcp<2,>=1.0; extra == 'mcp'
Provides-Extra: pandas
Requires-Dist: pandas<3,>=2.0; extra == 'pandas'
Description-Content-Type: text/markdown

# patrakit

**Describe a report once in Python or JSON. Save it as Word, PDF, PowerPoint or Excel.**

<!-- RELEASE CHECKLIST: remove the status note only after every command in this file
     has been tested against the package installed from PyPI. Replace bengalaiswaraj-sketch. -->

> **Status: pre-release.** This README is the specification for version 1.0.
> The package is not on PyPI yet, so the commands below do not work today.
> `patrakit` is a working name.

## Install

Python 3.11 or later.

```bash
pip install patrakit
```

For pandas DataFrames:

```bash
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`.

```python
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"):
    result = report.save(f"review.{extension}")
    print(result.path)
    for warning in result.warnings:
        print(f"  {warning.code}: {warning.message}")
```

You get four 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.

<!-- GALLERY RULES: no mock-ups and no hand-edited images. For each entry, replace the
     "Image pending" line with the commented image tag after the script has created it.
     Use absolute URLs so the images are not dependent on the page showing this file. -->

### PDF

<table>
<tr><th>Code</th><th>Real output</th></tr>
<tr>
<td>

```python
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")
```

</td>
<td>

<img alt="PDF page with a revenue figure and bar chart" width="420" src="https://raw.githubusercontent.com/bengalaiswaraj-sketch/patrakit/master/docs/pdf_sample.png">

</td>
</tr>
</table>

### Word

<table>
<tr><th>Code</th><th>Real output</th></tr>
<tr>
<td>

```python
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")
```

</td>
<td>

<img alt="Word page with a heading and bullet list" width="420" src="https://raw.githubusercontent.com/bengalaiswaraj-sketch/patrakit/master/docs/word_sample.png">

</td>
</tr>
</table>

### PowerPoint

<table>
<tr><th>Code</th><th>Real output</th></tr>
<tr>
<td>

```python
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")
```

</td>
<td>

<img alt="PowerPoint slide with an editable chart" width="420" src="https://raw.githubusercontent.com/bengalaiswaraj-sketch/patrakit/master/docs/ppt_sample.png">

</td>
</tr>
</table>

### Excel

<table>
<tr><th>Code</th><th>Real output</th></tr>
<tr>
<td>

```python
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")
```

</td>
<td>

<img alt="Excel sheet with KPIs and formatted data" width="420" src="https://raw.githubusercontent.com/bengalaiswaraj-sketch/patrakit/master/docs/excel_sample.png">

</td>
</tr>
</table>

## Five runnable examples

The examples are included in the package, so you do not need to clone the repository.

```bash
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.

[g1]: https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/guides/saas-monthly-review-powerpoint-pdf-python.md
[g2]: https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/guides/invoice-pdf-excel-python.md
[g3]: https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/guides/weekly-project-status-report-word-python.md
[g4]: https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/guides/pandas-dataframe-to-word-pdf-report.md
[g5]: https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/guides/llm-evaluation-report-pdf-excel-python.md

## 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.

```yaml
# 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"
```

```python
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:

```python
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.

```json
{
  "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}
      ]
    }
  ]
}
```

```bash
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.

## For AI agents

- JSON Schema: [`schema/report.schema.json`](https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/schema/report.schema.json)
- Agent guide: [`llms.txt`](https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/llms.txt)
- A small MCP server is planned for a later release.

A good agent workflow is: read the schema, create the JSON, run `patrakit validate`,
then run `patrakit render` and read the warnings.

## How each format behaves

| Format | Behaviour | Version 1 limits |
|---|---|---|
| Word | Flowing document with real heading, list and table styles | **Charts are images**, so you cannot edit their data in Word |
| PDF | Fixed pages | Accessibility and archival standards are not claimed |
| PowerPoint | Each level 1 heading starts a slide; long content continues on new slides; charts are editable | Check slides for fit before you present them |
| Excel | A summary sheet, plus sheets for tables and editable charts | Values only; no generated formulas |

patrakit creates new documents. It does not edit existing ones, accept HTML as input or
offer a visual designer.

## Privacy

The free package makes no network calls, calls no AI service and collects no usage data.
Your report stays on the machine that runs the code. Installing packages with `pip` uses
the network as usual.

## Free and Pro

patrakit Pro is **planned and not on sale yet**.

| Feature | Free | Pro (planned) |
|---|:---:|:---:|
| All content blocks and JSON Schema | ✓ | ✓ |
| Word, PDF, PowerPoint and Excel output | ✓ | ✓ |
| Three built-in themes and your own theme file | ✓ | ✓ |
| Choose fonts for each role | ✓ | ✓ |
| Premium report designs | | ✓ |
| Your own PDF and slide templates | | ✓ |
| Advanced PDF layouts: multi-column, dashboard, cover page | | ✓ |
| AI layout planner that uses your own LLM account | | ✓ |
| Your own Excel templates (after the first Pro release) | | ✓ |
| Bulk rendering (later) | | ✓ |

Features in the free column will stay free.

In Pro, you choose your LLM provider in one configuration file,
`patrakit.llm.yaml`: Gemini, OpenAI, or an endpoint compatible with the OpenAI Chat
Completions API, including a local one. The AI suggests a layout. It does not draw the
document or rewrite your values. In the free package, `layout="ai"` and `template=` raise
`FeatureNotAvailableError`.

[See the Pro page](https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/pro.md)
for sample files, proposed prices and draft terms.

## Help and contributing

- Report a bug or ask for a feature with a GitHub issue. Include a small example with
  made-up data. Never post API keys or private business data.
- Support for the free package is on a best-effort basis.
- Read `CONTRIBUTING.md` before you open a pull request. Report security problems as
  described in `SECURITY.md`.

## Licence

The free package uses the Apache License 2.0. See `LICENSE`. Libraries and bundled fonts
keep their own licences. See `THIRD_PARTY_NOTICES.md`. patrakit Pro will have a separate
commercial licence.
