Skip to content

feat: beancount parity - reports and importer - #22

Closed
robcohen wants to merge 9 commits into
mainfrom
feature/beancount-parity
Closed

robcohen wants to merge 9 commits into
mainfrom
feature/beancount-parity

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

This PR adds significant new functionality to bring rustledger closer to feature parity with Python beancount:

Phase 1: Core Reports

  • Balance Sheet (balsheet): Assets, Liabilities, Equity with net worth
  • Income Statement (income): Income and Expenses with net income
  • Journal/Register (journal): Transaction list with optional filtering and limit
  • Holdings (holdings): Investment positions with cost basis
  • Net Worth Over Time (networth): Track net worth by period (daily/weekly/monthly/yearly)

Export Formats

All reports now support multiple output formats via -f/--format:

  • text (default): Human-readable text tables
  • csv: Machine-readable CSV for spreadsheets
  • json: Structured JSON for programmatic use

Phase 2: Import System

  • New rustledger-importer crate with extensible import framework
  • CSV Importer with configurable:
    • Column mapping (by name or index)
    • Date formats (strftime-style)
    • Combined or separate debit/credit columns
    • Currency specification
    • Sign inversion
    • Header skip rows
  • rledger-extract and bean-extract CLI commands

Example Usage

# Reports
rledger-report ledger.beancount balsheet
rledger-report ledger.beancount income -f csv
rledger-report ledger.beancount holdings -f json

# Import
rledger-extract bank.csv --account Assets:Bank:Checking
rledger-extract statement.csv --date-format "%m/%d/%Y" --currency USD

Test plan

  • Existing tests pass
  • New importer tests pass (5 tests)
  • Manual testing of all reports with sample beancount files
  • Manual testing of CSV import with sample bank statement

🤖 Generated with Claude Code

robcohen and others added 3 commits January 10, 2026 15:34
Add new report types to match Python beancount functionality:
- balsheet: Balance sheet (Assets, Liabilities, Equity)
- income: Income statement (Income and Expenses)
- journal: Transaction journal/register with filtering
- holdings: Investment holdings with cost basis
- networth: Net worth over time (daily/weekly/monthly/yearly)

These reports close the gap with Python beancount's bean-report
command and provide essential financial analysis capabilities.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add -f/--format flag to rledger-report command supporting text (default),
csv, and json output formats. All reports now support these formats:
- balances: account balances with currency
- accounts: list of accounts
- commodities: list of commodities
- prices: price history
- balsheet: balance sheet with sections
- income: income statement with sections
- journal: transaction register
- holdings: positions with cost basis
- networth: net worth over time

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add new rustledger-importer crate with:
- Importer trait for extensible import framework
- CSV importer with configurable columns/formats
- ImporterRegistry for managing multiple importers
- rledger-extract and bean-extract CLI commands

Features:
- Flexible column mapping (by name or index)
- Support for combined or separate debit/credit columns
- Configurable date formats
- Currency specification
- Sign inversion option
- Warning collection for parse errors

Example usage:
  rledger-extract bank.csv --account Assets:Bank:Checking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@codecov

codecov Bot commented Jan 10, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

Add support for importing transactions from OFX (Open Financial Exchange)
and QFX (Quicken Financial Exchange) files commonly exported by banks.

Features:
- Parse bank and credit card transaction lists
- Extract date, amount, payee, and memo from transactions
- Automatic currency detection from statement
- Create balanced transactions with Unknown expense/income accounts
- Support for both .ofx and .qfx file extensions

Uses the ofxy crate for robust OFX parsing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions

github-actions Bot commented Jan 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results

Comparing main (base) vs feature/beancount-parity (pr)

