Metadata-Version: 2.4
Name: hledger-textual
Version: 1.0.0
Summary: A full-featured terminal user interface for hledger plain-text accounting
Author: Michele Broggi
Author-email: Michele Broggi <213027097+thesmokinator@users.noreply.github.com>
License-Expression: MIT
License-File: LICENSE.md
Requires-Dist: babel>=2.18.0
Requires-Dist: fpdf2>=2.8.0
Requires-Dist: pricehist>=1.4.14
Requires-Dist: textual>=8.0,<9
Requires-Dist: textual-plotext>=1.0.0
Requires-Python: >=3.12
Project-URL: Repository, https://github.com/thesmokinator/hledger-textual
Description-Content-Type: text/markdown

# hledger-textual

[![PyPI](https://img.shields.io/pypi/v/hledger-textual?label=PyPI&color=blue)](https://pypi.org/project/hledger-textual/)
[![GitHub Release](https://img.shields.io/github/v/release/thesmokinator/hledger-textual?label=GitHub&color=blue)](https://github.com/thesmokinator/hledger-textual/releases)
[![CI](https://github.com/thesmokinator/hledger-textual/actions/workflows/ci.yml/badge.svg)](https://github.com/thesmokinator/hledger-textual/actions/workflows/ci.yml)
[![Coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fthesmokinator%2Fhledger-textual%2Fmain%2Fcoverage.json&query=%24.totals.percent_covered_display&label=coverage&suffix=%25&color=green)](https://github.com/thesmokinator/hledger-textual/actions/workflows/ci.yml)

A full-featured terminal user interface for [hledger](https://hledger.org) plain-text accounting. Manage transactions, recurring rules, budgets, and investments — with multi-period reports, account drill-downs, and git sync — all from your terminal.

Built with [Textual](https://textual.textualize.io) and Python.

![hledger-textual demo](https://raw.githubusercontent.com/thesmokinator/hledger-textual/main/demo.gif)

## ✨ Feature highlights

- 📊 Multi-period reports — monthly, quarterly, yearly, and custom ranges, with charts
- 🔁 Recurring transaction rules with calendar view and one-shot generation
- 💰 Budgets with overview screen and per-category drill-down
- 📥 CSV import wizard with separator/header detection and rule editor
- 📈 Investment tracking with cost basis and market value conversion
- 🔄 Git sync and cloud sync support for the journal
- 🧩 Custom report builder with saved filters
- 🏦 Account hierarchy with directives (notes, metadata)
- 📄 PDF / CSV export of every view

## Why hledger-textual?

hledger-textual is the most advanced TUI in the hledger ecosystem, with feature parity for budgets, recurring transactions, investments, and reports. Everything lives in plain-text files you already own — the journal, a `budget.journal` for budgets, CSV rules for imports — so no database, no lock-in, and git-friendly versioning of your finances.

## Stack

- **Python 3.12+**
- **Textual** - TUI framework
- **hledger** - plain-text accounting (must be installed separately)
- **uv** - package manager (no `requirements.txt` needed, dependencies are in `pyproject.toml`)
- **pytest** - testing

## Requirements

- Python 3.12+
- [hledger](https://hledger.org/install.html) installed and available in `PATH`

## ⚡ Performance

hledger-textual launches independent hledger queries concurrently (with a
global cap so large journals cannot exhaust CPU or memory), caches results
until the journal or one of its `include` files changes, paints the Summary
cards before preloading the rest, loads the investment portfolio with a single
`balance -O json` query, and updates report tables incrementally.  A
persistent disk cache makes restarting on an unchanged journal effectively
instant.

Measured on an Apple M4 (10 cores), macOS, Python 3.12, Textual 8.2.8 and
hledger 1.52, with journals generated by the bundled script:

| Metric | 10k txns | 50k txns | 100k txns |
|---|---:|---:|---:|
| Summary ready, before (all sections) | 2.95 s | 13.11 s | 25.97 s |
| First Summary figures (cards), after | **0.56 s** | **2.22 s** | **4.75 s** |
| All Summary sections, after | **0.85 s** | **3.54 s** | **7.61 s** |
| All tabs preloaded in background, after | 1.38 s | 6.37 s | 12.82 s |
| Summary refresh (cache warm), before | 1.50 s | 6.70 s | 13.90 s |
| Summary refresh (cache warm), after | **0.07 s** | **0.10 s** | **0.15 s** |
| Reload Summary after a journal change, after | 0.78 s | 3.61 s | 7.66 s |
| Reload Transactions after a journal change, after | 0.41 s | 1.63 s | 3.30 s |
| **Restart with warm disk cache** (Summary) | **0.19 s** | **0.20 s** | **0.26 s** |
| **Restart with warm disk cache** (all tabs preloaded) | **0.19 s** | **0.26 s** | **0.35 s** |

The Summary shows its cards as soon as the first queries return; the
portfolio, breakdown tables and the other tabs keep loading in the
background behind a spinner that also displays elapsed seconds.

The persistent cache lives under the platform cache directory
(`~/Library/Caches/hledger-textual` on macOS, `$XDG_CACHE_HOME/hledger-textual`
on Linux).  Entries are keyed by the hledger arguments, the journal and every
`include` file, the hledger version and the calendar date.  Outputs larger than
8 MiB are not stored, and the cache is pruned to 512 entries / 128 MiB.  Set
`HLEDGER_TEXTUAL_NO_DISK_CACHE=1` to disable it, or
`HLEDGER_TEXTUAL_CACHE_DIR=/path` to move it.  The first run after a journal
change pays the usual load plus a small write overhead (<10%); every later
start reads the cached output instead of re-parsing the journal.

Absolute timings depend on hardware, disk and journal shape; the ratios are
what matters. Reproduce them with:

```bash
# Generate a deterministic synthetic journal and benchmark it
uv run python scripts/benchmark_perf.py --transactions 50000 --repeat 2

# Measure a restart served by the persistent disk cache
uv run python scripts/benchmark_perf.py --transactions 100000 --disk-cache

# Or benchmark an existing journal and save JSON for comparison
uv run python scripts/generate_synthetic_journal.py -n 100000 -o /tmp/100k.journal
uv run python scripts/benchmark_perf.py --journal /tmp/100k.journal --output perf.json
```

The benchmark reports startup, tab switches, cold reloads after a simulated
journal change, and cold/warm timings for the main hledger loaders. It exits
non-zero only on measurement errors; compare its JSON output across commits.

## Installation

```bash
# With pipx
pipx install hledger-textual

# With uv
uv tool install hledger-textual
```

## Usage

```bash
hledger-textual -f path/to/your.journal
```

The journal file is resolved in this order:

1. `-f` / `--file` CLI argument
2. `LEDGER_FILE` environment variable
3. `~/.config/hledger-textual/config.toml` (`journal_file` key)
4. `~/.hledger.journal`

### Default currency

For multi-currency journals, the default currency is resolved in this order:

1. The first `commodity` directive declared in the journal (following
   `include` files), e.g. `commodity €1,000.00`.
2. The `default_commodity` key in `~/.config/hledger-textual/config.toml`.

When resolved, the Accounts and Summary views convert balances to that
currency using `hledger -X --infer-market-prices`, so `P` price directives in
the journal are honored (see `examples/multicurrency-prices.journal`).
Commodities without a price are shown in their original currency, and the
Summary's Income / Expenses / Liabilities breakdowns show `—` instead of a
percentage for them (a note names the excluded commodities). Percentages are
always computed on converted amounts, so rows in different currencies are
never compared one-to-one.

When nothing is resolved, the Accounts view shows each account's balances in
their original currencies (stacked within the cell), the Reports view's flat
multi-period mode marks multi-currency accounts with a `◆` prefix, and the
Summary overview shows a per-currency balance line under each card (marquee
scrolling when it overflows). The Reports view's stacked mode (`M`) always
expands each currency into its own row. Summary breakdown percentages stay
hidden (`—`) for journals that mix currencies in that case, since there is no
common denominator; single-currency journals are unaffected.

To pin a currency via config instead:

```toml
default_commodity = "€"
```

## Configuration

Full reference: the [Wiki](https://github.com/thesmokinator/hledger-textual/wiki) documents every option. A minimal `~/.config/hledger-textual/config.toml`:

```toml
journal_file = "~/finance/all.journal"
default_commodity = "€"
theme = "nord"

# Reorder the tabs (any subset; missing tabs keep their default order)
tab_order = ["summary", "accounts", "transactions", "budget", "recurring", "reports"]
```

## Documentation

See the [Wiki](https://github.com/thesmokinator/hledger-textual/wiki) for the full documentation: feature overview, configuration, investment tracking, and per-tab reference.

## Roadmap

Planned work is tracked as [enhancement issues](https://github.com/thesmokinator/hledger-textual/labels/enhancement) — vote, comment, or pick one up.

## Contributing

Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for the development setup, test suite, and pull-request flow.

## Development

```bash
git clone https://github.com/thesmokinator/hledger-textual.git
cd hledger-textual
uv sync
```

### Testing

```bash
# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run with coverage report
uv run pytest --cov=hledger_textual --cov-report=term-missing
```
