hledger-lib-0.9: Core types and utilities for working with hledger (or c++ ledger) data.



A compound data type for efficiency. A Ledger caches information derived from a Journal for easier querying. Also it typically has had uninteresting Transactions and Postings filtered out. It contains:

  • the original unfiltered Journal
  • a tree of AccountNames
  • a map from account names to Accounts
  • the full text of the journal file, when available

This is the main object you'll deal with as a user of the Ledger library. The most useful functions also have shorter, lower-case aliases for easier interaction. Here's an example:

 > import Ledger
 > l <- readLedger "sample.ledger"
 > accountnames l
 > accounts l
 [Account assets with 0 txns and $-1 balance,Account assets:bank with...
 > topaccounts l
 [Account assets with 0 txns and $-1 balance,Account expenses with...
 > account l "assets"
 Account assets with 0 txns and $-1 balance
 > accountsmatching ["ch"] l
 accountsmatching ["ch"] l
 [Account assets:bank:checking with 4 txns and $0 balance]
 > subaccounts l (account l "assets")
 subaccounts l (account l "assets")
 [Account assets:bank with 0 txns and $1 balance,Account assets:cash...
 > head $ transactions l
 2008/01/01 income assets:bank:checking $1 RegularPosting
 > accounttree 2 l
 Node {rootLabel = Account top with 0 txns and 0 balance, subForest = [...
 > accounttreeat l (account l "assets")
 Just (Node {rootLabel = Account assets with 0 txns and $-1 balance, ...
 > datespan l -- disabled
 DateSpan (Just 2008-01-01) (Just 2009-01-01)
 > rawdatespan l
 DateSpan (Just 2008-01-01) (Just 2009-01-01)
 > ledgeramounts l
 > commodities l
 [Commodity {symbol = "$", side = L, spaced = False, comma = False, ...



cacheLedger :: Journal -> LedgerSource

Convert a journal to a more efficient cached ledger, described above.

cacheLedger' :: Ledger -> CachedLedgerSource

Add (or recalculate) the cached journal info in a ledger.

type CachedLedger = LedgerSource

Like cacheLedger, but filtering the journal first.

ledgerAccountNames :: Ledger -> [AccountName]Source

List a ledger's account names.

ledgerAccount :: Ledger -> AccountName -> AccountSource

Get the named account from a (cached) ledger. If the ledger has not been cached (with crunchJournal or cacheLedger'), this returns the null account.

ledgerAccounts :: Ledger -> [Account]Source

List a ledger's accounts, in tree order

ledgerTopAccounts :: Ledger -> [Account]Source

List a ledger's top-level accounts, in tree order

ledgerAccountsMatching :: [String] -> Ledger -> [Account]Source

Accounts in ledger whose name matches the pattern, in tree order.

ledgerSubAccounts :: Ledger -> Account -> [Account]Source

List a ledger account's immediate subaccounts

ledgerPostings :: Ledger -> [Posting]Source

List a ledger's postings, in the order parsed.

ledgerAccountTree :: Int -> Ledger -> Tree AccountSource

Get a ledger's tree of accounts to the specified depth.

ledgerAccountTreeAt :: Ledger -> Account -> Maybe (Tree Account)Source

Get a ledger's tree of accounts rooted at the specified account.

ledgerDateSpan :: Ledger -> DateSpanSource

The (fully specified) date span containing all the ledger's (filtered) transactions, or DateSpan Nothing Nothing if there are none.

accountnames :: Ledger -> [AccountName]Source

Convenience aliases.