Transaction

class transaction.Transaction(guid: str | None = None, slots: list[Slot] | None = None, currency: Commodity | None = None, date_posted: datetime | None = None, date_entered: datetime | None = None, description: str = '', splits: list[Split] | None = None, memo: str | None = None)[source]

Represents a transaction in GnuCash.

property associated_uri: str

URI associated with the transaction.

Returns:

URI associated with the transaction

Return type:

str

property cleared: bool

Checks if all splits in the transaction are cleared.

Returns:

Boolean indicating if all splits in the transaction are cleared.

Return type:

bool

property from_split_account_names: Generator[str, None, None]

Retrieves the names of accounts that are associated with the “from” splits.

Returns:

Names of accounts associated with splits that have a negative amount.

Return type:

collections.Iterable[Account]

property from_split_accounts: Generator[Account, None, None]

Retrieves the accounts that are associated with the “from” splits.

Returns:

Accounts associated with splits that have a negative amount.

Return type:

collections.Iterable[Account]

property from_splits: Generator[Split, None, None]

Retrieves the “from” splits in the transaction.

Returns:

Splits with a negative amount.

Return type:

collections.Iterable[Split]

mark_transaction_cleared() None[source]

Marks all splits in the transaction as cleared (reconciled_state = ‘c’).

property notes: str

Notes on the transaction.

Returns:

Notes tied to the transaction

Return type:

str

property reversed_by: str

GUID of the transaction that reverses this transaction.

Returns:

Transaction GUID

Return type:

str

property split_account_names: Generator[str, None, None]

Retrieves the names of the accounts involved in the splits.

Returns:

Names of the accounts involved in the splits.

Return type:

collections.Iterable[str]

property split_accounts: Generator[Account, None, None]

Retrieves the accounts involved in the splits.

Returns:

Accounts involved in splits.

Return type:

collections.Iterable[Account]

property splits_total: Decimal

Retrieves the sum of all positive split amounts.

Returns:

Sum of all positive split amounts.

Return type:

decimal.Decimal

property to_split_account_names: Generator[str, None, None]

Retrieves the names of accounts that are associated with the “to” splits.

Returns:

Names of accounts associated with splits that have a positive amount.

Return type:

collections.Iterable[str]

property to_split_accounts: Generator[Account, None, None]

Retrieves the accounts that are associated with the “to” splits.

Returns:

Accounts associated with splits that have a positive amount.

Return type:

collections.Iterable[Account]

property to_splits: Generator[Split, None, None]

Retrieves the “to” splits in the transaction.

Returns:

Splits with a positive amount.

Return type:

collections.Iterable[Split]

property void_reason: str

Reason that the transaction was voided.

Returns:

Reason that the transaction was voided

Return type:

str

property void_time: str

Time that the transaction was voided.

Returns:

Time that the transaction was voided

Return type:

str

property voided: str

Void status.

Returns:

Void status

Return type:

str

class transaction.Split(account: Account | None, amount: Decimal | None, reconciled_state: str = 'n', guid: str | None = None, action: str | None = None, memo: str | None = None, quantity_denominator: str = '100', reconcile_date: datetime | None = None, quantity_num: int | None = None, lot_guid: str | None = None, value_num: int | None = None, value_denom: int | None = None)[source]

Represents a split in GnuCash.

class transaction.TransactionManager(transactions: list[Transaction] | None = None, disable_sort: bool = False, sort_method: SortingMethod | None = None)[source]

Class used to add/remove transactions, maintaining a chronological order based on transaction posted date.

add(new_transaction: Transaction) None[source]

Adds a transaction to the transaction manager.

Parameters:

new_transaction (Transaction) – Transaction to add

create_reversing_transaction(transaction: Transaction, reversed_date: datetime | None = None) Transaction[source]

Creates a new transaction that reverses another transaction.

Parameters:
  • transaction (Transaction) – Transaction to be reversed

  • reversed_date (datetime) – The date that the transaction was reversed (optional, default is transaction’s date)

Returns:

New transaction that reverses the provided transaction

Return type:

Transaction

delete(transaction: Transaction) None[source]

Removes a transaction from the transaction manager.

Parameters:

transaction (Transaction) – Transaction to remove

get_account_ending_balance(account: Account) Decimal[source]

Retrieves the ending balance for the provided account given the list of transactions in the manager.

Parameters:

account (Account) – Account to get the ending balance for

Returns:

Account starting balance

Return type:

decimal.Decimal

get_account_starting_balance(account: Account) Decimal[source]

Retrieves the starting balance for the current account, given the list of transactions.

Parameters:

account (Account) – Account to get starting balance of.

Returns:

First transaction amount if the account has transactions, otherwise 0.

Return type:

decimal.Decimal

get_balance_at_date(account: Account, date: datetime | None = None) Decimal[source]

Retrieves the account balance for the current account at a certain date, given the list of transactions.

If the provided date is None, it will retrieve the ending balance.

Parameters:
  • account (Account) – Account to get the balance of

  • date (datetime.datetime) – Last date to consider when determining the account balance.

Returns:

Account balance at specified date (or ending balance) or 0, if no applicable transactions were found.

Return type:

decimal.Decimal

get_balance_at_transaction(account: Account, transaction: Transaction) Decimal[source]

Retrieves the account balance for the specified account at a certain transaction.

Parameters:
  • account (Account) – Account to get the balance of

  • transaction (Transaction) – Last transaction to consider when determining the account balance.

Returns:

Account balance at specified transaction or 0, if no applicable transactions were found.

Return type:

decimal.Decimal

get_cleared_balance(account: Account) Decimal[source]

Retrieves the current cleared balance for the specified account.

Parameters:

account (Account) – Account to get the cleared balance of.

Returns:

Current cleared balance for the account

Return type:

decimal.Decimal

get_transactions(account: Account | None = None) Iterator[Transaction][source]

Generator function that gets transactions based on a from account and/or to account for the transaction.

Parameters:

account (Account) – Account to retrieve transactions for (default None, all transactions)

Returns:

Generator that produces transactions based on the given from account and/or to account

Return type:

Iterator[Transaction]

minimum_balance_past_date(account: Account, date: datetime) tuple[Decimal | None, datetime | None][source]

Gets the minimum balance for the account after a certain date, given the list of transactions.

Parameters:
  • account (Account) – Account to get the minimum balance information of

  • date (datetime.datetime) – datetime object representing the date you want to find the minimum balance for.

Returns:

Tuple containing the minimum balance (element 0) and the date it’s at that balance (element 1)

Return type:

tuple

query() Query[source]

Gets a new Query object to query transactions.

Returns:

New Query object

Return type:

Query

class transaction.ScheduledTransaction(guid: str | None = None, name: str | None = None, enabled: bool | None = False, auto_create: bool | None = False, auto_create_notify: bool | None = False, advance_create_days: int | None = -1, advance_remind_days: int | None = -1, instance_count: int | None = 0, start_date: datetime | None = None, last_date: datetime | None = None, end_date: datetime | None = None, template_account: Account | None = None, recurrence_multiplier: int | None = 0, recurrence_period: str | None = None, recurrence_start: datetime | None = None, num_occur: int | None = None, rem_occur: int | None = None, recurrence_weekend_adjust: str | None = None)[source]

Class that represents a scheduled transaction in Gnucash.

class transaction.SimpleTransaction(from_account: Account | None = None, to_account: Account | None = None, amount: Decimal | None = None, currency: Commodity | None = None, date_posted: datetime | None = None, date_entered: datetime | None = None, description: str = '', memo: str | None = None)[source]

Class used to simplify creating and manipulating Transactions that only have 2 splits.

property amount: Decimal | None

Dollar amount for funds transferred.

Returns:

Dollar amount for funds transferred.

Return type:

decimal.Decimal

property from_account: Account | None

Account which the transaction transfers funds from.

Returns:

Account which the transaction transfers funds from.

Return type:

Account

classmethod from_transaction(other: Transaction) SimpleTransaction[source]

Creates a SimpleTransaction from a regular Transaction.

property to_account: Account | None

Account which the transaction transfers funds to.

Returns:

Account which the transaction transfers funds to.

Return type:

Account

class transaction.SortingMethod(reverse: bool = False)[source]

Base class for derivative sorting method classes.

compare(transaction1: Transaction, transaction2: Transaction) SortingResult[source]

Compares one transaction with another and returns which one is greater, or if they’re equal.

Parameters:
  • transaction1 (Transaction) – First transaction in comparison.

  • transaction2 (Transaction) – Second transaction in comparison.

Returns:

Enum result that contains if the first transaction is greater, second transaction is greater, or equal.

Return type:

SortingResult

class transaction.InvalidSortFieldException[source]

Custom exception class for when the sort field isn’t set.

class transaction.StandardSort(reverse: bool = False)[source]

Sort logic for GnuCash’s standard sort.

compare(transaction1: Transaction, transaction2: Transaction) SortingResult[source]

Compares one transaction with another and returns which one is greater, or if they’re equal.

Parameters:
  • transaction1 (Transaction) – First transaction in comparison.

  • transaction2 (Transaction) – Second transaction in comparison.

Returns:

Enum result that contains if the first transaction is greater, second transaction is greater, or equal.

Return type:

SortingResult

class transaction.AmountSort(reverse: bool = False)[source]

Sort logic for GnuCash’s split amount sort.

class transaction.DateSort(reverse: bool = False)[source]

Sort logic for GnuCash’s date sort.

class transaction.DateOfEntrySort(reverse: bool = False)[source]

Sort logic for GnuCash’s date of entry sort.

class transaction.DescriptionSort(reverse: bool = False)[source]

Sort logic for GnuCash’s description sort.

class transaction.MemoSort(reverse: bool = False)[source]

Sort logic for GnuCash’s memo sort.

class transaction.NumberActionSort(reverse: bool = False)[source]

Sort logic for GnuCash’s number/action sort.

class transaction.TransactionNumberSort(reverse: bool = False)[source]

Sort logic for GnuCash’s transaction number sort.