GnuCash File
- class gnucash_file.GnuCashFile(books: list[Book] | None = 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.
- classmethod read_file(source_file: str | PathLike, file_format: Any, sort_transactions: bool = True, sort_method: SortingMethod | None = None) GnuCashFile [source]
Reads the specified .gnucash file and loads it into memory.
- Parameters:
source_file (Union[str, PathLike]) – Full or relative path to the .gnucash file.
file_format (BaseFileFormat subclass) – File format of the file being uploaded.
sort_transactions (bool) – Flag for if transactions should be sorted by date_posted when reading from XML
sort_method (SortingMethod) – SortingMethod class instance that determines the sort order for the transactions.
- Returns:
New GnuCashFile object
- Return type:
- class gnucash_file.Book(root_account: Account | None = None, transactions: TransactionManager | None = None, commodities: list[Commodity] | None = None, slots: list[Slot] | None = None, template_root_account: Account | None = None, template_transactions: list[Transaction] | None = None, scheduled_transactions: list[ScheduledTransaction] | None = None, budgets: list[Budget] | None = None, guid: str | None = None, sort_method: SortingMethod | None = None)[source]
Represents a Book in GnuCash.
- accounts_query() Query [source]
Get a new Query object to query accounts.
- Returns:
New Query object
- Return type:
- get_account(*paths_to_account: str, **kwargs: Any) Account | None [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: Account) 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:
- class gnucash_file.Budget(guid: str | None = None, slots: list[Slot] | None = None, name: str | None = None, description: str | None = None, period_count: int | None = None, recurrence_multiplier: int | None = None, recurrence_period_type: str | None = None, recurrence_start: datetime | None = None)[source]
Class object representing a Budget in GnuCash.