Skip to content

title: Plugins Reference description: Plugin architecture, built-in plugins, and custom plugin development ​

Plugins Reference ​

rustledger supports a flexible plugin system for validation and transformation of your ledger data.

Plugin Architecture ​

rustledger supports three types of plugins:

TypePerformanceUse Case
Native RustFastestBuilt-in plugins, core functionality
WASMFastCustom plugins, external development
PythonSlow (10-100x)Legacy compatibility, migration path
┌─────────────────────────────────────────────────────────┐
│                    Beancount File                       │
│  plugin "beancount.plugins.auto_accounts"               │
│  plugin "my_custom_plugin.wasm"                         │
└─────────────────────────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────┐
│                   Plugin Loader                         │
│  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐       │
│  │   Native    │ │    WASM     │ │   Python    │       │
│  │  Registry   │ │   Runtime   │ │   Runtime   │       │
│  │  (33 plugins)│ │ (Wasmtime)  │ │(CPython-WASI)│      │
│  └─────────────┘ └─────────────┘ └─────────────┘       │
└─────────────────────────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────┐
│              Plugin Interface (PluginInput)             │
│  - directives: Vec<DirectiveWrapper>                    │
│  - options: PluginOptions                               │
│  - config: Option<String>                               │
└─────────────────────────────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────┐
│              Plugin Output (PluginOutput)               │
│  - ops: Vec<PluginOp>  (Keep/Modify/Insert/Delete)      │
│  - errors: Vec<PluginError>                             │
└─────────────────────────────────────────────────────────┘

PluginOp is an ordered operation list — not a replacement directive list — so transformed directives can inherit the source span / file_id of the input they came from. See Custom Plugins Guide for the variants and conventions.

Plugin Loading ​

Plugins are specified in your beancount file using the plugin directive:

beancount
; Built-in plugin (by name)
plugin "beancount.plugins.auto_accounts"

; WASM plugin (by path)
plugin "/path/to/my_plugin.wasm"

; Plugin with configuration
plugin "beancount.plugins.split_expenses" "alice bob"

Plugin Execution Order ​

The loader splits plugin execution around booking. Synthesizer plugins that inject directives the pre-booking stream needs (auto_accounts, document_discovery) run BEFORE Early validation and BEFORE booking. Every other plugin runs AFTER booking and BEFORE Late validation so cost-spec-reading plugins (implicit_prices, sellgains, unrealized, etc.) see filled-in cost.number_per values from the booker. Account checks run in Late validation, on what the plugins produced, so a directive a plugin renames or inserts is validated as beancount validates it.

The full pipeline is:

sort → synth-plugins → Early validation → booking
     → regular-plugins → Late validation → finalize

Native plugins declare their pass by implementing exactly one of two marker subtraits — SynthPlugin or RegularPlugin — both of which extend the base NativePlugin capability. The registry stores them in two separately-typed Vecs, and the loader looks up the right kind via find_synth / find_regular. The loader uses the PluginPass enum (PreBookingSynth, PostBooking) to select which subset of plugins to run on each pass. Callers that operate on already-booked input (LSP / FFI / standalone tests) invoke run_plugins twice — once per pass — matching the loader's own pipeline.

Within each pass, plugins still execute in the order they appear in your file. This matters because:

  • Transformation plugins modify directives that subsequent plugins see
  • Validation plugins should typically run after transformation plugins
beancount
; auto_accounts is a synthesizer — runs pre-booking, regardless of
; ordering with other plugins. Listed first by convention.
plugin "beancount.plugins.auto_accounts"

; Post-booking pass: implicit_prices reads booked cost specs.
plugin "beancount.plugins.implicit_prices"

; Post-booking pass: validation plugins run last.
plugin "beancount.plugins.check_commodity"
plugin "beancount.plugins.noduplicates"

Using Plugins ​

Enable plugins in your beancount file:

beancount
plugin "beancount.plugins.auto_accounts"
plugin "beancount.plugins.implicit_prices"

Built-in Plugins ​

rustledger includes 33 native plugins. Here are the most commonly used:

Validation Plugins ​

PluginDescription
check_average_costValidate sales use correct average cost
check_closingZero balance assertion on posting with closing: TRUE
check_commodityEnsure commodities are declared
check_drainedZero balance assertion on balance sheet account close
check_option_assignmentCheck an assigned short option's stock basis or proceeds
check_option_expiryError on option contracts open past expiry
coherent_costA currency is held at cost everywhere or nowhere
commodity_attrValidate commodity metadata attributes
leafonlyRestrict postings to leaf accounts
noduplicatesDetect duplicate directives
nounusedWarn about unused accounts
onecommodityOne commodity per account
pedanticStrict validation rules
unique_pricesOne price per commodity per day

Transformation Plugins ​