group                                     base                                     pr
-----                                     ----                                     --
inventory_add/10                          1.02    581.5±4.18ns 16.4 MElem/sec      1.00   572.7±13.37ns 16.7 MElem/sec
inventory_add/100                         1.02      5.8±0.07µs 16.4 MElem/sec      1.00      5.7±0.04µs 16.8 MElem/sec
inventory_add/1000                        1.00     84.9±1.64µs 11.2 MElem/sec      1.00     84.8±0.43µs 11.2 MElem/sec
inventory_at_cost/10                      1.00    334.7±0.94ns        ? ?/sec      1.00    335.5±1.95ns        ? ?/sec
inventory_at_cost/100                     1.00      3.4±0.01µs        ? ?/sec      1.00      3.3±0.01µs        ? ?/sec
inventory_at_cost/1000                    1.00     33.4±0.06µs        ? ?/sec      1.00     33.5±0.14µs        ? ?/sec
inventory_book_value/10                   1.02    495.6±7.24ns        ? ?/sec      1.00    483.7±4.94ns        ? ?/sec
inventory_book_value/100                  1.04      4.7±0.02µs        ? ?/sec      1.00      4.6±0.05µs        ? ?/sec
inventory_book_value/1000                 1.04     47.5±0.19µs        ? ?/sec      1.00     45.5±0.21µs        ? ?/sec
inventory_merge/10                        1.00    242.2±7.56ns        ? ?/sec      1.00    241.9±6.91ns        ? ?/sec
inventory_merge/100                       1.00      2.1±0.04µs        ? ?/sec      1.00      2.1±0.03µs        ? ?/sec
inventory_merge/500                       1.00     10.3±0.11µs        ? ?/sec      1.00     10.3±0.19µs        ? ?/sec
inventory_units/10                        1.00    113.9±0.28ns        ? ?/sec      1.00    113.9±0.20ns        ? ?/sec
inventory_units/100                       1.00   1107.0±2.53ns        ? ?/sec      1.00   1107.1±4.58ns        ? ?/sec
inventory_units/1000                      1.00     11.1±0.03µs        ? ?/sec      1.00     11.1±0.04µs        ? ?/sec
parse_large/1000_transactions             1.02      9.9±0.05ms    10.5 MB/sec      1.00      9.7±0.03ms    10.6 MB/sec
parse_medium/100_transactions             1.02   1014.4±9.10µs    10.2 MB/sec      1.00   997.1±16.80µs    10.4 MB/sec
parse_scaling/10                          1.03    126.1±0.72µs     9.4 MB/sec      1.00    122.3±0.81µs     9.7 MB/sec
parse_scaling/100                         1.03  1026.6±11.43µs    10.1 MB/sec      1.00    995.9±8.20µs    10.4 MB/sec
parse_scaling/1000                        1.02     10.0±0.06ms    10.4 MB/sec      1.00      9.7±0.03ms    10.6 MB/sec
parse_scaling/50                          1.01    523.6±5.33µs    10.1 MB/sec      1.00   517.2±17.43µs    10.2 MB/sec
parse_scaling/500                         1.04      5.0±0.04ms    10.2 MB/sec      1.00      4.9±0.02ms    10.6 MB/sec
parse_small/10_transactions               1.02    124.5±1.37µs     9.5 MB/sec      1.00    121.7±1.78µs     9.8 MB/sec
pipeline_full/1000_txns                   1.02     14.0±0.04ms 69.7 KElem/sec      1.00     13.7±0.32ms 71.4 KElem/sec
pipeline_full/100_txns                    1.02  1479.6±20.51µs 66.0 KElem/sec      1.00  1453.1±30.21µs 67.2 KElem/sec
pipeline_full/500_txns                    1.03      7.1±0.04ms 69.1 KElem/sec      1.00      6.9±0.04ms 71.2 KElem/sec
pipeline_parse/1000_txns                  1.04     13.0±0.07ms     7.7 MB/sec      1.00     12.4±0.08ms     8.1 MB/sec
pipeline_parse/100_txns                   1.03  1353.7±31.57µs     7.7 MB/sec      1.00  1315.5±18.37µs     7.9 MB/sec
pipeline_parse/5000_txns                  1.02     66.1±1.28ms     7.7 MB/sec      1.00     64.6±2.28ms     7.8 MB/sec
pipeline_parse/500_txns                   1.03      6.5±0.04ms     7.7 MB/sec      1.00      6.3±0.06ms     8.0 MB/sec
pipeline_parse_validate/1000_txns         1.04     13.6±0.07ms 71.6 KElem/sec      1.00     13.2±0.09ms 74.3 KElem/sec
pipeline_parse_validate/100_txns          1.03  1439.8±11.46µs 67.8 KElem/sec      1.00  1397.3±25.47µs 69.9 KElem/sec
pipeline_parse_validate/500_txns          1.03      6.9±0.04ms 71.1 KElem/sec      1.00      6.6±0.05ms 73.6 KElem/sec
query_balances/balances                   1.00    102.7±0.37µs  9.3 MElem/sec      1.00    103.1±0.51µs  9.2 MElem/sec
query_group_by/group_by_account_sum       1.00   636.4±10.54µs 1534.5 KElem/sec    1.02    647.6±7.53µs 1508.0 KElem/sec
query_scaling/100                         1.00     65.5±0.34µs 1491.8 KElem/sec    1.02     66.7±0.69µs 1464.3 KElem/sec
query_scaling/1000                        1.02    647.8±9.64µs 1507.4 KElem/sec    1.00    634.1±3.93µs 1540.2 KElem/sec
query_scaling/500                         1.04    324.6±4.93µs 1504.1 KElem/sec    1.00    310.8±1.95µs 1571.0 KElem/sec
query_scaling/5000                        1.00      3.1±0.04ms 1562.2 KElem/sec    1.00      3.1±0.03ms 1558.6 KElem/sec
query_simple_select/select_all_columns    1.03    643.0±7.95µs 1518.8 KElem/sec    1.00    623.7±2.33µs 1565.7 KElem/sec
query_where/where_account_contains        1.00    563.2±2.59µs 1733.9 KElem/sec    1.01    568.3±4.04µs 1718.5 KElem/sec
reduce_fifo/10                            1.00  1791.8±45.12ns        ? ?/sec      1.00  1797.2±28.27ns        ? ?/sec
reduce_fifo/100                           1.00    134.4±1.92µs        ? ?/sec      1.01    135.2±2.52µs        ? ?/sec
reduce_fifo/500                           1.00      3.2±0.01ms        ? ?/sec      1.00      3.2±0.02ms        ? ?/sec
reduce_lifo/10                            1.00  1745.3±31.83ns        ? ?/sec      1.00  1741.8±48.76ns        ? ?/sec
reduce_lifo/100                           1.01    136.0±2.52µs        ? ?/sec      1.00    135.3±2.97µs        ? ?/sec
reduce_lifo/500                           1.00      3.2±0.01ms        ? ?/sec      1.00      3.2±0.07ms        ? ?/sec
reduce_strict/10                          1.00    259.8±8.73ns        ? ?/sec      1.00   259.9±10.58ns        ? ?/sec
reduce_strict/100                         1.01   840.7±22.27ns        ? ?/sec      1.00   831.4±28.66ns        ? ?/sec
reduce_strict/500                         1.01      4.1±0.08µs        ? ?/sec      1.00      4.1±0.09µs        ? ?/sec
throughput/10k_transactions               1.05    131.3±0.69ms 74.4 KElem/sec      1.00    125.3±0.82ms 77.9 KElem/sec
validate_balance_assertions/10            1.00      3.8±0.04µs  2.5 MElem/sec      1.00      3.8±0.07µs  2.5 MElem/sec
validate_balance_assertions/100           1.00     34.2±0.18µs  2.8 MElem/sec      1.00     34.4±0.94µs  2.8 MElem/sec
validate_balance_assertions/50            1.01     17.3±0.09µs  2.8 MElem/sec      1.00     17.1±0.17µs  2.8 MElem/sec
validate_valid/100                        1.00     34.2±0.32µs  2.8 MElem/sec      1.00     34.1±0.13µs  2.8 MElem/sec
validate_valid/1000                       1.00    114.8±0.68µs  8.3 MElem/sec      1.00    114.6±0.93µs  8.3 MElem/sec
validate_valid/500                        1.02    115.9±0.89µs  4.1 MElem/sec      1.00    114.1±1.07µs  4.2 MElem/sec
validate_valid/5000                       1.00    113.9±1.49µs 41.9 MElem/sec      1.01    114.9±0.68µs 41.5 MElem/sec
validate_with_errors/100                  1.00     32.7±0.14µs  2.9 MElem/sec      1.00     32.7±0.24µs  2.9 MElem/sec
validate_with_errors/1000                 1.00    344.8±2.36µs  2.8 MElem/sec      1.01    348.2±2.12µs  2.7 MElem/sec
validate_with_errors/500                  1.00    174.6±2.29µs  2.7 MElem/sec      1.00    175.0±0.81µs  2.7 MElem/sec

