Metadata-Version: 2.5
Name: pfetl-analytics-studio
Version: 1.1.3
Summary: Local-first, read-only analytical companion to Personal Finance ETL for visual exploration, reporting, and intelligence.
Project-URL: Homepage, https://github.com/tks18/pfetl-analytics-studio
Project-URL: Repository, https://github.com/tks18/pfetl-analytics-studio
Project-URL: Issues, https://github.com/tks18/pfetl-analytics-studio/issues
Author-email: Shan <tksudharshan@gmail.com>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Requires-Python: >=3.13
Requires-Dist: duckdb<2.0.0,>=1.5.5
Requires-Dist: kaleido<2.0.0,>=1.5.0
Requires-Dist: nicegui<5.0.0,>=4.0.0
Requires-Dist: pillow>=11.0.0
Requires-Dist: platformdirs>=4.0.0
Requires-Dist: plotly<8.0.0,>=7.1.0
Requires-Dist: polars<3.0.0,>=2.1.0
Requires-Dist: pydantic<3.0.0,>=2.14.0
Requires-Dist: pystray>=0.19.5
Requires-Dist: python-pptx>=1.0.2
Requires-Dist: reportlab<6.0.0,>=5.1.0
Requires-Dist: xlsxwriter<4.0.0,>=3.3.0
Description-Content-Type: text/markdown

<p align="center">
  <img src=".github/assets/logo.png" width="150" alt="PFETL Analytics Studio logo">
</p>

# PFETL Analytics Studio

<p align="center">
  <strong>Local-first analytics &amp; reporting UI for <a href="https://github.com/tks18/personal-finance-etl">Personal Finance ETL</a> — your numbers, your machine, zero cloud.</strong>
</p>

<p align="center">
  <a href="https://pypi.org/project/pfetl-analytics-studio/"><img src="https://img.shields.io/pypi/v/pfetl-analytics-studio?label=PyPI" alt="PyPI"></a>
  <img src="https://img.shields.io/badge/Python-3.13%2B-3776AB?logo=python&amp;logoColor=white" alt="Python">
  <a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPL--3.0-blue.svg" alt="GPL-3.0-or-later"></a>
  <img src="https://img.shields.io/badge/UI-NiceGUI-5898D4" alt="NiceGUI">
  <img src="https://img.shields.io/badge/Charts-Plotly-3F4F75?logo=plotly&amp;logoColor=white" alt="Plotly">
  <img src="https://img.shields.io/badge/Warehouse-DuckDB-FFF000?logo=duckdb&amp;logoColor=000" alt="DuckDB">
  <img src="https://img.shields.io/badge/Compute-Polars-CD792C" alt="Polars">
</p>

---

## What's the vibe?

PFETL Analytics Studio is a read-only desktop/web UI built with NiceGUI and Plotly on top of [Personal Finance ETL](https://github.com/tks18/personal-finance-etl) ([PyPI](https://pypi.org/project/personal-finance-etl/)) (PFETL Core).

PFETL Core already does the heavy lifting — ingestion, reconciliation, FIFO lot math, XIRR, tax classification, and FIRE simulations. Studio doesn't import `personal-finance-etl` or re-math any of that. It strictly reads the DuckDB warehouse, Control Plane SQLite, and TOML configs that Core already built, and turns them into interactive charts, drill-downs, read-only SQL, and exportable reports.

## How it integrates with PFETL Core

Studio connects to PFETL Core purely through its output files and CLI/HTTP contract:

```mermaid
flowchart LR
    subgraph CORE["PFETL Core Outputs"]
        DUCK[("Personal_Finance_DB.duckdb")]
        CP[("Control Plane SQLite")]
        TOML["Settings + FinancialRules TOML"]
        JSONL["Forensic JSONL"]
    end

    subgraph STUDIO["Analytics Studio (Read-Only)"]
        APP["NiceGUI + Plotly UI"]
        EXP["Explorer + Read-Only SQL"]
        REP["Report Engine"]
    end

    subgraph OUT["Exports"]
        PDF["PDF / PPTX"]
        DATA["XLSX / CSV / PNG / SVG"]
    end

    DUCK --> APP
    CP --> APP
    TOML --> APP
    JSONL --> APP
    APP --> EXP
    APP --> REP
    REP --> PDF
    REP --> DATA
```

| Core Input | What Studio Reads |
|---|---|
| `Personal_Finance_DB.duckdb` | Gold & Silver tables across all domains (read-only; respects `pipeline.lock`) |
| Control Plane SQLite | Run history, sync health, source registry, artifact events, provider requests, failures, retained payloads |
| `Settings.toml` & `FinancialRules.toml` | Active profile paths, currency, tax/FIRE rules, and config snapshots |
| Forensic JSONL | Run-level stage timings, worker activity, and diagnostic logs |

Studio keeps its own stuff (Saved Views, custom report layouts, runtime metadata) in a separate local SQLite via `platformdirs` — Core's files stay completely untouched.

---

## Workspaces

| Workspace | What it covers |
|---|---|
| **Overview** | Top-level KPIs (Net Worth, Income, Expense, Cashflow, Portfolio & XIRR, Total Indicative Tax, FI Coverage, Latest Run) with period/YoY comparisons and trend charts |
| **Household** | 4 tabs: Income, Expense, Budget & Cashflow, and a searchable Transactions ledger with Silver-field inspection and streaming CSV export |
| **Wealth** | Market vs Book Net Worth, monthly attribution (savings vs market vs FX), liquid vs illiquid split, asset-class breakdown, and click-to-drill asset detail |
| **Investments** | 5 tabs: Allocation, Performance & Benchmarks (XIRR, drawdown, FX vs asset P&L), Lot Explorer (open lots + 88-col lot detail), Realized & Reconciliation, and Market Evidence |
| **Tax** | 4 tabs: FY Overview & Exposure (liability waterfall, multi-FY trends, reference rates), Income Head Breakdown, Reconciliation & Audit, and Tax Events & Harvesting (with LTCG maturity & lot drill-down) |
| **FIRE** | FI corpus targets, Lean/Coast FI, emergency runway, savings velocity, Monte Carlo P10/P50/P90 trajectories, simulation provenance, and a separate what-if sandbox |
| **Operations** | 4 tabs: Runs & Sync Health, Sources & Artifacts (with streaming SQLite BLOB downloads), Providers & Failures, and Forensics & Evidence (Settings/Rules diffs + JSONL logs) |
| **Explorer** | Data Catalog across PFETL Gold/Silver/Control Plane surfaces, Guided Analytics, Saved Views, and a read-only SQL editor (`SELECT` / `WITH ... SELECT` only) |
| **Reports** | 15 built-in report templates + custom report builder with block reordering, historical run selection, and export to **PDF, PPTX, XLSX, CSV, PNG, and SVG** |

---

## Install & Run

Requires **Python 3.13+**.

### Grab it

```bash
# With uv (recommended for development)
uv sync

# Or install from PyPI
pip install pfetl-analytics-studio
```

### Launch

```bash
# Default Windows tray mode (auto-picks port, opens browser, manages server lifecycle)
pfetl-studio

# Direct/headless server mode in the current terminal
pfetl-studio --cli

# Point directly to a PFETL profile
pfetl-studio --cli --settings path/to/Settings.toml --rules path/to/FinancialRules.toml
```

Useful CLI flags:

| Flag | Description |
|---|---|
| `--cli` | Run the NiceGUI server directly in the terminal instead of the system tray host |
| `--host` | Loopback host to bind (default `127.0.0.1`; non-loopback hosts are rejected) |
| `--port` | Port to listen on (default `8080`, or `0` with `--auto-port`) |
| `--auto-port` | Prefer `8080` and fall back to a free loopback port if busy |
| `--settings` / `--rules` | Paths to PFETL `Settings.toml` and `FinancialRules.toml` |
| `--no-browser` | Start without opening a browser tab |
| `--runtime-file` | Write atomic JSON runtime metadata (URL, PID, port) for launcher orchestration |

Additional entrypoints: `pfetl-studio-server` (headless server) and `pfetl-studio-tray` (GUI tray host). Health check is exposed at `/healthz`.

---

## Project Layout & Stack

```text
src/pfetl_analytics_studio/
├── analytics/        # Domain services, DTOs, and DuckDB/SQLite queries
├── data/             # Read-only DuckDB/Control Plane readers, catalog, streaming exports
├── semantic/         # Period resolution, filter specs, metric & dataset definitions
├── pages/            # NiceGUI page & tab views
├── reports/          # Report templates, builder runtime, PDF/PPTX/XLSX/CSV/image exporters
├── ui/               # Dark theme, KPI cards, tables, Plotly chart builders
├── app.py            # NiceGUI app shell & routing
├── cli.py            # CLI entrypoints
├── server.py         # Loopback server lifecycle & /healthz
└── tray.py           # System tray controller
```

| Layer | Libraries |
|---|---|
| UI & Charts | NiceGUI, Plotly, Kaleido |
| Data & Models | DuckDB, Polars, SQLite, Pydantic |
| Exports | ReportLab (PDF), python-pptx (PPTX), XlsxWriter (XLSX) |
| Packaging & Desktop | Hatchling, PyInstaller, pystray, Pillow, platformdirs |
| Quality | Ruff, Pyright, Mypy, Pylint, Pytest |

---

## Dev & Vibe Checks

```bash
uv run pytest
uv run poe audit-fast
uv run poe audit-full
uv run pylint src tests
```

---

## Author & License

Built by **Shan** (`tksudharshan@gmail.com`) — wanted a proper local cockpit for [Personal Finance ETL](https://github.com/tks18/personal-finance-etl) ([PyPI](https://pypi.org/project/personal-finance-etl/)), so here we are.

Licensed under the **GNU General Public License v3.0 or later (GPL-3.0-or-later)**. See [LICENSE](LICENSE).