PluginDescription
auto_accountsAuto-generate Open directives
auto_tagAuto-tag transactions by account patterns
box_accrualSplit capital losses across multiple years
close_treeRecursively close account trees
currency_accountsAuto-generate currency trading postings
document_discoveryAuto-discover documents from directories
effective_dateMove postings to effective dates
forecastGenerate recurring transactions
generate_base_ccy_pricesGenerate base currency prices from FX rates
implicit_pricesGenerate prices from transactions
long_shortClassify capital gains as short/long term
gain_lossClassify capital gains as gains/losses
rename_accountsRename accounts using regex patterns
rx_txn_pluginSet defaults for Regular Expected Transactions
sellgainsAuto-generate capital gains postings
split_expensesSplit shared expenses
unrealizedCalculate unrealized gains/losses
valuationTrack opaque fund values
zerosumMatch zero-sum postings within date ranges

All Built-in Plugins ​

Complete list of 33 native plugins
PluginDescription
auto_accountsAuto-generate Open directives
auto_tagAutomatically tag transactions
box_accrualAccrual accounting for boxed periods
gain_lossSplit capital gains into gain/loss accounts
long_shortSplit capital gains by holding period
check_average_costValidate average cost bookings
check_closingZero balance on account close
check_commodityValidate commodity declarations
check_drainedEnsure accounts drained before close
check_option_assignmentCheck an assigned short option's stock basis or proceeds
check_option_expiryError on option contracts open past expiry
close_treeClose descendant accounts
coherent_costHeld at cost everywhere or nowhere
commodity_attrValidate commodity attributes
currency_accountsAuto-generate currency trading postings
document_discoveryAuto-discover documents from directories
effective_dateOverride posting date via metadata
forecastGenerate recurring transactions
generate_base_ccy_pricesCreate base currency price entries
implicit_pricesGenerate prices from costs
leafonlyError on non-leaf account postings
noduplicatesDetect duplicate directives
nounusedWarn on unused accounts
onecommoditySingle commodity per account
pedanticEnable all strict validations
rename_accountsRename accounts via metadata
rx_txn_pluginLink related transactions
sellgainsCross-check capital gains
split_expensesSplit expenses across accounts
unique_pricesOne price per day per pair
unrealizedCalculate unrealized gains
valuationMark-to-market valuation
zerosumGroup transactions that sum to zero

Plugin Details ​

auto_accounts ​

Automatically generates Open directives for any account a transaction, balance, pad, note, document or close names without one, dated at its first use.

beancount
plugin "beancount.plugins.auto_accounts"

; No need for explicit Open directives
2024-01-15 * "Coffee"
  Expenses:Food:Coffee   5.00 USD
  Assets:Cash           -5.00 USD

Options: None

check_commodity ​

Ensures all commodities are explicitly declared. Each undeclared currency is one error, Missing Commodity directive for 'USD' in 'Assets:Bank', naming the first account (in sorted order) that uses it in a posting's units, cost or price, a balance, or an open's currency list, or Price Directive Context when only price directives use it.

beancount
plugin "beancount.plugins.check_commodity"

2020-01-01 commodity USD
2020-01-01 commodity AAPL

Options: optionally a Python dict of account regex to currency regex, as in beancount: a currency matching the second in an account matching the first (both matched at the start) is exempt, and so are its prices.

beancount
plugin "beancount.plugins.check_commodity" "{'Assets:Options:.*': 'SPX_.*'}"

coherent_cost ​

Checks that each currency is held either always at cost or never at cost. A currency some posting holds at cost ({...}) and another holds without one is an error, Currency 'HOOL' is used both with and without cost, located at the first transaction holding it without cost.

beancount
plugin "beancount.plugins.coherent_cost"

Options: None

implicit_prices ​

Generates price directives from transaction costs.

beancount
plugin "beancount.plugins.implicit_prices"

2024-01-15 * "Buy stock"
  Assets:Brokerage   10 AAPL {150.00 USD}
  Assets:Cash       -1500.00 USD

; Generates:
; 2024-01-15 price AAPL 150.00 USD

Options: None

leafonly ​

Restricts postings to leaf accounts only. Reports an error if you post to an account that has sub-accounts: one per account, Non-leaf account 'Expenses' has postings on it, at its open. A pad counts as posting to both its accounts.

Unlike beancount, a note, document, close or custom naming a parent account is not reported: none of them posts anything.

beancount
plugin "beancount.plugins.leafonly"
beancount
; ERROR: Cannot post to parent account
2024-01-15 * "Coffee"
  Expenses   5.00 USD    ; Error if Expenses:Food exists
  Assets:Cash

; OK: Posting to leaf account
2024-01-15 * "Coffee"
  Expenses:Food:Coffee   5.00 USD
  Assets:Cash

Options: None

noduplicates ​

Detects duplicate directives of every type but price, as beancount's does. Two directives are duplicates when every field but their metadata is equal: a transaction's flag, payee, narration, tags, links and postings; an open's account, currencies and booking method; a balance's account, amount and tolerance; a note's or document's account, text or path, tags and links; and so on. Tags, links, an open's currencies, a custom directive's values and a transaction's postings are compared without regard to order, and a total price is compared as the per-unit price it stands for (2 HOOL @@ 10 USD is 2 HOOL @ 5 USD). Numbers keep their scale (10 USD is not 10.00 USD), as in beancount. A repeated price is allowed: a price source commonly repeats one for a day the market was closed. Each later copy is an error at the copy, naming it: Duplicate entry: 2024-01-02 "Lunch" for a transaction, Duplicate entry: 2024-01-04 note Assets:Bank "hello" for another directive.

Deliberate differences from beancount, which hashes the text of each field: beancount follows Duplicate entry: with both entries' Python representations; it does not compare the directive's type, so an event "a" "b" and a query "a" "b" on one date are duplicates there and not here; and it rounds the division of a total price or total cost to 28 digits, so 3 HOOL @@ 10 USD is a duplicate of 3 HOOL @ 3.333333333333333333333333333 USD there, while here a total that the per-unit number does not multiply back to exactly is compared as written.

beancount
plugin "beancount.plugins.noduplicates"

Options: None

onecommodity ​

Ensures each account only holds one commodity: its postings' and balance assertions' units in one currency, and its costs in one currency. An account with more is one error, More than one currency in account 'Assets:Bank': EUR,USD (or More than one cost currency ...), at the last entry that added a currency. An account whose open lists more than one currency, or has onecommodity: FALSE, is skipped.

beancount
plugin "beancount.plugins.onecommodity"

2020-01-01 open Assets:Bank:USD   USD
2020-01-01 open Assets:Bank:EUR   EUR

Options: optionally a regular expression: only accounts whose open it matches (at the start) are checked.

pedantic ​

Runs every pedantic plugin, as beancount's does, in its order: check_commodity, coherent_cost, leafonly, noduplicates, nounused, onecommodity, sellgains, unique_prices, then check_drained, each without a config.

beancount
plugin "beancount.plugins.pedantic"

Options: None

sellgains ​

Cross-checks a sale's proceeds against its price. For a transaction whose postings at cost all have a price, the priced value of those postings must match the weight of the transaction's Assets, Liabilities, Equity and Expenses postings (Income, the gain, is left out), within twice the transaction's tolerance. This catches a typo in the proceeds when the gain is elided. The tolerance uses beancount's default tolerance options (inferred_tolerance_default and the other tolerance options are not passed to plugins), and, unlike beancount's, counts the precision of a posting booking interpolated.

beancount
plugin "beancount.plugins.sellgains"

2024-01-15 * "Sell AAPL"
  Assets:Brokerage  -10 AAPL {150.00 USD} @ 175.00 USD
  Assets:Cash       1760.00 USD
  Income:CapitalGains
; Error: Invalid price vs. proceeds/gains: (1750.00 USD) vs. (1760.00 USD); difference: (-10.00 USD)

Options: None

split_expenses ​

Splits expenses among multiple people.

beancount
plugin "beancount.plugins.split_expenses" "mark,john 50,50"

2024-01-15 * "Dinner" #shared
  Expenses:Food      100.00 USD
  Assets:Cash

Options: "person1,person2 share1,share2"

unique_prices ​

Ensures prices of one commodity pair on one day agree. Prices that disagree are one error, Disagreeing price entries; a repeated price with the same value is allowed, as in beancount.

beancount
plugin "beancount.plugins.unique_prices"

Options: None


Additional Plugins ​

auto_tag ​

Automatically tags transactions based on account patterns.

beancount
plugin "beancount.plugins.auto_tag" "{'Expenses:Food:.*': 'food', 'Expenses:Transport:.*': 'transport'}"

2024-01-15 * "Coffee"
  Expenses:Food:Coffee   5.00 USD
  Assets:Cash
; Automatically gets #food tag

Options: Python dict mapping regex patterns to tag names.

box_accrual ​

Splits capital losses across multiple years based on synthetic_loan_expiry metadata. Used for tax purposes when losses must be recognized proportionally.

beancount
plugin "beancount.plugins.box_accrual"

2024-07-01 * "Sell synthetic"
  synthetic_loan_expiry: 2026-06-30
  Assets:Broker           1000 USD
  Income:Capital-Losses   -365 USD
; Splits the loss across 2024, 2025, 2026 proportionally

Options: None

check_average_cost ​

For accounts opened with the NONE booking method, checks that each reducing posting's cost is within the tolerance of the account's average cost before it. The average is of what the account holds, each sale included at the cost it was booked at, as beancount keeps it. Reports beancount's error at the transaction.

beancount
plugin "beancount.plugins.check_average_cost" "0.01"

; Buy 10 @ $100, then 10 @ $120 -> average = $110
; Selling at $100 cost:
; Error: Cost basis on reducing posting is too far from the average cost (100 vs. 110)

Options: Tolerance as a Python float (default: 0.01 = 1%); anything else is an error.

close_tree ​

Automatically closes all descendant accounts when a parent account is closed.

beancount
plugin "beancount.plugins.close_tree"

2024-01-01 open Assets:Bank
2024-01-01 open Assets:Bank:Checking
2024-01-01 open Assets:Bank:Savings

2024-12-31 close Assets:Bank
; Automatically generates:
; 2024-12-31 close Assets:Bank:Checking
; 2024-12-31 close Assets:Bank:Savings

Options: None

check_closing ​

Inserts zero balance assertions when a posting has a truthy closing metadata value (TRUE, a non-empty string, a non-zero number or amount), and removes the closing key from the posting. The assertion is dated one day after the transaction.

