Skip to content

Migrating from Python Beancount

rustledger is designed as a drop-in replacement for Python beancount with 10-30x better performance.

Quick Start

Your existing beancount files work as-is:

bash
# Validate with rustledger
rledger check ledger.beancount

# Run queries
rledger query ledger.beancount "SELECT account, sum(position) GROUP BY account"

Compatibility

Fully Compatible

  • All beancount syntax
  • All directive types (transaction, balance, open, close, etc.)
  • All booking methods (FIFO, LIFO, STRICT, etc.)
  • BQL query language
  • Include directives
  • Options
  • Metadata

Plugin Compatibility

PluginStatusNotes
auto_accounts✅ NativeFaster implementation
implicit_prices✅ NativeFaster implementation
check_commodity✅ Native
coherent_cost✅ Native
leafonly✅ Native
noduplicates✅ Native
onecommodity✅ Native
sellgains✅ Native
unique_prices✅ Native
Custom Python plugins⚠️ WASMRequires compilation

See Plugins Reference for full list.

Known Differences

  1. Decimal precision: rustledger uses 28-digit precision vs Python's arbitrary precision. This only affects extreme edge cases (28+ decimal places).

  2. Error messages: Format differs but contains same information.

  3. Plugin loading: Python plugins require WASM compilation.

Migration Steps

1. Install rustledger

bash
cargo install rustledger

2. Validate Your Ledger

bash
rledger check ledger.beancount

Compare output with Python beancount:

bash
bean-check ledger.beancount

3. Test Reports

bash
# Balance report
rledger report balances ledger.beancount

# Compare with
bean-report ledger.beancount balances

4. Test Queries

bash
rledger query ledger.beancount "SELECT account, sum(position) GROUP BY account"

5. Update Your Workflow

Replace beancount commands:

Python Beancountrustledger
bean-checkrledger check
bean-queryrledger query
bean-reportrledger report
bean-formatrledger format
bean-pricerledger price
bean-extractrledger extract

6. Update Editor

If using VS Code or other editors with Python beancount LSP, switch to rustledger LSP for better performance.

Plugin Migration

Python Plugins to WASM

For custom Python plugins, you have options:

  1. Rewrite in Rust: Add to rustledger-plugin/src/native/
  2. Compile to WASM: Use py2wasm (experimental)
  3. Use pre/post hooks: For simple transformations

Check Plugin Equivalents

Many Python plugins have native Rust equivalents:

beancount
; Before (Python)
plugin "beancount.plugins.auto_accounts"

; After (rustledger) - same syntax, native implementation
plugin "beancount.plugins.auto_accounts"

Performance Comparison

Typical speedups on real ledgers:

Ledger SizePythonrustledgerSpeedup
1,000 txns2.5s0.1s25x
10,000 txns8s0.3s27x
50,000 txns35s1.2s29x

Troubleshooting

"Unknown plugin" Error

The plugin may not be implemented yet. Check Plugins Reference or open an issue.

Different Balance

Check for precision differences:

bash
# Python
bean-query ledger.beancount "SELECT sum(position) WHERE account ~ 'Assets'"

# rustledger
rledger query ledger.beancount "SELECT sum(position) WHERE account ~ 'Assets'"

If amounts differ by tiny fractions (e.g., 1e-20), it's a precision difference and can be ignored.

Query Syntax Differences

BQL is compatible, but check:

  • Date literals: Use 2024-01-15 not "2024-01-15"
  • Regex: Use account ~ "pattern" for regex matching

See Also