GnuCash File

class gnucash_file.GnuCashFile(books: Optional[List[Book]] = None)[source]

Class representing a GnuCash file on disk.

build_file(target_file: str, file_format: Any, prettify_xml: bool = False) → None[source]

Writes the contents of the GnuCashFile object out to a .gnucash file on disk.

Parameters:
  • target_file (str) – Full or relative path to the target file
  • file_format (Any) – Class handling the writing of the GnuCash file. See ‘file_formats’ for more info.
  • prettify_xml (bool) – Prettifies XML before writing to disk. Default False.
classmethod read_file(source_file: str, file_format: Any, sort_transactions: bool = True) → gnucash_file.GnuCashFile[source]

Reads the specified .gnucash file and loads it into memory.

Parameters:
  • source_file (str) – Full or relative path to the .gnucash file.
  • sort_transactions (bool) – Flag for if transactions should be sorted by date_posted when reading from XML
  • file_format (BaseFileFormat subclass) – File format of the file being uploaded.
Returns:

New GnuCashFile object

Return type:

GnuCashFile

simplify_transactions() → None[source]

Converts every transaction to a SimpleTransaction.

strip_transaction_timezones() → None[source]

Removes timezone information from the date_posted and date_entered properties in every transaction.

class gnucash_file.Book(root_account: Optional[gnewcash.account.Account] = None, transactions: Optional[gnewcash.transaction.TransactionManager] = None, commodities: Optional[List[gnewcash.commodity.Commodity]] = None, slots: Optional[List[gnewcash.slot.Slot]] = None, template_root_account: Optional[gnewcash.account.Account] = None, template_transactions: Optional[List[gnewcash.transaction.Transaction]] = None, scheduled_transactions: Optional[List[gnewcash.transaction.ScheduledTransaction]] = None, budgets: Optional[List[Budget]] = None)[source]

Represents a Book in GnuCash.

get_account(*paths_to_account, **kwargs) → Optional[gnewcash.account.Account][source]

Retrieves an account based on a path of account names.

Parameters:
  • paths_to_account – Names of accounts that indicate the path
  • kwargs (dict) – Keyword arguments.
Returns:

Account object if found, otherwise None

Return type:

NoneType|Account

Example: get_account('Assets', 'Current Assets', 'Checking Account')

Keyword Arguments:

  • current_level = Account to start searching from. If no account is provided, root account is assumed.
get_account_balance(account: gnewcash.account.Account) → decimal.Decimal[source]

Retrieves the balance for a specified account based on the transactions in the Book.

Parameters:account (Account) – Account object to retrieve the balance of.
Returns:Account balance if applicable transactions found, otherwise 0.
Return type:decimal.Decimal or int
class gnucash_file.Budget[source]

Class object representing a Budget in GnuCash.