beancount
plugin "beancount.plugins.check_closing"

2024-12-31 * "Close out position"
  Assets:Broker:AAPL  -10 AAPL {100 USD}
    closing: TRUE
  Assets:Cash          1000 USD
; Generates: 2025-01-01 balance Assets:Broker:AAPL 0 AAPL

Options: None

check_drained ​

Inserts zero balance assertions when balance sheet accounts (Assets, Liabilities, Equity) are closed. The assertion is dated one day after the close directive.

beancount
plugin "beancount.plugins.check_drained"

2024-01-01 open Assets:Bank USD
2024-12-31 close Assets:Bank
; Generates: 2025-01-01 balance Assets:Bank 0 USD

Options: None

check_option_assignment ​

Checks the stock leg when a short option is assigned. For a short put, the stock's basis must be strike × shares − premium. For a short call, the sale proceeds must be strike × shares + premium. Options are recognized by OCC symbol, as for check_option_expiry.

An assignment is a transaction that reduces a short option position and also moves the option's root commodity (stock rises for a put, falls for a call). Puts and calls on one root are separate, so a put assigned in the same entry as a call bought back is still checked. Ordinary closes, long options, cash-settled index options, assignments split across two transactions, and shorts held without a cost (-1 AAPL261016P00225000 @ 3.00 USD, so the premium is unknown) are not checked. Each assignment gets at most one error, from the first rule that fails:

  1. Stock units = 100 × contracts.
  2. The option leg is closed at cost (no gain realized on it). Closing it at @ 0.00 USD counts as realizing the premium, as in sellgains.
  3. Basis (put) or proceeds (call) match within half a cent per share, compared as totals across all lots. A put's stock leg needs a cost and a call's a price; when an assigned call opens a short stock position (no stock held in that account before), the short lot's cost is its proceeds.

Each rule runs when its own arithmetic fits in the supported decimal range (about ±7.9e28): the share count needs only contracts × 100, so it is still checked when strike × shares does not fit. When a rule cannot run for that reason, and no earlier rule failed, the assignment gets an error instead of passing: AAPL261016P99999999 assignment not checked: amounts exceed the supported decimal range.

Units count contracts: 1 unit is 1 contract, and the cost per unit is the premium × 100 (-1 AAPL261016P00225000 {300.00 USD} for a 3.00 premium). A ledger that records options in share units (-100 … {3.00 USD}) gets a share-count error from this plugin.

beancount
plugin "beancount_options.check_option_assignment"

2026-01-01 open Assets:Broker:Cash USD
2026-01-01 open Assets:Broker:Stock AAPL
2026-01-01 open Assets:Broker:Options
2026-01-01 open Income:Trading:Gains

2026-09-03 * "Sell to open 1 AAPL 2026-10-16 225 put @ 3.00"
  Assets:Broker:Options  -1 AAPL261016P00225000 {300.00 USD}
  Assets:Broker:Cash     300.00 USD

2026-10-16 * "Assigned: buy 100 AAPL at 225, premium booked as income"
  Assets:Broker:Options   1 AAPL261016P00225000 {}
  Assets:Broker:Stock   100 AAPL {225.00 USD}
  Assets:Broker:Cash  -22500.00 USD
  Income:Trading:Gains   -300.00 USD
; Error: AAPL261016P00225000 assignment: AAPL basis 22500.00 USD, expected 22200.00 USD (strike 225 × 100 − premium 300.00)

The correct entry drops the income line and writes the stock lot as {222.00 USD}.

Its Python counterpart in beancount-options is not released yet, so until it is, bean-check and Fava fail on this plugin line. To keep a file portable meanwhile, leave the line out and enable the plugin on the command line: rledger check --native-plugin check_option_assignment ledger.beancount.

Options: None. A config string gives a warning and is ignored.

check_option_expiry ​

Reports an error for each option contract whose net position in an account is non-zero after its expiry date. Contracts are recognized by their OCC symbol with spaces removed: a root of 1–6 capital letters, digits or dots starting with a letter (adjusted roots such as XYZ1 are checked too), the expiry as YYMMDD, C or P, and the strike × 1000 as 8 digits (AAPL261016P00230000 is the AAPL 2026-10-16 230 put). Other commodities are ignored.

"Today" is the date of the last directive of any kind in the ledger, so the check is deterministic. A close dated on the expiry day is accepted, and a ledger that ends on or before expiry is not reported. Each transaction's legs on one contract are netted before they apply, and the error is located at the transaction that opened the position still open (the last one that moved it off zero or across it). Same-day entries are taken in beancount's order: by date, then by directive type (open first, then balance, then transactions and every other type, then document, then close), then by line number, whatever the file. So with trades split across included files the error names the entry bean-check names. Units count contracts: -1 is one short contract, as for check_option_assignment. The plugin only reports; it never inserts or changes directives.

beancount
plugin "beancount_options.check_option_expiry"

2026-01-01 open Assets:Broker:Cash USD
2026-01-01 open Assets:Broker:Options

