patrakit 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- patrakit/__init__.py +417 -0
- patrakit/charts/__init__.py +144 -0
- patrakit/cli.py +189 -0
- patrakit/errors.py +88 -0
- patrakit/examples/__init__.py +1 -0
- patrakit/examples/ai_evaluation_report.py +74 -0
- patrakit/examples/analytics_report.py +86 -0
- patrakit/examples/invoice.py +60 -0
- patrakit/examples/project_status.py +59 -0
- patrakit/examples/saas_monthly_review.py +74 -0
- patrakit/fonts/__init__.py +110 -0
- patrakit/formats.py +169 -0
- patrakit/model/__init__.py +34 -0
- patrakit/model/blocks.py +122 -0
- patrakit/model/report.py +48 -0
- patrakit/plugins.py +77 -0
- patrakit/py.typed +0 -0
- patrakit/renderers/__init__.py +40 -0
- patrakit/renderers/docx.py +273 -0
- patrakit/renderers/pdf.py +218 -0
- patrakit/renderers/pptx.py +270 -0
- patrakit/renderers/typst/report.typ +143 -0
- patrakit/renderers/xlsx.py +259 -0
- patrakit/schema.py +35 -0
- patrakit/security.py +116 -0
- patrakit/theme/__init__.py +211 -0
- patrakit-0.1.0.dist-info/METADATA +510 -0
- patrakit-0.1.0.dist-info/RECORD +31 -0
- patrakit-0.1.0.dist-info/WHEEL +4 -0
- patrakit-0.1.0.dist-info/entry_points.txt +2 -0
- patrakit-0.1.0.dist-info/licenses/LICENSE +190 -0
patrakit/cli.py
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Command-line interface for patrakit."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import shutil
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from patrakit.errors import PatrakitError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(argv: list[str] | None = None) -> int:
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="patrakit",
|
|
16
|
+
description="Describe a report once. Save it as Word, PDF, PowerPoint or Excel.",
|
|
17
|
+
)
|
|
18
|
+
sub = parser.add_subparsers(dest="command")
|
|
19
|
+
|
|
20
|
+
p_render = sub.add_parser("render", help="Render a report from JSON")
|
|
21
|
+
p_render.add_argument("input", help="Input JSON file")
|
|
22
|
+
p_render.add_argument("-o", "--output", required=True, help="Output file path")
|
|
23
|
+
p_render.add_argument("--theme", help="Theme name or YAML file path")
|
|
24
|
+
p_render.add_argument("--strict-fonts", action="store_true", help="Fail on missing fonts")
|
|
25
|
+
|
|
26
|
+
p_validate = sub.add_parser("validate", help="Validate a JSON report")
|
|
27
|
+
p_validate.add_argument("input", help="Input JSON file")
|
|
28
|
+
|
|
29
|
+
p_schema = sub.add_parser("schema", help="Export JSON Schema")
|
|
30
|
+
p_schema.add_argument("-o", "--output", help="Output file path (default: stdout)")
|
|
31
|
+
|
|
32
|
+
p_fonts = sub.add_parser("fonts", help="List available fonts")
|
|
33
|
+
p_fonts.add_argument("--font-dir", action="append", dest="font_dirs", help="Additional font directory")
|
|
34
|
+
|
|
35
|
+
p_examples = sub.add_parser("examples", help="List or copy examples")
|
|
36
|
+
ex_sub = p_examples.add_subparsers(dest="examples_command")
|
|
37
|
+
ex_sub.add_parser("list", help="List available examples")
|
|
38
|
+
p_copy = ex_sub.add_parser("copy", help="Copy an example to a directory")
|
|
39
|
+
p_copy.add_argument("name", help="Example name")
|
|
40
|
+
p_copy.add_argument("dest", help="Destination directory")
|
|
41
|
+
|
|
42
|
+
args = parser.parse_args(argv)
|
|
43
|
+
|
|
44
|
+
if args.command is None:
|
|
45
|
+
parser.print_help()
|
|
46
|
+
return 2
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
if args.command == "render":
|
|
50
|
+
return _cmd_render(args)
|
|
51
|
+
elif args.command == "validate":
|
|
52
|
+
return _cmd_validate(args)
|
|
53
|
+
elif args.command == "schema":
|
|
54
|
+
return _cmd_schema(args)
|
|
55
|
+
elif args.command == "fonts":
|
|
56
|
+
return _cmd_fonts(args)
|
|
57
|
+
elif args.command == "examples":
|
|
58
|
+
return _cmd_examples(args)
|
|
59
|
+
except PatrakitError as e:
|
|
60
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
61
|
+
return 1
|
|
62
|
+
except Exception as e:
|
|
63
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
64
|
+
return 1
|
|
65
|
+
|
|
66
|
+
return 0
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _cmd_render(args: argparse.Namespace) -> int:
|
|
70
|
+
from patrakit import Report, Theme
|
|
71
|
+
|
|
72
|
+
input_path = Path(args.input)
|
|
73
|
+
if not input_path.exists():
|
|
74
|
+
print(f"Error: File not found: {input_path}", file=sys.stderr)
|
|
75
|
+
return 2
|
|
76
|
+
|
|
77
|
+
report = Report.from_file(input_path)
|
|
78
|
+
|
|
79
|
+
kwargs: dict = {}
|
|
80
|
+
if args.theme:
|
|
81
|
+
theme_path = Path(args.theme)
|
|
82
|
+
if theme_path.exists():
|
|
83
|
+
kwargs["strict_fonts"] = args.strict_fonts
|
|
84
|
+
report._theme_input = Theme.load(args.theme)
|
|
85
|
+
else:
|
|
86
|
+
report._theme_input = args.theme
|
|
87
|
+
|
|
88
|
+
if args.strict_fonts:
|
|
89
|
+
kwargs["strict_fonts"] = True
|
|
90
|
+
|
|
91
|
+
result = report.save(args.output, **kwargs)
|
|
92
|
+
print(result.path)
|
|
93
|
+
for w in result.warnings:
|
|
94
|
+
print(f" {w.code}: {w.message}", file=sys.stderr)
|
|
95
|
+
return 0
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _cmd_validate(args: argparse.Namespace) -> int:
|
|
99
|
+
from patrakit import Report
|
|
100
|
+
|
|
101
|
+
input_path = Path(args.input)
|
|
102
|
+
if not input_path.exists():
|
|
103
|
+
print(f"Error: File not found: {input_path}", file=sys.stderr)
|
|
104
|
+
return 2
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
Report.from_file(input_path)
|
|
108
|
+
print(f"Valid: {input_path}")
|
|
109
|
+
return 0
|
|
110
|
+
except PatrakitError as e:
|
|
111
|
+
print(f"Invalid: {e}", file=sys.stderr)
|
|
112
|
+
return 2
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _cmd_schema(args: argparse.Namespace) -> int:
|
|
116
|
+
from patrakit.schema import generate_schema
|
|
117
|
+
import json
|
|
118
|
+
|
|
119
|
+
schema = generate_schema()
|
|
120
|
+
text = json.dumps(schema, indent=2, ensure_ascii=False) + "\n"
|
|
121
|
+
|
|
122
|
+
if args.output:
|
|
123
|
+
Path(args.output).parent.mkdir(parents=True, exist_ok=True)
|
|
124
|
+
Path(args.output).write_text(text, encoding="utf-8")
|
|
125
|
+
print(f"Schema written to {args.output}")
|
|
126
|
+
else:
|
|
127
|
+
print(text)
|
|
128
|
+
return 0
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _cmd_fonts(args: argparse.Namespace) -> int:
|
|
132
|
+
from patrakit.fonts import list_available_fonts
|
|
133
|
+
|
|
134
|
+
fonts = list_available_fonts(args.font_dirs)
|
|
135
|
+
if fonts:
|
|
136
|
+
for f in fonts:
|
|
137
|
+
print(f)
|
|
138
|
+
else:
|
|
139
|
+
print("No fonts found.")
|
|
140
|
+
return 0
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
_EXAMPLES = {
|
|
144
|
+
"saas-monthly-review": "saas_monthly_review.py",
|
|
145
|
+
"invoice": "invoice.py",
|
|
146
|
+
"project-status": "project_status.py",
|
|
147
|
+
"analytics": "analytics_report.py",
|
|
148
|
+
"ai-evaluation": "ai_evaluation_report.py",
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _cmd_examples(args: argparse.Namespace) -> int:
|
|
153
|
+
if args.examples_command == "list":
|
|
154
|
+
print("Available examples:")
|
|
155
|
+
for name, script in _EXAMPLES.items():
|
|
156
|
+
print(f" {name:25s} {script}")
|
|
157
|
+
return 0
|
|
158
|
+
|
|
159
|
+
elif args.examples_command == "copy":
|
|
160
|
+
name = args.name
|
|
161
|
+
if name not in _EXAMPLES:
|
|
162
|
+
print(f"Error: Unknown example '{name}'. Run 'patrakit examples list'.", file=sys.stderr)
|
|
163
|
+
return 2
|
|
164
|
+
|
|
165
|
+
script = _EXAMPLES[name]
|
|
166
|
+
src = Path(__file__).parent / "examples" / script
|
|
167
|
+
if not src.exists():
|
|
168
|
+
print(f"Error: Example file not found: {src}", file=sys.stderr)
|
|
169
|
+
return 1
|
|
170
|
+
|
|
171
|
+
dest_dir = Path(args.dest)
|
|
172
|
+
dest_dir.mkdir(parents=True, exist_ok=True)
|
|
173
|
+
dest = dest_dir / script
|
|
174
|
+
|
|
175
|
+
if dest.exists():
|
|
176
|
+
print(f"Error: File already exists: {dest}", file=sys.stderr)
|
|
177
|
+
return 1
|
|
178
|
+
|
|
179
|
+
shutil.copy2(src, dest)
|
|
180
|
+
print(f"Copied to {dest}")
|
|
181
|
+
return 0
|
|
182
|
+
|
|
183
|
+
else:
|
|
184
|
+
print("Usage: patrakit examples list | patrakit examples copy NAME DIR", file=sys.stderr)
|
|
185
|
+
return 2
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
if __name__ == "__main__":
|
|
189
|
+
sys.exit(main())
|
patrakit/errors.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Exceptions and warnings for patrakit."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PatrakitError(Exception):
|
|
9
|
+
"""Base exception for all patrakit errors."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ReportValidationError(PatrakitError):
|
|
13
|
+
"""Raised when a report definition is invalid."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, message: str, block_id: str | None = None, field: str | None = None):
|
|
16
|
+
parts = []
|
|
17
|
+
if block_id:
|
|
18
|
+
parts.append(f"block {block_id}")
|
|
19
|
+
if field:
|
|
20
|
+
parts.append(f"field '{field}'")
|
|
21
|
+
prefix = f"[{', '.join(parts)}] " if parts else ""
|
|
22
|
+
super().__init__(f"{prefix}{message}")
|
|
23
|
+
self.block_id = block_id
|
|
24
|
+
self.field = field
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FontNotFoundError(PatrakitError):
|
|
28
|
+
"""Raised when a required font cannot be found and strict_fonts is True."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, font_name: str, search_paths: list[str] | None = None):
|
|
31
|
+
msg = f"Font '{font_name}' not found."
|
|
32
|
+
if search_paths:
|
|
33
|
+
msg += f" Searched: {', '.join(search_paths)}"
|
|
34
|
+
msg += " Install the font or add its directory to font_dirs."
|
|
35
|
+
super().__init__(msg)
|
|
36
|
+
self.font_name = font_name
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AssetError(PatrakitError):
|
|
40
|
+
"""Raised when an image or asset cannot be loaded or is outside asset_root."""
|
|
41
|
+
|
|
42
|
+
def __init__(self, message: str, path: str | None = None):
|
|
43
|
+
prefix = f"[{path}] " if path else ""
|
|
44
|
+
super().__init__(f"{prefix}{message}")
|
|
45
|
+
self.asset_path = path
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class RenderError(PatrakitError):
|
|
49
|
+
"""Raised when rendering fails."""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class FeatureNotAvailableError(PatrakitError):
|
|
53
|
+
"""Raised when a Pro-only feature is used without Pro installed."""
|
|
54
|
+
|
|
55
|
+
def __init__(self, feature: str):
|
|
56
|
+
super().__init__(
|
|
57
|
+
f"'{feature}' is available in patrakit Pro. "
|
|
58
|
+
"See https://github.com/bengalaiswaraj-sketch/patrakit/blob/main/docs/pro.md"
|
|
59
|
+
)
|
|
60
|
+
self.feature = feature
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True)
|
|
64
|
+
class RenderWarning:
|
|
65
|
+
"""A non-fatal warning produced during rendering."""
|
|
66
|
+
|
|
67
|
+
code: str
|
|
68
|
+
message: str
|
|
69
|
+
block_id: str | None = None
|
|
70
|
+
|
|
71
|
+
FONT_FALLBACK = "FONT_FALLBACK"
|
|
72
|
+
TEXT_SPLIT = "TEXT_SPLIT"
|
|
73
|
+
TABLE_SPLIT = "TABLE_SPLIT"
|
|
74
|
+
CONTENT_OVERFLOW = "CONTENT_OVERFLOW"
|
|
75
|
+
ALT_TEXT_MISSING = "ALT_TEXT_MISSING"
|
|
76
|
+
SHEET_NAME_CHANGED = "SHEET_NAME_CHANGED"
|
|
77
|
+
AI_LAYOUT_FALLBACK = "AI_LAYOUT_FALLBACK"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass(frozen=True)
|
|
81
|
+
class RenderResult:
|
|
82
|
+
"""Result of a render operation."""
|
|
83
|
+
|
|
84
|
+
path: "pathlib.Path"
|
|
85
|
+
warnings: list[RenderWarning]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
import pathlib # noqa: E402 — needed for RenderResult type annotation
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Runnable example scripts shipped in the patrakit wheel."""
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""AI evaluation report — PDF and Excel with synthetic data.
|
|
2
|
+
|
|
3
|
+
The model names and scores are made up. They do not represent
|
|
4
|
+
real model performance.
|
|
5
|
+
|
|
6
|
+
Run:
|
|
7
|
+
python ai_evaluation_report.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from patrakit import Report, Heading, Text, KPIRow, Table, Chart
|
|
11
|
+
|
|
12
|
+
eval_results = [
|
|
13
|
+
{"model": "model-a", "pass_rate": 0.91, "avg_latency_ms": 320, "cost_per_1k": 0.45, "failures": 18},
|
|
14
|
+
{"model": "model-b", "pass_rate": 0.87, "avg_latency_ms": 180, "cost_per_1k": 0.12, "failures": 26},
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
failure_types = [
|
|
18
|
+
{"type": "Format error", "model_a": 8, "model_b": 12},
|
|
19
|
+
{"type": "Wrong answer", "model_a": 5, "model_b": 7},
|
|
20
|
+
{"type": "Timeout", "model_a": 3, "model_b": 4},
|
|
21
|
+
{"type": "Refusal", "model_a": 2, "model_b": 3},
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
report = Report(
|
|
25
|
+
title="AI Model Evaluation Report",
|
|
26
|
+
subtitle="Synthetic data — model names and scores are made up",
|
|
27
|
+
theme="modern",
|
|
28
|
+
blocks=[
|
|
29
|
+
Heading("Summary"),
|
|
30
|
+
Text(
|
|
31
|
+
"Two models were evaluated on a synthetic benchmark of 200 prompts. "
|
|
32
|
+
"These are made-up results for demonstration purposes."
|
|
33
|
+
),
|
|
34
|
+
KPIRow({
|
|
35
|
+
"Models tested": "2",
|
|
36
|
+
"Total prompts": "200",
|
|
37
|
+
"Best pass rate": "91%",
|
|
38
|
+
}),
|
|
39
|
+
Heading("Results comparison"),
|
|
40
|
+
Table(
|
|
41
|
+
eval_results,
|
|
42
|
+
formats={
|
|
43
|
+
"pass_rate": "percent:1",
|
|
44
|
+
"avg_latency_ms": "integer",
|
|
45
|
+
"cost_per_1k": "currency:USD",
|
|
46
|
+
"failures": "integer",
|
|
47
|
+
},
|
|
48
|
+
),
|
|
49
|
+
Heading("Pass rate comparison"),
|
|
50
|
+
Chart.bar(
|
|
51
|
+
eval_results,
|
|
52
|
+
x="model",
|
|
53
|
+
y="pass_rate",
|
|
54
|
+
title="Pass rate by model",
|
|
55
|
+
alt_text="Bar chart comparing pass rates: model-a 91%, model-b 87%",
|
|
56
|
+
),
|
|
57
|
+
Heading("Failure type breakdown"),
|
|
58
|
+
Chart.bar(
|
|
59
|
+
failure_types,
|
|
60
|
+
x="type",
|
|
61
|
+
y=["model_a", "model_b"],
|
|
62
|
+
title="Failures by type and model",
|
|
63
|
+
alt_text="Grouped bar chart showing failure types for each model",
|
|
64
|
+
),
|
|
65
|
+
Heading("Failure details"),
|
|
66
|
+
Table(failure_types, formats={"model_a": "integer", "model_b": "integer"}),
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
for ext in ("pdf", "xlsx"):
|
|
71
|
+
result = report.save(f"ai_evaluation_report.{ext}")
|
|
72
|
+
print(result.path)
|
|
73
|
+
for w in result.warnings:
|
|
74
|
+
print(f" {w.code}: {w.message}")
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Analytics report with pandas — Word and PDF with synthetic data.
|
|
2
|
+
|
|
3
|
+
Requires the pandas extra:
|
|
4
|
+
pip install "patrakit[pandas]"
|
|
5
|
+
|
|
6
|
+
Run:
|
|
7
|
+
python analytics_report.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import pandas as pd
|
|
12
|
+
except ImportError:
|
|
13
|
+
raise SystemExit("This example needs pandas: pip install 'patrakit[pandas]'")
|
|
14
|
+
|
|
15
|
+
from patrakit import Report, Heading, Text, KPIRow, Table, Chart
|
|
16
|
+
|
|
17
|
+
data = pd.DataFrame({
|
|
18
|
+
"channel": ["Organic", "Organic", "Paid", "Paid", "Referral", "Referral",
|
|
19
|
+
"Direct", "Direct", "Social", "Social"],
|
|
20
|
+
"month": ["Nov", "Dec", "Nov", "Dec", "Nov", "Dec",
|
|
21
|
+
"Nov", "Dec", "Nov", "Dec"],
|
|
22
|
+
"sessions": [45000, 48200, 32000, 35100, 12000, 13400, 8000, 8600, 6000, 7200],
|
|
23
|
+
"conversions": [2250, 2650, 1920, 2106, 840, 938, 320, 344, 180, 216],
|
|
24
|
+
"revenue": [112500, 132500, 96000, 105300, 42000, 46900, 16000, 17200, 9000, 10800],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
dec = data[data["month"] == "Dec"]
|
|
28
|
+
total_sessions = dec["sessions"].sum()
|
|
29
|
+
total_conversions = dec["conversions"].sum()
|
|
30
|
+
total_revenue = dec["revenue"].sum()
|
|
31
|
+
conv_rate = total_conversions / total_sessions
|
|
32
|
+
|
|
33
|
+
channel_summary = dec.groupby("channel").agg(
|
|
34
|
+
sessions=("sessions", "sum"),
|
|
35
|
+
conversions=("conversions", "sum"),
|
|
36
|
+
revenue=("revenue", "sum"),
|
|
37
|
+
).reset_index()
|
|
38
|
+
channel_summary["conv_rate"] = channel_summary["conversions"] / channel_summary["sessions"]
|
|
39
|
+
|
|
40
|
+
report = Report(
|
|
41
|
+
title="Marketing Analytics — December",
|
|
42
|
+
subtitle="Synthetic demo data",
|
|
43
|
+
theme="modern",
|
|
44
|
+
blocks=[
|
|
45
|
+
Heading("Summary"),
|
|
46
|
+
Text("December showed growth across all channels compared to November."),
|
|
47
|
+
KPIRow({
|
|
48
|
+
"Sessions": f"{total_sessions:,}",
|
|
49
|
+
"Conversions": f"{total_conversions:,}",
|
|
50
|
+
"Revenue": f"${total_revenue:,.0f}",
|
|
51
|
+
"Conv rate": f"{conv_rate:.1%}",
|
|
52
|
+
}),
|
|
53
|
+
Heading("Revenue by channel"),
|
|
54
|
+
Chart.bar(
|
|
55
|
+
channel_summary.to_dict("records"),
|
|
56
|
+
x="channel",
|
|
57
|
+
y="revenue",
|
|
58
|
+
title="December revenue by channel",
|
|
59
|
+
alt_text="Bar chart showing revenue by marketing channel in December",
|
|
60
|
+
),
|
|
61
|
+
Heading("Conversion rate by channel"),
|
|
62
|
+
Chart.bar(
|
|
63
|
+
channel_summary.to_dict("records"),
|
|
64
|
+
x="channel",
|
|
65
|
+
y="conv_rate",
|
|
66
|
+
title="Conversion rate by channel",
|
|
67
|
+
alt_text="Bar chart showing conversion rates by channel",
|
|
68
|
+
),
|
|
69
|
+
Heading("Channel breakdown"),
|
|
70
|
+
Table(
|
|
71
|
+
channel_summary,
|
|
72
|
+
formats={
|
|
73
|
+
"sessions": "integer",
|
|
74
|
+
"conversions": "integer",
|
|
75
|
+
"revenue": "currency:USD",
|
|
76
|
+
"conv_rate": "percent:1",
|
|
77
|
+
},
|
|
78
|
+
),
|
|
79
|
+
],
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
for ext in ("docx", "pdf"):
|
|
83
|
+
result = report.save(f"analytics_report.{ext}")
|
|
84
|
+
print(result.path)
|
|
85
|
+
for w in result.warnings:
|
|
86
|
+
print(f" {w.code}: {w.message}")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Invoice example — PDF and Excel with synthetic data.
|
|
2
|
+
|
|
3
|
+
This is a layout example. It does not claim to meet the tax or legal
|
|
4
|
+
invoice rules of any country.
|
|
5
|
+
|
|
6
|
+
Run:
|
|
7
|
+
python invoice.py
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from decimal import Decimal
|
|
11
|
+
|
|
12
|
+
from patrakit import Report, Heading, Text, KPIRow, Table
|
|
13
|
+
|
|
14
|
+
line_items = [
|
|
15
|
+
{"description": "Web application development", "hours": Decimal("120"), "rate": Decimal("150.00"), "amount": Decimal("18000.00")},
|
|
16
|
+
{"description": "Database design and setup", "hours": Decimal("40"), "rate": Decimal("150.00"), "amount": Decimal("6000.00")},
|
|
17
|
+
{"description": "API integration", "hours": Decimal("60"), "rate": Decimal("150.00"), "amount": Decimal("9000.00")},
|
|
18
|
+
{"description": "Testing and QA", "hours": Decimal("30"), "rate": Decimal("125.00"), "amount": Decimal("3750.00")},
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
subtotal = sum(item["amount"] for item in line_items)
|
|
22
|
+
sample_tax = (subtotal * Decimal("0.18")).quantize(Decimal("0.01"))
|
|
23
|
+
total = subtotal + sample_tax
|
|
24
|
+
|
|
25
|
+
report = Report(
|
|
26
|
+
title="Invoice #2024-0042",
|
|
27
|
+
subtitle="Synthetic demo data — layout example",
|
|
28
|
+
theme="classic",
|
|
29
|
+
blocks=[
|
|
30
|
+
Heading("From"),
|
|
31
|
+
Text("Acme Software Pvt Ltd (fictional)\n123 Demo Street, Bengaluru 560001"),
|
|
32
|
+
Heading("To"),
|
|
33
|
+
Text("Example Corp (fictional)\n456 Sample Avenue, Mumbai 400001"),
|
|
34
|
+
Heading("Line items"),
|
|
35
|
+
Table(
|
|
36
|
+
line_items,
|
|
37
|
+
formats={
|
|
38
|
+
"rate": "currency:USD",
|
|
39
|
+
"amount": "currency:USD",
|
|
40
|
+
"hours": "number:0",
|
|
41
|
+
},
|
|
42
|
+
),
|
|
43
|
+
Heading("Summary"),
|
|
44
|
+
KPIRow({
|
|
45
|
+
"Subtotal": f"${subtotal:,.2f}",
|
|
46
|
+
"Sample tax (18%)": f"${sample_tax:,.2f}",
|
|
47
|
+
"Total": f"${total:,.2f}",
|
|
48
|
+
}),
|
|
49
|
+
Text("Payment terms: Net 30 days. This is a fictional invoice for demonstration purposes."),
|
|
50
|
+
],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
assert subtotal == sum(item["amount"] for item in line_items), "Subtotal does not match"
|
|
54
|
+
assert total == subtotal + sample_tax, "Total does not match"
|
|
55
|
+
|
|
56
|
+
for ext in ("pdf", "xlsx"):
|
|
57
|
+
result = report.save(f"invoice.{ext}")
|
|
58
|
+
print(result.path)
|
|
59
|
+
for w in result.warnings:
|
|
60
|
+
print(f" {w.code}: {w.message}")
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Weekly project status report — Word and PDF with synthetic data.
|
|
2
|
+
|
|
3
|
+
Run:
|
|
4
|
+
python project_status.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from patrakit import Report, Heading, Text, BulletList, KPIRow, Table
|
|
8
|
+
|
|
9
|
+
milestones = [
|
|
10
|
+
{"milestone": "Design review", "status": "Complete", "owner": "Design lead"},
|
|
11
|
+
{"milestone": "Backend API", "status": "In progress", "owner": "Backend team"},
|
|
12
|
+
{"milestone": "Frontend build", "status": "In progress", "owner": "Frontend team"},
|
|
13
|
+
{"milestone": "Integration testing", "status": "Not started", "owner": "QA lead"},
|
|
14
|
+
{"milestone": "Launch", "status": "Not started", "owner": "Project manager"},
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
report = Report(
|
|
18
|
+
title="Project Status — Week 48",
|
|
19
|
+
subtitle="Synthetic demo data",
|
|
20
|
+
theme="modern",
|
|
21
|
+
blocks=[
|
|
22
|
+
Heading("Overall status"),
|
|
23
|
+
Text(
|
|
24
|
+
"The project is on track for the Q1 launch date. "
|
|
25
|
+
"Backend API is 70% complete. Frontend work started this week."
|
|
26
|
+
),
|
|
27
|
+
KPIRow({
|
|
28
|
+
"Overall": "On track",
|
|
29
|
+
"Sprint velocity": "34 pts",
|
|
30
|
+
"Blockers": "1",
|
|
31
|
+
}),
|
|
32
|
+
Heading("Milestones"),
|
|
33
|
+
Table(milestones),
|
|
34
|
+
Heading("Work completed this week"),
|
|
35
|
+
BulletList([
|
|
36
|
+
"Finished user authentication endpoints",
|
|
37
|
+
"Completed database schema migration",
|
|
38
|
+
"Set up CI/CD pipeline for staging",
|
|
39
|
+
"Reviewed and approved UI component library",
|
|
40
|
+
]),
|
|
41
|
+
Heading("Risks and blockers"),
|
|
42
|
+
BulletList([
|
|
43
|
+
"Third-party payment API documentation is incomplete — awaiting vendor response",
|
|
44
|
+
"One team member on leave next week — may slow frontend progress",
|
|
45
|
+
]),
|
|
46
|
+
Heading("Plan for next week"),
|
|
47
|
+
BulletList([
|
|
48
|
+
"Complete remaining API endpoints for order management",
|
|
49
|
+
"Start frontend integration with backend APIs",
|
|
50
|
+
"Begin writing integration test cases",
|
|
51
|
+
]),
|
|
52
|
+
],
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
for ext in ("docx", "pdf"):
|
|
56
|
+
result = report.save(f"project_status.{ext}")
|
|
57
|
+
print(result.path)
|
|
58
|
+
for w in result.warnings:
|
|
59
|
+
print(f" {w.code}: {w.message}")
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""SaaS monthly review — PowerPoint and PDF with synthetic data.
|
|
2
|
+
|
|
3
|
+
Run:
|
|
4
|
+
python saas_monthly_review.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from patrakit import Report, Heading, Text, BulletList, KPIRow, Table, Chart
|
|
8
|
+
|
|
9
|
+
mrr_data = [
|
|
10
|
+
{"month": "Jul", "mrr": 38000},
|
|
11
|
+
{"month": "Aug", "mrr": 39500},
|
|
12
|
+
{"month": "Sep", "mrr": 41000},
|
|
13
|
+
{"month": "Oct", "mrr": 44500},
|
|
14
|
+
{"month": "Nov", "mrr": 47200},
|
|
15
|
+
{"month": "Dec", "mrr": 49800},
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
customer_data = [
|
|
19
|
+
{"month": "Jul", "new": 12, "churned": 3},
|
|
20
|
+
{"month": "Aug", "new": 15, "churned": 4},
|
|
21
|
+
{"month": "Sep", "new": 18, "churned": 2},
|
|
22
|
+
{"month": "Oct", "new": 22, "churned": 5},
|
|
23
|
+
{"month": "Nov", "new": 20, "churned": 3},
|
|
24
|
+
{"month": "Dec", "new": 25, "churned": 4},
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
report = Report(
|
|
28
|
+
title="SaaS Monthly Review — December",
|
|
29
|
+
subtitle="Synthetic demo data",
|
|
30
|
+
theme="modern",
|
|
31
|
+
blocks=[
|
|
32
|
+
Heading("Key metrics"),
|
|
33
|
+
KPIRow({
|
|
34
|
+
"MRR": "$49.8K",
|
|
35
|
+
"New customers": "25",
|
|
36
|
+
"Churned": "4",
|
|
37
|
+
"Net growth": "+21",
|
|
38
|
+
}),
|
|
39
|
+
Heading("MRR trend"),
|
|
40
|
+
Chart.line(
|
|
41
|
+
mrr_data,
|
|
42
|
+
x="month",
|
|
43
|
+
y="mrr",
|
|
44
|
+
title="Monthly Recurring Revenue",
|
|
45
|
+
alt_text="Line chart showing MRR growth from $38K to $49.8K over six months",
|
|
46
|
+
),
|
|
47
|
+
Heading("New vs churned customers"),
|
|
48
|
+
Chart.bar(
|
|
49
|
+
customer_data,
|
|
50
|
+
x="month",
|
|
51
|
+
y=["new", "churned"],
|
|
52
|
+
title="Customer movement",
|
|
53
|
+
alt_text="Bar chart comparing new and churned customers per month",
|
|
54
|
+
),
|
|
55
|
+
Heading("Risks"),
|
|
56
|
+
BulletList([
|
|
57
|
+
"Enterprise deal pipeline is thin for Q1",
|
|
58
|
+
"Support response time increased to 18 hours",
|
|
59
|
+
"Two key engineers leaving in January",
|
|
60
|
+
]),
|
|
61
|
+
Heading("Next actions"),
|
|
62
|
+
BulletList([
|
|
63
|
+
"Launch outbound campaign targeting mid-market",
|
|
64
|
+
"Hire two support engineers by end of January",
|
|
65
|
+
"Ship the dashboard feature to reduce support load",
|
|
66
|
+
]),
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
for ext in ("pptx", "pdf"):
|
|
71
|
+
result = report.save(f"saas_monthly_review.{ext}")
|
|
72
|
+
print(result.path)
|
|
73
|
+
for w in result.warnings:
|
|
74
|
+
print(f" {w.code}: {w.message}")
|