Legend
  • Ratio < 1.0: PR is faster (improvement)
  • Ratio > 1.0: PR is slower (regression)
  • Differences within ~5% are typically noise

robcohen and others added 5 commits January 10, 2026 16:44
Implement rledger-price/bean-price CLI tool to fetch current prices
from Yahoo Finance API for commodities defined in beancount files.

Features:
- Fetch prices for stock symbols (AAPL, MSFT, VTI, etc.)
- Support for cryptocurrency via symbol mapping (-m BTC:BTC-USD)
- Output as beancount price directives (-b flag)
- Read commodities from beancount files (-f flag)
- Configurable base currency (-c flag)
- Custom date support (-d flag)

Example usage:
  rledger-price AAPL MSFT -b
  rledger-price -f ledger.beancount -b
  rledger-price -m BTC:BTC-USD,ETH:ETH-USD BTC ETH -b

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Implement JSON REST API server for accessing ledger data, enabling
web UIs and external tool integration.

API Endpoints:
- GET /health - Server health check
- GET /api/v1/accounts - List all accounts with open dates
- GET /api/v1/accounts/:account/balance - Get account balance
- GET /api/v1/balances - Get all account balances (filterable)
- GET /api/v1/transactions - List transactions (paginated, filterable)
- GET /api/v1/commodities - List declared commodities
- GET /api/v1/prices - List all price directives

