Crate beancount_parser

source ·
Expand description

A parsing library for the beancount language


Use parse to get an instance of BeancountFile.

This is generic over the decimal type. The examples use f64 as a decimal type. You may also use Decimal from the rust_decimal crate.

use beancount_parser::{BeancountFile, DirectiveContent};

let input = r#"
2023-05-20 * "Coffee beans"
  Expenses:Groceries   10 CHF

// Parse into the `BeancountFile` struct:
let beancount: BeancountFile<f64> = input.parse()?;

let directive = &beancount.directives[0];
assert_eq!(, 2023);
assert_eq!(, 5);
assert_eq!(, 20);

let DirectiveContent::Transaction(trx) = &directive.content else {
    panic!("was not a transaction")
assert_eq!(trx.narration.as_deref(), Some("Coffee beans"));
assert_eq!(trx.postings[0].account.as_str(), "Expenses:Groceries");
assert_eq!(trx.postings[0].amount.as_ref().unwrap().value, 10.0);
assert_eq!(trx.postings[0].amount.as_ref().unwrap().currency.as_str(), "CHF");
assert_eq!(trx.postings[1].account.as_str(), "Assets:Checking");
assert_eq!(trx.postings[1].amount, None);





  • Decimal type to which amount values and expressions will be parsed into.


  • Parse the input beancount file and return an instance of BeancountFile on success
  • Parse the beancount file and return an iterator over Result<Entry<D>, Result>
  • Read the files from disk and parse their content.