2026-09-02 * "Sell to open 1 AAPL 2026-10-16 230 put"
  Assets:Broker:Options  -1 AAPL261016P00230000 {250.00 USD}
  Assets:Broker:Cash     250.00 USD

2026-10-20 balance Assets:Broker:Cash 250.00 USD
; Error: AAPL261016P00230000 expired 2026-10-16 but -1 contract(s) remain open in Assets:Broker:Options

Its Python counterpart is beancount_options.check_option_expiry in beancount-options (pip install git+https://github.com/rustledger/beancount-options). rledger matches a native plugin by the last part of the name, so the same plugin line runs the native plugin under rledger and the Python one under bean-check and Fava, with the same messages at the same lines.

Options: an optional dict literal, "{'as_of': 'YYYY-MM-DD'}", which sets "today" instead of the last directive's date. Entries dated after as_of are ignored, so a forecast or scheduled transaction neither moves "today" forward nor closes a position early. Entries dated on as_of count. A contract that expired before as_of is reported even when the ledger has no later entry; one expiring on as_of is fine.

beancount
plugin "beancount_options.check_option_expiry" "{'as_of': '2026-10-20'}"

2026-01-01 open Assets:Broker:Cash USD
2026-01-01 open Assets:Broker:Options
2026-01-01 open Income:Options

2026-09-02 * "Sell to open 1 AAPL 2026-10-16 230 put"
  Assets:Broker:Options  -1 AAPL261016P00230000 @ 2.50 USD
  Assets:Broker:Cash     2.50 USD

2026-11-20 * "Forecast: buy to close"
  Assets:Broker:Options   1 AAPL261016P00230000 @ 0.00 USD
  Income:Options
; Error: AAPL261016P00230000 expired 2026-10-16 but -1 contract(s) remain open in Assets:Broker:Options

No config, a blank one (ASCII whitespace only) and {} keep the default rules. Any other config that is not exactly that dict gives one error, Invalid configuration for check_option_expiry plugin: <problem>; skipping., located at <check_option_expiry>:0, and the plugin then reports nothing else. The problems are checked in this order: not a dict (expected a dict such as {'as_of': '2026-10-16'}), a key that is not a string (keys must be strings), the first other key (unknown key 'asof'), a value that is not a string (as_of must be a string), and a date not written YYYY-MM-DD or not a real date (as_of must be a date written YYYY-MM-DD, not '2026-02-30'). A repeated key takes its last value. A key or value is quoted back only when it is 1–40 printable ASCII characters with no ', " or \. These are beancount-options' rules, and rustledger's tests run its shared config cases. A few configs nobody would write read differently, because Python's literal_eval accepts or rejects them where rledger's reader does not: \N{...} escapes, complex numbers, and lists, sets or dicts used as keys or set elements.

--native-plugin passes no config, so as_of needs the plugin line.

commodity_attr ​

Validates that Commodity directives have required metadata attributes.

beancount
plugin "beancount.plugins.commodity_attr" "{'name': None, 'sector': ('Tech', 'Finance', 'Healthcare')}"

2024-01-01 commodity AAPL
  name: "Apple Inc"
  sector: "Tech"

Options: Python dict where:

  • Keys are attribute names
  • None means required but any value allowed (null is accepted too)
  • a tuple, list or set such as ('a', 'b') means required and must be one of the listed values

A missing attribute is Missing attribute 'name' for Commodity directive AAPL, and a value not listed is Invalid value 'x' for attribute sector, Commodity directive AAPL; valid options: Tech, Finance, Healthcare, each at the commodity directive.

currency_accounts ​

Automatically generates currency conversion postings through trading accounts when transactions involve multiple currencies. For when to choose this style and a worked example, see Currency Accounts in the Cookbook.

beancount
plugin "beancount.plugins.currency_accounts"

2024-01-15 * "Buy EUR"
  Assets:Bank:EUR    100 EUR @ 1.10 USD
  Assets:Bank:USD   -110 USD
; Generates postings through Equity:CurrencyAccounts:EUR and Equity:CurrencyAccounts:USD

Options: The base account (default Equity:CurrencyAccounts; a value that is not a valid account name falls back to it; beancount 3's plugin fails without a config, rledger's uses the default). A processed transaction is marked currency_accounts_processed: TRUE.

document_discovery ​

Auto-discovers document files from directories. Scans directories specified in option "documents" for files matching the pattern {Account}/YYYY-MM-DD.description.*.

beancount
option "documents" "/path/to/documents"
plugin "beancount.plugins.document_discovery"

; File: /path/to/documents/Assets/Bank/Checking/2024-01-15.statement.pdf
; Generates:
; 2024-01-15 document Assets:Bank:Checking "/path/to/documents/Assets/Bank/Checking/2024-01-15.statement.pdf"

Options: None (uses option "documents" paths)

effective_date ​

Moves postings to their effective date using holding accounts. Add effective_date metadata to defer recognition.

beancount
plugin "beancount.plugins.effective_date"

2024-01-15 * "Invoice"
  Income:Consulting  -1000 USD
    effective_date: 2024-02-15
  Assets:Receivable   1000 USD
; Creates a holding entry until 2024-02-15

Options: None

forecast ​

Generates recurring transactions from templates. Use pattern syntax in the narration to specify recurrence.

beancount
plugin "beancount.plugins.forecast"

2024-01-01 # "Rent [MONTHLY]"
  Expenses:Rent      2000 USD
  Assets:Checking   -2000 USD

2024-01-01 # "Gym [WEEKLY REPEAT 12 TIMES]"
  Expenses:Gym        50 USD
  Assets:Cash        -50 USD

Patterns:

  • [MONTHLY] - Repeat monthly indefinitely
  • [WEEKLY] - Repeat weekly indefinitely
  • [DAILY] - Repeat daily indefinitely
  • [MONTHLY REPEAT N TIMES] - Repeat N times
  • [WEEKLY SKIP 2] - Repeat every 2 weeks
  • [MONTHLY UNTIL 2024-12-31] - Repeat until date

Options: None

gain_loss ​

Classifies capital gains transactions as gains or losses. Adds metadata gain_loss: "gain" or gain_loss: "loss" to transactions.

beancount
plugin "beancount.plugins.gain_loss"

2024-01-15 * "Sell AAPL"
  Assets:Brokerage  -10 AAPL {100 USD} @ 150 USD
  Assets:Cash        1500 USD
  Income:CapitalGains
; Transaction gets gain_loss: "gain" metadata

Options: None

generate_base_ccy_prices ​

Generates price entries in a base currency by applying exchange rates to existing prices.

beancount
plugin "beancount.plugins.generate_base_ccy_prices" "USD"

2024-01-01 price EUR 1.10 USD
2024-01-01 price ETH 2000 EUR
; Generates: 2024-01-01 price ETH 2200 USD (2000 * 1.10)

Options: Base currency code (e.g., "USD")

long_short ​

Rebooks capital gains into short-term and long-term accounts, lot by lot, by holding period, as beancount_reds_plugins.capital_gains_classifier.long_short does. A lot is long-term when the sale falls after its one-year anniversary (a Feb 29 acquisition's anniversary is Feb 28), the rule rledger report capgains uses. Closing a written option or any short position — a reduction posting with positive units — is always short-term whatever its holding period (US IRC 1234(b), and 1233(a) for short sales), the rule rledger report capgains applies and a deliberate divergence from the Python plugin, which books it by holding period like a sale. A cover needs no cost date; a sale of a long lot without one is left unchanged. Accounts it books to that the ledger doesn't open are opened for you.

beancount
plugin "beancount_reds_plugins.capital_gains_classifier.long_short" "{
  'Income.*:Capital-Gains': [':Capital-Gains', ':Capital-Gains:Short', ':Capital-Gains:Long']
}"

2023-01-01 open Assets:Brokerage
2023-01-01 open Assets:Cash
2023-01-01 open Income:Capital-Gains

2023-01-10 * "Buy AAPL"
  Assets:Brokerage   10 AAPL {100 USD}
  Assets:Cash     -1000 USD

2024-03-01 * "Buy AAPL"
  Assets:Brokerage   10 AAPL {120 USD}
  Assets:Cash     -1200 USD

2024-06-03 * "Sell AAPL"
  Assets:Brokerage  -10 AAPL {100 USD, 2023-01-10} @ 150 USD
  Assets:Brokerage  -10 AAPL {120 USD, 2024-03-01} @ 150 USD
  Assets:Cash        3000 USD
  Income:Capital-Gains
; Income:Capital-Gains becomes:
;   Income:Capital-Gains:Short  -300 USD   (2024 lot, held under a year)
;   Income:Capital-Gains:Long   -500 USD   (2023 lot)

Options: required, a dict {'account_regex': ['to_replace', 'short_replacement', 'long_replacement']}. Postings to accounts matching account_regex are replaced, with to_replace in the account name swapped for short_replacement or long_replacement. Without a config the plugin changes nothing.

nounused ​

Reports an error, at its open, for each account that is opened but never named by any other directive (a transaction, balance, pad, note, document or close). Unlike beancount's, an account named only by a custom directive counts as used.

beancount
plugin "beancount.plugins.nounused"

2024-01-01 open Assets:OldAccount
; Error: Unused account 'Assets:OldAccount'

Options: None

rename_accounts ​

Renames accounts using regex patterns. Useful for bulk account reorganization.

beancount
plugin "beancount.plugins.rename_accounts" "{'Expenses:Food:(.*)': 'Expenses:Dining:\\\\1'}"

2024-01-01 open Expenses:Food:Groceries
; Becomes: 2024-01-01 open Expenses:Dining:Groceries

Options: Python dict mapping regex patterns to replacement strings, applied as Python's re.sub applies them: every match anywhere in the account name is replaced, and the replacement refers to a group as \1 or \g<name> ($1 is literal text). The beancount string and the Python string literal each consume one level of backslashes, so \1 is written \\\\1 in the file (or r'...\\1' with a raw Python string).

Regular expressions in plugin configs (rename_accounts, check_commodity, onecommodity, long_short, gain_loss) are read as Python's re reads them. A construct Python supports and rledger cannot express (lookahead and lookbehind, backreferences, conditional and atomic groups, possessive quantifiers, \N{...} and the (?x) flag) is reported as an error naming the plugin and the construct, never matched differently. So is a rename_accounts pattern that can match the empty string, or that repeats something able to match empty: Python's re.sub substitutes those differently. With (?i), case-insensitive matching of non-ASCII characters follows Unicode simple case folding, which differs from Python's for a few characters (Python matches i with the dotless ı). \b and \B are word boundaries, matched as Python matches them except on an account or currency holding one of the characters Python and rledger classify differently as word characters (a separately written combining accent, say), which the plugin reports as an error naming the character instead of matching; (?a)\b, the ASCII word boundary, never does. See the BQL reference.

rx_txn_plugin ​

Sets default metadata for Regular Expected Transactions (for beanahead integration). Transactions tagged #rx_txn get default final: None and roll: True metadata.

beancount
plugin "beancount.plugins.rx_txn_plugin"

2024-01-15 * "Monthly rent" #rx_txn
  Expenses:Rent      2000 USD
  Assets:Checking
; Gets metadata: final: None, roll: True

Options: None

unrealized ​

Calculates unrealized gains and losses for positions at market value.

beancount
plugin "beancount.plugins.unrealized" "Income:Unrealized"

2024-01-01 price AAPL 150 USD
; For positions bought at $100, generates unrealized gain entries

Options: Account for unrealized gains (e.g., "Income:Unrealized")

valuation ​

Tracks opaque fund values using synthetic commodities. Useful for retirement accounts or funds that don't provide per-share NAV.

beancount
plugin "beancount.plugins.valuation"

2024-01-01 * "401k contribution"
  Assets:401k:Fund    100 FUND401K {50 USD}
  Assets:Checking    -5000 USD

2024-06-30 custom "valuation" Assets:401k:Fund 6000 USD
; Creates synthetic position reflecting current value

Options: None

zerosum ​

Matches pairs of postings that sum to zero within a date range. Useful for tracking reimbursements, loans, or transfers.

beancount
plugin "beancount.plugins.zerosum" "Assets:Reimbursable 30"

2024-01-15 * "Expense to be reimbursed"
  Assets:Reimbursable   100 USD
  Assets:Cash          -100 USD

2024-01-20 * "Reimbursement received"
  Assets:Bank           100 USD
  Assets:Reimbursable  -100 USD
; These two postings match and are linked

Options: "Account:Pattern days" - Account pattern to match and maximum days between matching postings

Custom Plugins ​

For custom functionality, you can write plugins in two ways:

Needs the plugin runtimes

WASM plugins, Python plugins and WASM importers run in builds with the plugin runtimes: cargo install rustledger and source builds. Release binaries (GitHub Releases, Homebrew, Scoop, cargo binstall) leave them out on purpose and report an error naming cargo install rustledger. See Plugin Runtimes. Built-in native plugins run in every build.

Write plugins in Rust, compile to WebAssembly, and use them without modifying rustledger.

Quick start:

bash
# Clone the template
git clone https://github.com/rustledger/rustledger
cp -r rustledger/examples/wasm-plugin-template my-plugin
cd my-plugin

# Build
rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --release

# Use in your beancount file
# plugin "/path/to/target/wasm32-unknown-unknown/release/my_plugin.wasm"

See the Custom Plugins Guide for a complete walkthrough.

Native Rust Plugins (Contributors) ​

For adding plugins to rustledger itself, see Contributing Plugins.

Python Plugin Compatibility ​

Experimental Feature

Python plugin support is experimental and significantly slower than native plugins (10-100x). Use native equivalents when available.

rustledger can run some Python beancount plugins using CPython compiled to WebAssembly (WASI). This is primarily for migration purposes.

Python plugins need a build with the plugin runtimes: cargo install rustledger or a source build. Release binaries leave them out; see Plugin Runtimes.

Referencing a Python Plugin ​

How a plugin name resolves depends on whether it matches a built-in:

  • Built-in name → native implementation. If the name matches a built-in plugin, rustledger runs the native Rust version, regardless of the beancount.plugins. prefix. So plugin "beancount.plugins.auto_accounts" "just works" — it resolves to the native auto_accounts, not to Python. (See Supported Python Plugins.)

  • Custom Python plugin → file path required. A plugin with no native equivalent must be referenced by file path, not by module name. beancount's plugin "mypackage.mymodule" form is not supported:

    beancount
    ; ❌ Not supported — module names do not resolve to the host environment
    plugin "mypackage.mymodule"
    
    ; ✅ Reference the file directly (absolute, or relative to the ledger)
    plugin "/abs/path/to/mymodule.py"
    plugin "./plugins/mymodule.py"

    Referencing a custom plugin by module name fails with … is not supported by module name; reference the file directly: plugin "…". This is intentional: rustledger does not search the system Python path, keeping it explicit which plugins still need native Rust implementations.

Entry Points: __plugins__ ​

rustledger runs a Python plugin file the way beancount's loader runs a plugin module: it calls the functions the module's __plugins__ lists, in order, each on the entries the previous one returned.

python
__plugins__ = ['add_tag', check]   # a name, or the function itself

def add_tag(entries, options_map):
    ...
    return entries, errors

def check(entries, options_map, config):   # config: the directive's string
    ...
    return entries, errors

Each function is called with (entries, options_map), plus the config string when the plugin directive has one (plugin "./my_plugin.py" "config"). An exception in one function is reported as an error, and the next function gets the entries as they were before it, as in beancount.

Two cases are reported where beancount is silent or crashes:

  • No __plugins__: nothing runs (beancount skips such a module silently), and rustledger warns that the plugin ran nothing, since that is almost always a forgotten line rather than a plugin meant to do nothing. A function merely named plugin is not an entry point.
  • A listed name the module does not define: an error naming it, and nothing in the module runs (beancount aborts the whole load with an AttributeError).

The Plugin Sandbox: Plugins Must Be Self-Contained ​

Python plugins run in a pinned CPython-WASI sandbox (wasmtime). On sys.path it sees only:

  • the plugin source file, plus a bundled beancount.core.data compatibility shim, and
  • the bundled CPython standard library.

The plugin sees exactly one directory, read-only: /lib (the standard library). Its inputs (the entries, options and config) reach it from memory, so nothing of the ledger is written to disk while it runs, and an interrupted run (Ctrl-C) leaves nothing behind. It cannot write files, read the ledger's directory or anything else of the host, or open network connections. What it prints goes to rledger's stderr (up to 4 MiB); its result travels back separately, so a print cannot corrupt it.

The host's virtualenv / site-packages is never mounted — there is no VIRTUAL_ENV or site-packages handling, by design (the sandbox has no host filesystem access). So even with the correct file-path reference, a plugin only loads if it is self-contained: standard library plus whatever the compat shim provides.

The compat shim covers the common beancount plugin surface — the beancount.core.data namedtuples (Transaction, Posting, Amount, Open, Close, Balance, Price, Custom, Cost, …), data.new_metadata and data.filter_txns, amount.CURRENCY_RE, the beancount.core.{getters,flags} helpers, beancount.core.realization (the account tree: realize(entries, compute_balance=False), iter_children, get, get_or_create, contains, postings_by_account, RealAccount) and beancount.core.compare (hash_entry, hash_entries, compare_entries, includes_entries, excludes_entries), so beancount's own leafonly and noduplicates run unchanged. Entries carry their metadata, including filename and lineno, as in beancount, and an error a plugin returns (any object with message and source, such as a beancount-style namedtuple) is reported at its entry's location. Modules the shim does not provide, such as beancount.core.inventory, fail with an ImportError naming them; realize with balances (its default, compute_balance=True) needs that module, so it raises NotImplementedError saying to pass compute_balance=False. A plugin that imports third-party packages, C extensions, or unbundled stdlib modules will not load — rewrite it as a native Rust plugin instead.

Built-in Python Plugins ​

check_commodity and leafonly also have Python implementations that behave as beancount's do (same checks, same messages). plugin "python:leafonly" (or "python:beancount.plugins.leafonly") runs that instead of the native plugin. python: before any other bare name is refused, like a module name; before a file path, it runs the file in Python.

Supported Python Plugins ​

Most Python beancount plugins have native equivalents:

Python Pluginrustledger Equivalent
auto_accounts✅ auto_accounts
implicit_prices✅ implicit_prices
check_commodity✅ check_commodity
leafonly✅ leafonly
noduplicates✅ noduplicates
onecommodity✅ onecommodity
sellgains✅ sellgains
split_expenses✅ split_expenses
close_tree✅ close_tree
coherent_cost✅ coherent_cost
pedantic✅ pedantic
unique_prices✅ unique_prices
forecast (beanahead)✅ forecast
effective_date✅ effective_date
zerosum✅ zerosum
unrealized✅ unrealized
rename_accounts✅ rename_accounts
beancount_options.check_option_expiry✅ check_option_expiry
Custom PythonRewrite in Rust

Python Plugin Limitations ​

  • Performance: 10-100x slower than native plugins
  • First run: Downloads ~14MB CPython-WASI runtime
  • Compilation: First execution compiles WASM (~30 seconds)
  • Time budget: each call has the same time budget as a WASM plugin (30 seconds by default), of which starting the interpreter takes about 1.2; a plugin over a very large ledger can need more. See Plugin Time Budget
  • Memory: the interpreter, and every entry as Python objects (about 1.2 KB per transaction), must fit in the sandbox memory cap, 256 MiB by default, which holds roughly 150,000 transactions. Raise it with [plugins] max_memory_mb or --plugin-max-memory-mb. See Plugin Memory Cap
  • Other resources: a plugin may hold at most 256 open files and pending polls (select) at once; it is stopped when it runs past its time budget on the clock, including time spent sleeping
  • Not all plugins work: C extensions and some stdlib modules unavailable
  • File-path references only: custom Python plugins must be referenced by file path and be self-contained — see Referencing a Python Plugin
  • Debugging: Error messages may be less helpful

Migrating from Python Plugins ​

  1. Check if a native equivalent exists (see table above)
  2. If not, consider writing a WASM plugin
  3. As a last resort, Python plugins may work but with limitations

See Also ​