Features:
- Configurable port and host binding
- Optional CORS support for browser access
- Query parameters for filtering by account, date range
- JSON responses with proper error handling

Example usage:
  rledger-web ledger.beancount --cors -p 3000
  curl http://localhost:3000/api/v1/balances?account=Assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add Fava JSON API compatibility to rledger-web server:

- /api/ledger_data - ledger metadata (accounts, currencies, tags, etc.)
- /api/balance_sheet - hierarchical asset/liability/equity tree
- /api/income_statement - income and expense summary
- /api/journal - all transactions and directives
- /api/query - BQL query execution endpoint
- /api/commodities - commodity list with prices
- /api/events - event directives
- /api/errors - parsing and validation errors

This enables Fava (or Fava-compatible frontends) to connect to
rustledger as a backend, providing a familiar web interface for
beancount users migrating to rustledger.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Fava reads beancount files directly, so the API isn't needed
for Fava integration. Can be re-added later if custom frontends
are desired.

This reverts commit eef5254.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
CLI tools and Fava cover all use cases. The REST API can be
re-added later if custom frontends are needed.

This reverts commit 1b290de.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@robcohen

Copy link
Copy Markdown
Member Author

Superseded by PRs #23 (reports), #24 (import system), and #25 (price fetching) which were merged separately.

@robcohen robcohen closed this Jan 11, 2026
@robcohen
robcohen deleted the feature/beancount-parity branch January 14, 2026 04:04
robcohen added a commit that referenced this pull request Nov 27, 2026
… from beancount

Beancount booking regroups a transaction postings by the currency each
weighs in. rledger keeps the written order: compatibility.md #22, and the
semantic gate counts such a ledger as the currency-group-posting-order
deviation (only when regrouping reproduces beancount order exactly).

Maintainer decision on question 4 of #3071.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 28, 2026
… from beancount

Beancount booking regroups a transaction postings by the currency each
weighs in. rledger keeps the written order: compatibility.md #22, and the
semantic gate counts such a ledger as the currency-group-posting-order
deviation (only when regrouping reproduces beancount order exactly).

Maintainer decision on question 4 of #3071.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 28, 2026
… from beancount

Beancount booking regroups a transaction postings by the currency each
weighs in. rledger keeps the written order: compatibility.md #22, and the
semantic gate counts such a ledger as the currency-group-posting-order
deviation (only when regrouping reproduces beancount order exactly).

Maintainer decision on question 4 of #3071.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 28, 2026
… from beancount

Beancount booking regroups a transaction postings by the currency each
weighs in. rledger keeps the written order: compatibility.md #22, and the
semantic gate counts such a ledger as the currency-group-posting-order
deviation (only when regrouping reproduces beancount order exactly).

Maintainer decision on question 4 of #3071.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant