beancount.ops

Operations on the entries defined in the core modules.

This package contains various functions which operate on lists of entries.

beancount.ops.balance

Automatic padding of gaps between entries.

class beancount.ops.balance.BalanceError(source, message, entry)
beancount.ops.balance.check(entries, options_map)

Process the balance assertion directives.

For each Balance directive, check that their expected balance corresponds to the actual balance computed at that time and replace failing ones by new ones with a flag that indicates failure.

Parameters
  • entries – A list of directives.

  • options_map – A dict of options, parsed from the input file.

Returns

A pair of a list of directives and a list of balance check errors.

beancount.ops.balance.get_balance_tolerance(balance_entry, options_map)

Get the tolerance amount for a single entry.

Parameters
  • balance_entry – An instance of data.Balance

  • options_map – An options dict, as per the parser.

Returns

A Decimal, the amount of tolerance implied by the directive.

beancount.ops.basicops

Basic filteirng and aggregration operations on lists of entries.

This module contains some common basic operations on entries that are complex enough not to belong in core/data.py.

Yield all the entries which have the given link.

Parameters

link – A string, the link we are interested in.

Yields

Every entry in ‘entries’ that links to ‘link.

beancount.ops.basicops.filter_tag(tag, entries)

Yield all the entries which have the given tag.

Parameters

tag – A string, the tag we are interested in.

Yields

Every entry in ‘entries’ that tags to ‘tag.

beancount.ops.basicops.get_common_accounts(entries)

Compute the intersection of the accounts on the given entries.

Parameters

entries – A list of Transaction entries to process.

Returns

A set of strings, the names of the common accounts from these entries.

Group the list of entries by link.

Parameters

entries – A list of directives/transactions to process.

Returns

A dict of link-name to list of entries.

beancount.ops.compress

Compress multiple entries into a single one.

This can be used during import to compress the effective output, for accounts with a large number of similar entries. For example, I had a trading account which would pay out interest every single day. I have no desire to import the full detail of these daily interests, and compressing these interest-only entries to monthly ones made sense. This is the code that was used to carry this out.

beancount.ops.compress.compress(entries, predicate)

Compress multiple transactions into single transactions.

Replace consecutive sequences of Transaction entries that fulfill the given predicate by a single entry at the date of the last matching entry. ‘predicate’ is the function that determines if an entry should be compressed.

This can be used to simply a list of transactions that are similar and occur frequently. As an example, in a retail FOREX trading account, differential interest of very small amounts is paid every day; it is not relevant to look at the full detail of this interest unless there are other transactions. You can use this to compress it into single entries between other types of transactions.

Parameters
  • entries – A list of directives.

  • predicate – A callbable which accepts an entry and return true if the entry is intended to be compressed.

Returns

A list of directives, with compressible transactions replaced by a summary equivalent.

beancount.ops.compress.merge(entries, prototype_txn)

Merge the postings of a list of Transactions into a single one.

Merge postings the given entries into a single entry with the Transaction attributes of the prototype. Return the new entry. The combined list of postings are merged if everything about the postings is the same except the number.

Parameters
  • entries – A list of directives.

  • prototype_txn – A Transaction which is used to create the compressed Transaction instance. Its list of postings is ignored.

Returns

A new Transaction instance which contains all the postings from the input entries merged together.

beancount.ops.documents

Everything that relates to creating the Document directives.

class beancount.ops.documents.DocumentError(source, message, entry)
beancount.ops.documents.find_documents(directory, input_filename, accounts_only=None, strict=False)

Find dated document files under the given directory.

If a restricting set of accounts is provided in ‘accounts_only’, only return entries that correspond to one of the given accounts.

Parameters
  • directory – A string, the name of the root of the directory hierarchy to be searched.

  • input_filename – The name of the file to be used for the Document directives. This is also used to resolve relative directory names.

  • accounts_only – A set of valid accounts strings to search for.

  • strict – A boolean, set to true if you want to generate errors on documents found in accounts not provided in accounts_only. This is only meaningful if accounts_only is specified.

Returns

A list of new Document objects that were created from the files found, and a list of new errors generated.

beancount.ops.documents.process_documents(entries, options_map)

Check files for document directives and create documents directives automatically.

Parameters
  • entries – A list of all directives parsed from the file.

  • options_map – An options dict, as is output by the parser. We’re using its ‘filename’ option to figure out relative path to search for documents.

Returns

A pair of list of all entries (including new ones), and errors generated during the process of creating document directives.

beancount.ops.documents.verify_document_files_exist(entries, unused_options_map)

Verify that the document entries point to existing files.

Parameters
  • entries – a list of directives whose documents need to be validated.

  • unused_options_map – A parser options dict. We’re not using it.

Returns

The same list of entries, and a list of new errors, if any were encountered.

beancount.ops.holdings

Compute final holdings for a list of entries.

class beancount.ops.holdings.Holding(account, number, currency, cost_number, cost_currency, book_value, market_value, price_number, price_date)
beancount.ops.holdings.aggregate_holdings_by(holdings, keyfun)

Aggregate holdings by some key.

Note that the cost-currency must always be included in the group-key (sums over multiple currency units do not make sense), so it is appended to the sort-key automatically.

Parameters

keyfun – A callable, which returns the key to aggregate by. This key need not include the cost-currency.

Returns

A list of aggregated holdings.

beancount.ops.holdings.aggregate_holdings_list(holdings)

Aggregate a list of holdings.

If there are varying ‘account’, ‘currency’ or ‘cost_currency’ attributes, their values are replaced by ‘*’. Otherwise they are preserved. Note that all the cost-currency values must be equal in order for aggregations to succeed (without this constraint a sum of units in different currencies has no meaning).

Parameters

holdings – A list of Holding instances.

Returns

A single Holding instance, or None, if there are no holdings in the input list.

Raises

ValueError – If multiple cost currencies encountered.

beancount.ops.holdings.convert_to_currency(price_map, target_currency, holdings_list)

Convert the given list of holdings’s fields to a common currency.

If the rate is not available to convert, leave the fields empty.

Parameters
  • price_map – A price-map, as built by prices.build_price_map().

  • target_currency – The target common currency to convert amounts to.

  • holdings_list – A list of holdings.Holding instances.

Returns

A modified list of holdings, with the ‘extra’ field set to the value in ‘currency’, or None, if it was not possible to convert.

beancount.ops.holdings.get_commodities_at_date(entries, options_map, date=None)

Return a list of commodities present at a particular date.

This routine fetches the holdings present at a particular date and returns a list of the commodities held in those holdings. This should define the list of price date points required to assess the market value of this portfolio.

Notes:

  • The ticker symbol will be fetched from the corresponding Commodity directive. If there is no ticker symbol defined for a directive or no corresponding Commodity directive, the currency is still included, but ‘None’ is specified for the symbol. The code that uses this routine should be free to use the currency name to make an attempt to fetch the currency using its name, or to ignore it.

  • The ‘cost-currency’ is that which is found on the holdings instance and can be ignored. The ‘quote-currency’ is that which is declared on the Commodity directive from its ‘quote’ metadata field.

This is used in a routine that fetches prices from a data source on the internet (either from Ledgerhub, but you can reuse this in your own script if you build one).

Parameters
  • entries – A list of directives.

  • date – A datetime.date instance, the date at which to get the list of relevant holdings.

Returns

A list of (currency, cost-currency, quote-currency, ticker) tuples, where

currency: The Beancount base currency to fetch a price for. cost-currency: The cost-currency of the holdings found at the given date. quote-currency: The currency formally declared as quote currency in the

metadata of Commodity directives.

ticker: The ticker symbol to use for fetching the price (extracted from

the metadata of Commodity directives).

beancount.ops.holdings.get_final_holdings(entries, included_account_types=None, price_map=None, date=None)

Get a dictionary of the latest holdings by account.

This basically just flattens the balance sheet’s final positions, including that of equity accounts. If a ‘price_map’ is provided, insert price information in the flattened holdings at the latest date, or at the given date, if one is provided.

Only the accounts in ‘included_account_types’ will be included, and this is always called for Assets and Liabilities only. If left unspecified, holdings from all account types will be included, including Equity, Income and Expenses.

Parameters
  • entries – A list of directives.

  • included_account_types – A sequence of strings, the account types to include in the output. A reasonable example would be (‘Assets’, ‘Liabilities’). If not specified, include all account types.

  • price_map – A dict of prices, as built by prices.build_price_map().

  • date – A datetime.date instance, the date at which to price the holdings. If left unspecified, we use the latest price information.

Returns

Return type

A list of dicts, with the following fields

beancount.ops.holdings.holding_to_position(holding)

Convert the holding to a position.

Parameters

holding – An instance of Holding.

Returns

An instance of Position.

beancount.ops.holdings.holding_to_posting(holding)

Convert the holding to an instance of Posting.

Parameters

holding – An instance of Holding.

Returns

An instance of Position.

beancount.ops.holdings.reduce_relative(holdings)

Convert the market and book values of the given list of holdings to relative data.

Parameters

holdings – A list of Holding instances.

Returns

A list of holdings instances with the absolute value fields replaced by fractions of total portfolio. The new list of holdings is sorted by currency, and the relative fractions are also relative to that currency.

beancount.ops.holdings.scale_holding(holding, scale_factor)

Scale the values of a holding.

Parameters
  • holding – An instance of Holding.

  • scale_factor – A float or Decimal number.

Returns

A scaled copy of the holding.

beancount.ops.lifetimes

Given a Beancount ledger, compute time intervals where we hold each commodity.

This script computes, for each commodity, which time intervals it is required at. This can then be used to identify a list of dates at which we need to fetch prices in order to properly fill the price database.

beancount.ops.lifetimes.compress_intervals_days(intervals, num_days)

Compress a list of date pairs to ignore short stretches of unused days.

Parameters
  • intervals – A list of pairs of datetime.date instances.

  • num_days – An integer, the number of unused days to require for intervals to be distinct, to allow a gap.

Returns

A new dict of lifetimes map where some intervals may have been joined.

beancount.ops.lifetimes.compress_lifetimes_days(lifetimes_map, num_days)

Compress a lifetimes map to ignore short stretches of unused days.

Parameters
  • lifetimes_map – A dict of currency intervals as returned by get_commodity_lifetimes.

  • num_days – An integer, the number of unused days to ignore.

Returns

A new dict of lifetimes map where some intervals may have been joined.

beancount.ops.lifetimes.get_commodity_lifetimes(entries)

Given a list of directives, figure out the life of each commodity.

Parameters

entries – A list of directives.

Returns

A dict of (currency, cost-currency) commodity strings to lists of (start, end) datetime.date pairs. The dates are inclusive of the day the commodity was seen; the end/last dates are one day _after_ the last date seen.

beancount.ops.lifetimes.required_weekly_prices(lifetimes_map, date_last)

Enumerate all the commodities and fridays where the price is required.

Given a map of lifetimes for a set of commodities, enumerate all the Fridays for each commodity where it is active. This can be used to connect to a historical price fetcher routine to fill in missing price entries from an existing ledger.

Parameters
  • lifetimes_map – A dict of currency to active intervals as returned by get_commodity_lifetimes().

  • date_last – A datetime.date instance, the last date which we’re interested in.

Returns

Tuples of (date, currency, cost-currency).

beancount.ops.pad

Automatic padding of gaps between entries.

class beancount.ops.pad.PadError(source, message, entry)
beancount.ops.pad.pad(entries, options_map)

Insert transaction entries for to fulfill a subsequent balance check.

Synthesize and insert Transaction entries right after Pad entries in order to fulfill checks in the padded accounts. Returns a new list of entries. Note that this doesn’t pad across parent-child relationships, it is a very simple kind of pad. (I have found this to be sufficient in practice, and simpler to implement and understand.)

Furthermore, this pads for a single currency only, that is, balance checks are specified only for one currency at a time, and pads will only be inserted for those currencies.

Parameters
  • entries – A list of directives.

  • options_map – A parser options dict.

Returns

A new list of directives, with Pad entries inserte, and a list of new errors produced.

beancount.ops.summarize

Summarization of entries.

This code is used to summarize a sequence of entries (e.g. during a time period) into a few “opening balance” entries. This is when computing a balance sheet for a specific time period: we don’t want to see the entries from before some period of time, so we fold them into a single transaction per account that has the sum total amount of that account.

beancount.ops.summarize.balance_by_account(entries, date=None)

Sum up the balance per account for all entries strictly before ‘date’.

Parameters
  • entries – A list of directives.

  • date – An optional datetime.date instance. If provided, stop accumulating on and after this date. This is useful for summarization before a specific date.

Returns

A pair of a dict of account string to instance Inventory (the balance of this account before the given date), and the index in the list of entries where the date was encountered. If all entries are located before the cutoff date, an index one beyond the last entry is returned.

beancount.ops.summarize.cap(entries, account_types, conversion_currency, account_earnings, account_conversions)

Transfer net income to equity and insert a final conversion entry.

This is used to move and nullify balances from the income and expense accounts to an equity account in order to draw up a balance sheet with a balance of precisely zero.

Parameters
  • entries – A list of directives.

  • account_types – An instance of AccountTypes.

  • conversion_currency – A string, the transfer currency to use for zero prices on the conversion entry.

  • account_earnings – A string, the name of the equity account to transfer final balances of the income and expense accounts to.

  • account_conversions – A string, the name of the equity account to use as the source for currency conversions.

Returns

A modified list of entries, with the income and expense accounts transferred.

beancount.ops.summarize.cap_opt(entries, options_map)

Close by getting all the parameters from an options map.

See cap() for details.

Parameters
  • entries – See cap().

  • options_map – A parser’s option_map.

Returns

Same as close().

beancount.ops.summarize.clamp(entries, begin_date, end_date, account_types, conversion_currency, account_earnings, account_opening, account_conversions)

Filter entries to include only those during a specified time period.

Firstly, this method will transfer all balances for the income and expense accounts occurring before the given period begin date to the ‘account_earnings’ account (earnings before the period, or “retained earnings”) and summarize all of the transactions before that date against the ‘account_opening’ account (usually “opening balances”). The resulting income and expense accounts should have no transactions (since their balances have been transferred out and summarization of zero balances should not add any transactions).

Secondly, all the entries after the period end date will be truncated and a conversion entry will be added for the resulting transactions that reflect changes occurring between the beginning and end of the exercise period. The resulting balance of all account should be empty.

Parameters
  • entries – A list of directive tuples.

  • begin_date – A datetime.date instance, the beginning of the period.

  • end_date – A datetime.date instance, one day beyond the end of the period.

  • account_types – An instance of AccountTypes.

  • conversion_currency – A string, the transfer currency to use for zero prices on the conversion entry.

  • account_earnings – A string, the name of the account to transfer previous earnings from the income statement accounts to the balance sheet.

  • account_opening – A string, the name of the account in equity to transfer previous balances from, in order to initialize account balances at the beginning of the period. This is typically called an opening balances account.

  • account_conversions – A string, tne name of the equity account to book currency conversions against.

Returns

A new list of entries is returned, and the index that points to the first original transaction after the beginning date of the period. This index can be used to generate the opening balances report, which is a balance sheet fed with only the summarized entries.

beancount.ops.summarize.clamp_opt(entries, begin_date, end_date, options_map)

Clamp by getting all the parameters from an options map.

See clamp() for details.

Parameters
  • entries – See clamp().

  • begin_date – See clamp().

  • end_date – See clamp().

  • options_map – A parser’s option_map.

Returns

Same as clamp().

beancount.ops.summarize.clear(entries, date, account_types, account_earnings)

Transfer income and expenses balances at the given date to the equity accounts.

This method insert entries to zero out balances on income and expenses accounts by transfering them to an equity account.

Parameters
  • entries – A list of directive tuples.

  • date – A datetime.date instance, one day beyond the end of the period. This date can be optionally left to None in order to close at the end of the list of entries.

  • account_types – An instance of AccountTypes.

  • account_earnings – A string, the name of the account to transfer previous earnings from the income statement accounts to the balance sheet.

Returns

A new list of entries is returned, and the index that points to one before the last original transaction before the transfers.

beancount.ops.summarize.clear_opt(entries, date, options_map)

Convenience function to clear() using an options map.

beancount.ops.summarize.close(entries, date, conversion_currency, account_conversions)

Truncate entries that occur after a particular date and ensure balance.

This method essentially removes entries after a date. It truncates the future. To do so, it will

  1. Remove all entries which occur after ‘date’, if given.

  2. Insert conversion transactions at the end of the list of entries to ensure that the total balance of all postings sums up to empty.

The result is a list of entries with a total balance of zero, with possibly non-zero balances for the income/expense accounts. To produce a final balance sheet, use transfer() to move the net income to the equity accounts.

Parameters
  • entries – A list of directive tuples.

  • date – A datetime.date instance, one day beyond the end of the period. This date can be optionally left to None in order to close at the end of the list of entries.

  • conversion_currency – A string, the transfer currency to use for zero prices on the conversion entry.

  • account_conversions – A string, tne name of the equity account to book currency conversions against.

Returns

A new list of entries is returned, and the index that points to one beyond the last original transaction that was provided. Further entries may have been inserted to normalize conversions and ensure the total balance sums to zero.

beancount.ops.summarize.close_opt(entries, date, options_map)

Convenience function to close() using an options map.

beancount.ops.summarize.conversions(entries, conversion_account, conversion_currency, date=None)

Insert a conversion entry at date ‘date’ at the given account.

Parameters
  • entries – A list of entries.

  • conversion_account – A string, the account to book against.

  • conversion_currency – A string, the transfer currency to use for zero prices on the conversion entry.

  • date – The date before which to insert the conversion entry. The new entry will be inserted as the last entry of the date just previous to this date.

Returns

A modified list of entries.

beancount.ops.summarize.create_entries_from_balances(balances, date, source_account, direction, meta, flag, narration_template)

“Create a list of entries from a dict of balances.

This method creates a list of new entries to transfer the amounts in the ‘balances’ dict to/from another account specified in ‘source_account’.

The balancing posting is created with the equivalent at cost. In other words, if you attempt to balance 10 HOOL {500 USD}, this will synthesize a posting with this position on one leg, and with 5000 USD on the ‘source_account’ leg.

Parameters
  • balances – A dict of account name strings to Inventory instances.

  • date – A datetime.date object, the date at which to create the transaction.

  • source_account – A string, the name of the account to pull the balances from. This is the magician’s hat to pull the rabbit from.

  • direction – If ‘direction’ is True, the new entries transfer TO the balances account from the source account; otherwise the new entries transfer FROM the balances into the source account.

  • meta – A dict to use as metadata for the transactions.

  • flag – A string, the flag to use for the transactinos.

  • narration_template – A format string for creating the narration. It is formatted with ‘account’ and ‘date’ replacement variables.

Returns

A list of newly synthesizes Transaction entries.

beancount.ops.summarize.get_open_entries(entries, date)

Gather the list of active Open entries at date.

This returns the list of Open entries that have not been closed at the given date, in the same order they were observed in the document.

Parameters
  • entries – A list of directives.

  • date – The date at which to look for an open entry. If not specified, will return the entries still open at the latest date.

Returns

A list of Open directives.

beancount.ops.summarize.open(entries, date, account_types, conversion_currency, account_earnings, account_opening, account_conversions)

Summarize entries before a date and transfer income/expenses to equity.

This method essentially prepares a list of directives to contain only transactions that occur after a particular date. It truncates the past. To do so, it will

  1. Insert conversion transactions at the given open date, then

  2. Insert transactions at that date to move accumulated balances from before that date from the income and expenses accounts to an equity account, and finally

  3. It removes all the transactions previous to the date and replaces them by opening balances entries to bring the balances to the same amount.

The result is a list of entries for which the income and expense accounts are beginning with a balance of zero, and all other accounts begin with a transaction that brings their balance to the expected amount. All the past has been summarized at that point.

An index is returned to the first transaction past the balance opening transactions, so you can keep just those in order to render a balance sheet for only the opening balances.

Parameters
  • entries – A list of directive tuples.

  • date – A datetime.date instance, the date at which to do this.

  • account_types – An instance of AccountTypes.

  • conversion_currency – A string, the transfer currency to use for zero prices on the conversion entry.

  • account_earnings – A string, the name of the account to transfer previous earnings from the income statement accounts to the balance sheet.

  • account_opening – A string, the name of the account in equity to transfer previous balances from, in order to initialize account balances at the beginning of the period. This is typically called an opening balances account.

  • account_conversions – A string, tne name of the equity account to book currency conversions against.

Returns

A new list of entries is returned, and the index that points to the first original transaction after the beginning date of the period. This index can be used to generate the opening balances report, which is a balance sheet fed with only the summarized entries.

beancount.ops.summarize.open_opt(entries, date, options_map)

Convenience function to open() using an options map.

beancount.ops.summarize.summarize(entries, date, account_opening)

Summarize all entries before a date by replacing then with summarization entries.

This function replaces the transactions up to (and not including) the given date with a opening balance transactions, one for each account. It returns new entries, all of the transactions before the given date having been replaced by a few summarization entries, one for each account.

Notes: - Open entries are preserved for active accounts. - The last relevant price entry for each (base, quote) pair is preserved. - All other entries before the cutoff date are culled.

Parameters
  • entries – A list of directives.

  • date – A datetime.date instance, the cutoff date before which to summararize.

  • account_opening – A string, the name of the source account to book summarization entries against.

Returns

The function returns a list of new entries and the integer index at which the entries on or after the cutoff date begin.

beancount.ops.summarize.transfer_balances(entries, date, account_pred, transfer_account)

Synthesize transactions to transfer balances from some accounts at a given date.

For all accounts that match the ‘account_pred’ predicate, create new entries to transfer the balance at the given date from the account to the transfer account. This is used to transfer balances from income and expenses from a previous period to a “retained earnings” account. This is accomplished by creating new entries.

Note that inserting transfers breaks any following balance checks that are in the transferred accounts. For this reason, all balance assertion entries following the cutoff date for those accounts are removed from the list in output.

Parameters
  • entries – A list of directives.

  • date – A datetime.date instance, the date at which to make the transfer.

  • account_pred – A predicate function that, given an account string, returns true if the account is meant to be transferred.

  • transfer_account – A string, the name of the source account to be used on the transfer entries to receive balances at the given date.

Returns

A new list of entries, with the new transfer entries added in.

beancount.ops.summarize.truncate(entries, date)

Filter out all the entries at and after date. Returns a new list of entries.

Parameters
  • entries – A sorted list of directives.

  • date – A datetime.date instance.

Returns

A truncated list of directives.

beancount.ops.validation

Validation checks.

These checks are intended to be run after all the plugins have transformed the list of entries, just before serving them or generating reports from them. The idea is to ensure a reasonable set of invariants and generate errors if those invariants are violated. They are not sanity checks–user data is subject to constraints which are hopefully detected here and which will result in errors trickled up to the user.

class beancount.ops.validation.ValidationError(source, message, entry)
beancount.ops.validation.validate(entries, options_map, log_timings=None, extra_validations=None)

Perform all the standard checks on parsed contents.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

  • log_timings – An optional function to use for logging the time of individual operations.

  • extra_validations – A list of extra validation functions to run after loading this list of entries.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_active_accounts(entries, unused_options_map)

Check that all references to accounts occurs on active accounts.

We basically check that references to accounts from all directives other than Open and Close occur at dates the open-close interval of that account. This should be good for all of the directive types where we can extract an account name.

Note that this is more strict a check than comparing the dates: we actually check that no references to account are made on the same day before the open directive appears for that account. This is a nice property to have, and is supported by our custom sorting routine that will sort open entries before transaction entries, given the same date.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_check_transaction_balances(entries, options_map)

Check again that all transaction postings balance, as users may have transformed transactions.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_currency_constraints(entries, options_map)

Check the currency constraints from account open declarations.

Open directives admit an optional list of currencies that specify the only types of commodities that the running inventory for this account may contain. This function checks that all postings are only made in those commodities.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_data_types(entries, options_map)

Check that all the data types of the attributes of entries are as expected.

Users are provided with a means to filter the list of entries. They’re able to write code that manipulates those tuple objects without any type constraints. With discipline, this mostly works, but I know better: check, just to make sure. This routine checks all the data types and assumptions on entries.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_documents_paths(entries, options_map)

Check that all filenames in resolved Document entries are absolute filenames.

The processing of document entries is assumed to result in absolute paths. Relative paths are resolved at the parsing stage and at point we want to make sure we don’t have to do any further processing on them.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_duplicate_balances(entries, unused_options_map)

Check that balance entries occur only once per day.

Because we do not support time, and the declaration order of entries is meant to be kept irrelevant, two balance entries with different amounts should not occur in the file. We do allow two identical balance assertions, however, because this may occur during import.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_duplicate_commodities(entries, unused_options_map)

Check that commodty entries are unique for each commodity.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.

beancount.ops.validation.validate_open_close(entries, unused_options_map)

Check constraints on open and close directives themselves.

This method checks two kinds of constraints:

  1. An open or a close directive may only show up once for each account. If a duplicate is detected, an error is generated.

  2. Close directives may only appears if an open directive has been seen previous (chronologically).

  3. The date of close directives must be strictly greater than their

corresponding open directive.

Parameters
  • entries – A list of directives.

  • unused_options_map – An options map.

Returns

A list of new errors, if any were found.