Account

Standard Accounts

class account.Account(guid: str | None = None, slots: list[Slot] | None = None, name: str = '', account_type: str | None = None, description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: GuidObject, SlottableObject

Represents an account in GnuCash.

as_dict(account_hierarchy: dict[str, Account] | None = None, path_to_self: str = '/') dict[str, Account][source]

Retrieves the current account hierarchy as a dictionary.

Parameters:
  • account_hierarchy (dict) – Existing account hierarchy. If None is provided, assumes a new dictionary.

  • path_to_self (str) – Dictionary key for the current account.

Returns:

Dictionary containing current account and all subaccounts.

Return type:

dict

property color: str

Account color.

Returns:

Account color as a string

Return type:

str

property dict_entry_name: str

Retrieves the dictionary entry based on account name.

Only alpha-numeric and underscore characters allowed. Spaces and slashes (/) are converted to underscores.

Returns:

String with the dictionary entry name.

Return type:

str

get_account_guids(account_guids: list[str] | None = None) list[str][source]

Gets a flat list of account GUIDs under the current account.

Parameters:

account_guids (list[str]) – Running list of account GUIDs (should be None on first call)

Returns:

List of account GUIDs under the current account

Return type:

list[str]

get_parent_commodity() Commodity | None[source]

Retrieves the commodity for the account.

If none is provided, it will look at it’s parent (and ancestors recursively) to find it.

Returns:

Commodity object, or None if no commodity was found in the ancestry chain.

Return type:

NoneType|Commodity

get_subaccount_by_id(subaccount_id: str) Account | None[source]

Finds a subaccount by its guid field.

Parameters:

subaccount_id (str) – Subaccount guid to find

Returns:

Account object for that guid or None if no account was found

Return type:

NoneType|Account

property hidden: bool

Hidden flag for the account.

Returns:

True if account is marked hidden, otherwise False.

Return type:

bool

property notes: str

User defined notes for the account.

Returns:

User-defined notes

Return type:

str

property parent: Account | None

Parent account of the current account.

Returns:

Account’s parent

Return type:

NoneType|Account

property placeholder: bool

Placeholder flag for the account.

Returns:

True if the account is a placeholder, otherwise False

Return type:

bool

class account.AccountType[source]

Enumeration class to indicate the types of accounts available in GnuCash.

Shortcut Accounts

class account.AssetAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.ASSET.

class account.BankAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.BANK.

class account.CreditAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.CREDIT.

class account.EquityAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.EQUITY.

class account.ExpenseAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.EXPENSE.

class account.IncomeAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.INCOME.

class account.LiabilityAccount(name: str = '', description: str | None = None, children: list[Account] | None = None, code: str | None = None, commodity: Commodity | None = None, commodity_scu: str | None = None, non_std_scu: int | None = None)[source]

Bases: Account

Shortcut class to create an account with the type set to AccountType.LIABILITY.

Special Accounts

class account.InterestAccountBase[source]

Abstract class defining the API for Interest accounts.

abstract get_all_payments(skip_additional_payments: bool = False) list[tuple[datetime, Decimal, Decimal]][source]

Abstract method for retrieving all payments for the loan plan.

Parameters:

skip_additional_payments (bool) – Skips additional payments if True.

abstract get_info_at_date(date: datetime) LoanStatus[source]

Abstract method for retrieving the loan info at a specified date for the account.

Parameters:

date (datetime.datetime) – datetime object indicating the date you want the loan status of

abstract property interest_percentage: Decimal

Abstract method for retrieving the interest percentage for the account.

abstract property payment_amount: Decimal

Abstract method for retrieving the payment amount for the account.

abstract property starting_balance: Decimal

Abstract method for retrieving the starting balance for the account.

abstract property starting_date: datetime

Abstract method for retrieving the starting date for the account.

class account.InterestAccount(starting_balance: Decimal, starting_date: datetime, interest_percentage: Decimal, payment_amount: Decimal, additional_payments: list[LoanExtraPayment] | None = None, skip_payment_dates: list[datetime] | None = None, interest_start_date: datetime | None = None)[source]

Class used to calculate interest balances.

__init__(starting_balance: Decimal, starting_date: datetime, interest_percentage: Decimal, payment_amount: Decimal, additional_payments: list[LoanExtraPayment] | None = None, skip_payment_dates: list[datetime] | None = None, interest_start_date: datetime | None = None)[source]

Class initializer.

Parameters:
  • starting_balance (decimal.Decimal|NoneType) – Starting balance for the interest account.

  • starting_date (datetime.datetime|NoneType) – datetime object indicating the date of the starting balance.

  • interest_percentage (decimal.Decimal|NoneType) – Percentage to interest on the loan.

  • payment_amount (decimal.Decimal|NoneType) – Payment amount on the loan.

  • additional_payments (list[LoanExtraPayment]|NoneType) – List of LoanExtraPayment objects indicating extra payments to the loan.

  • skip_payment_dates (list[datetime.datetime]|NoneType) – List of datetime objects that the loan payment should be skipped

  • interest_start_date (datetime.datetime|NoneType) – datetime object that interest starts on

get_all_payments(skip_additional_payments: bool = False) list[tuple[datetime, Decimal, Decimal]][source]

Retrieves a list of tuples that show all payments for the loan plan.

Parameters:

skip_additional_payments (bool) – Skips additional payments if True.

Returns:

List of tuples with the date (index 0), balance (index 1) and amount to capital (index 2)

Return type:

list[tuple]

get_info_at_date(date: datetime) LoanStatus[source]

Retrieves the loan info at a specified date for the current account.

Parameters:

date (datetime.datetime) – datetime object indicating the date you want the loan status of

Returns:

LoanStatus object

Return type:

LoanStatus

property interest_percentage: Decimal

Retrieves the interest percentage for the account.

Returns:

Current InterestAccount object’s percentage.

Return type:

decimal.Decimal

property payment_amount: Decimal

Retrieves the payment amount for the account.

Returns:

Current InterestAccount object’s payment amount.

Return type:

decimal.Decimal

property starting_balance: Decimal

Retrieves the starting balance for the account.

Returns:

Current InterestAccount object’s starting balance.

Return type:

decimal.Decimal

property starting_date: datetime

Retrieves the starting date for the account.

Returns:

Current InterestAccount’s starting date.

Return type:

datetime.datetime

class account.InterestAccountWithSubaccounts(subaccounts: list[InterestAccount], additional_payments: list[dict[str, Decimal | datetime]] | None = None, skip_payment_dates: list[datetime] | None = None)[source]

Class used to calculate interest balances based off of balances of subaccounts.

__init__(subaccounts: list[InterestAccount], additional_payments: list[dict[str, Decimal | datetime]] | None = None, skip_payment_dates: list[datetime] | None = None)[source]

Class initializer.

Parameters:
  • subaccounts (list[InterestAccount]) – List of InterestAccount objects that are subaccounts of this InterestAccount

  • additional_payments (list[dict]|NoneType) – List of dictionaries containing an “amount” key for additional amount paid, and “payment_date” for the date the additional amount was paid.

  • skip_payment_dates (list[datetime.datetime]|NoneType) – List of datetime objects that the loan payment should be skipped

get_all_payments(skip_additional_payments: bool = False) list[tuple[datetime, Decimal, Decimal]][source]

Retrieves a list of tuples that show all payments for the loan plan.

Parameters:

skip_additional_payments (bool) – Skips additional payments if True.

Returns:

List of tuples with the date (index 0), balance (index 1) and amount to capital (index 2)

Return type:

list[tuple]

get_info_at_date(date: datetime) LoanStatus[source]

Retrieves the loan info at a specified date for all subaccounts.

Parameters:

date (datetime.datetime) – datetime object indicating the date you want the loan status of

Returns:

LoanStatus object

Return type:

LoanStatus

property interest_percentage: Decimal

Retrieves the sum of the subaccounts’ interest percentage.

Returns:

Sum of interest percentages.

Return type:

decimal.Decimal

property payment_amount: Decimal

Retrieves the sum of the subaccounts’ payment amount.

Returns:

Sum of the payment amounts.

Return type:

decimal.Decimal

property starting_balance: Decimal

Retrieves the sum of the subaccounts’ starting balance.

Returns:

Sum of the starting balances.

Return type:

decimal.Decimal

property starting_date: datetime

Retrieves the minimum starting date of the subaccounts.

Returns:

Minimum starting date.

Return type:

datetime.datetime

class account.LoanStatus(iterator_balance, iterator_date, interest, amount_to_capital)

Bases: tuple

amount_to_capital

Alias for field number 3

interest

Alias for field number 2

iterator_balance

Alias for field number 0

iterator_date

Alias for field number 1

class account.LoanExtraPayment(payment_date, payment_amount)

Bases: tuple

payment_amount

Alias for field number 1

payment_date

Alias for field number 0