Budgets
budgets
Classes:
-
BudgetCategory–Represents budget information for a single category in a specific month.
-
BudgetCategoryGroup–Represents budget information for a category group and all its categories in a specific month.
-
IncomeCategory–Represents budget information for a single income category in a specific month.
-
IncomeCategoryGroup–Represents income information for a category group and all its categories in a specific month.
-
BaseBudget–Base class for budget information for a single month.
-
EnvelopeBudget–Budget information for envelope budgeting mode for a single month.
-
TrackingBudget–Budget information for tracking budgeting mode for a single month.
-
BudgetList–A list of budget objects with helper methods for accessing budget information.
Functions:
-
get_budget_history–Returns the budget history from the first available month to the given month, as iterable.
BudgetCategory
dataclass
BudgetCategory(
database_object: Categories,
spent: Decimal,
accumulated_balance: Decimal,
budget: BaseBudgets | None = None,
)
Bases: _HasDatabaseObject
Represents budget information for a single category in a specific month.
This dataclass contains both the budgeted amount and actual spending information for a category, along with balance calculations.
Parameters:
-
(database_objectCategories) –The category database object this budget information applies to.
-
(spentDecimal) –The actual amount spent in this category this month (typically negative).
-
(accumulated_balanceDecimal) –The balance including carryover from previous months.
This reflects the values displayed on the Actual frontend.
-
(budgetBaseBudgets | None, default:None) –The underlying budget database record, if it exists.
If a budget was not set for the month, it will be set to
None, and budgeted amount assumed to be zero.
Methods:
-
as_dict–Converts the budget category to a dictionary representation.
Attributes:
-
database_object(Categories) –The category database object this budget information applies to.
-
spent(Decimal) –The actual amount spent in this category this month (typically negative).
-
accumulated_balance(Decimal) –The balance including carryover from previous months.
-
budget(BaseBudgets | None) –The underlying budget database record, if it exists.
-
budgeted(Decimal) –The amount budgeted for this category in this month.
-
balance(Decimal) –The simple balance (budgeted plus spent) for this month only.
-
carryover(bool) –Whether this category has carryover enabled (rolls over balance to next month).
-
hidden(bool) –Whether this category is hidden.
-
is_income(bool) –Whether this category is an income category.
database_object
instance-attribute
database_object: Categories
The category database object this budget information applies to.
spent
instance-attribute
spent: Decimal
The actual amount spent in this category this month (typically negative).
accumulated_balance
instance-attribute
accumulated_balance: Decimal
The balance including carryover from previous months.
This reflects the values displayed on the Actual frontend.
budget
class-attribute
instance-attribute
budget: BaseBudgets | None = None
The underlying budget database record, if it exists.
If a budget was not set for the month, it will be set to None, and budgeted amount assumed to be zero.
balance
property
balance: Decimal
The simple balance (budgeted plus spent) for this month only.
If you are looking for the accumulated balance (taking into account previous months and carryover flags,
use accumulated_balance instead.
carryover
property
carryover: bool
Whether this category has carryover enabled (rolls over balance to next month).
as_dict
as_dict() -> dict
Converts the budget category to a dictionary representation.
It's important to note that the property balance represents the accumulated_balance.
Source code in actual/budgets.py
BudgetCategoryGroup
dataclass
BudgetCategoryGroup(
database_object: CategoryGroups,
categories: list[BudgetCategory],
)
Bases: _HasDatabaseObject
Represents budget information for a category group and all its categories in a specific month.
A category group contains multiple categories and aggregates their budget information.
Parameters:
-
(database_objectCategoryGroups) –The category group database object this budget information applies to.
-
(categorieslist[BudgetCategory]) –List of BudgetCategory objects for all categories in this group.
Methods:
-
as_dict–Converts the budget category group to a dictionary representation, including nested categories.
Attributes:
-
database_object(CategoryGroups) –The category group database object this budget information applies to.
-
categories(list[BudgetCategory]) –List of BudgetCategory objects for all categories in this group.
-
budgeted(Decimal) –Sum of all budgeted amounts from the categories under this category group.
-
spent(Decimal) –Sum of all spent amounts from the categories under this category group.
-
accumulated_balance(Decimal) –Sum of all accumulated balances from the categories under this category group.
-
hidden(bool) –Whether this category is hidden.
-
is_income(bool) –Whether this category is an income category.
database_object
instance-attribute
database_object: CategoryGroups
The category group database object this budget information applies to.
categories
instance-attribute
categories: list[BudgetCategory]
List of BudgetCategory objects for all categories in this group.
budgeted
property
budgeted: Decimal
Sum of all budgeted amounts from the categories under this category group.
spent
property
spent: Decimal
Sum of all spent amounts from the categories under this category group.
accumulated_balance
property
accumulated_balance: Decimal
Sum of all accumulated balances from the categories under this category group.
as_dict
as_dict() -> dict
Converts the budget category group to a dictionary representation, including nested categories.
It's important to note that the property balance represents the accumulated_balance.
Source code in actual/budgets.py
IncomeCategory
dataclass
IncomeCategory(
database_object: Categories,
received: Decimal,
budgeted: Decimal = Decimal(0),
budget: ReflectBudgets | None = None,
)
Bases: _HasDatabaseObject
Represents budget information for a single income category in a specific month.
This dataclass contains both the budgeted amount and actual spending information for a category, along with balance calculations.
Parameters:
-
(database_objectCategories) –The category database object this budget information applies to.
-
(receivedDecimal) –The amount of money received in this month.
-
(budgetedDecimal, default:Decimal('0')) –The amount budgeted for this category in this month. Only exists for TrackingBudget.
-
(budgetReflectBudgets | None, default:None) –The underlying budget database record, if it exists. Only exists for TrackingBudget
If a budget was not set for the month, it will be set to
None, and budgeted amount assumed to be zero.
Methods:
-
as_dict–Converts the income category to a dictionary representation.
Attributes:
-
database_object(Categories) –The category database object this budget information applies to.
-
received(Decimal) –The amount of money received in this month.
-
budgeted(Decimal) –The amount budgeted for this category in this month. Only exists for TrackingBudget.
-
budget(ReflectBudgets | None) –The underlying budget database record, if it exists. Only exists for TrackingBudget
-
hidden(bool) –Whether this category is hidden.
-
is_income(bool) –Whether this category is an income category.
database_object
instance-attribute
database_object: Categories
The category database object this budget information applies to.
budgeted
class-attribute
instance-attribute
The amount budgeted for this category in this month. Only exists for TrackingBudget.
budget
class-attribute
instance-attribute
budget: ReflectBudgets | None = None
The underlying budget database record, if it exists. Only exists for TrackingBudget
If a budget was not set for the month, it will be set to None, and budgeted amount assumed to be zero.
as_dict
as_dict() -> dict
Converts the income category to a dictionary representation.
Source code in actual/budgets.py
IncomeCategoryGroup
dataclass
IncomeCategoryGroup(
database_object: CategoryGroups,
categories: list[IncomeCategory],
)
Bases: _HasDatabaseObject
Represents income information for a category group and all its categories in a specific month.
An income category group contains multiple income categories and aggregates their budget information.
Parameters:
-
(database_objectCategoryGroups) –The category group database object this budget information applies to.
-
(categorieslist[IncomeCategory]) –List of IncomeCategory objects for all income categories in this group.
Methods:
-
as_dict–Converts the income category group to a dictionary representation, including nested categories.
Attributes:
-
database_object(CategoryGroups) –The category group database object this budget information applies to.
-
categories(list[IncomeCategory]) –List of IncomeCategory objects for all income categories in this group.
-
received(Decimal) –Sum of all received amounts from the income categories under this income category group.
-
budgeted(Decimal) –Sum of all budgeted amounts from the income categories under this income category group.
-
hidden(bool) –Whether this category is hidden.
-
is_income(bool) –Whether this category is an income category.
database_object
instance-attribute
database_object: CategoryGroups
The category group database object this budget information applies to.
categories
instance-attribute
categories: list[IncomeCategory]
List of IncomeCategory objects for all income categories in this group.
received
property
received: Decimal
Sum of all received amounts from the income categories under this income category group.
budgeted
property
budgeted: Decimal
Sum of all budgeted amounts from the income categories under this income category group.
Only exists for TrackingBudget.
as_dict
as_dict() -> dict
Converts the income category group to a dictionary representation, including nested categories.
Source code in actual/budgets.py
BaseBudget
dataclass
BaseBudget(
month: date,
category_groups: list[BudgetCategoryGroup],
income_category_groups: list[IncomeCategoryGroup],
)
Base class for budget information for a single month.
This is the parent class for both EnvelopeBudget and TrackingBudget, containing common properties and methods for budget calculations.
Parameters:
-
(monthdate) –The month this budget applies to (always the first day of the month).
-
(category_groupslist[BudgetCategoryGroup]) –List of BudgetCategoryGroup objects containing all budget categories.
-
(income_category_groupslist[IncomeCategoryGroup]) –List of IncomeCategoryGroup objects containing all income categories.
Methods:
-
from_category–Returns the budget category for the given category if it exists.
Attributes:
-
month(date) –The month this budget applies to (always the first day of the month).
-
category_groups(list[BudgetCategoryGroup]) –List of BudgetCategoryGroup objects containing all budget categories.
-
income_category_groups(list[IncomeCategoryGroup]) –List of IncomeCategoryGroup objects containing all income categories.
-
received(Decimal) –Total income for this month.
-
budgeted(Decimal) –The amount of money distributed on all budgets for this month.
-
accumulated_balance(Decimal) –Sum of all balances from all categories.
-
spent–Expenses for the current month.
-
categories(Iterator[BudgetCategory]) –List all categories in this budget.
month
instance-attribute
month: date
The month this budget applies to (always the first day of the month).
category_groups
instance-attribute
category_groups: list[BudgetCategoryGroup]
List of BudgetCategoryGroup objects containing all budget categories.
income_category_groups
instance-attribute
income_category_groups: list[IncomeCategoryGroup]
List of IncomeCategoryGroup objects containing all income categories.
budgeted
property
budgeted: Decimal
The amount of money distributed on all budgets for this month.
Keep in mind that, while frontend shows this as a negative number, the budgeted amount is always positive.
from_category
from_category(
category: Categories,
) -> BudgetCategory | None
Returns the budget category for the given category if it exists.
Source code in actual/budgets.py
EnvelopeBudget
dataclass
EnvelopeBudget(
month: date,
category_groups: list[BudgetCategoryGroup],
income_category_groups: list[IncomeCategoryGroup],
for_next_month: Decimal,
last_month_overspent: Decimal,
from_last_month: Decimal,
)
Bases: BaseBudget
Budget information for envelope budgeting mode for a single month.
Envelope budgeting is the default budgeting mode in Actual Budget, where money is allocated to specific categories and can be carried over between months.
Parameters:
-
(monthdate) – -
(category_groupslist[BudgetCategoryGroup]) – -
(income_category_groupslist[IncomeCategoryGroup]) – -
(for_next_monthDecimal) –The amount of money held for the next month.
-
(last_month_overspentDecimal) –The overspent amount from the previous month.
-
(from_last_monthDecimal) –The amount of money inherited from the previous month.
Methods:
-
as_dict–Converts the envelope budget to a dictionary representation, including all category groups.
-
from_category–Returns the budget category for the given category if it exists.
Attributes:
-
for_next_month(Decimal) –The amount of money held for the next month.
-
last_month_overspent(Decimal) –The overspent amount from the previous month.
-
from_last_month(Decimal) –The amount of money inherited from the previous month.
-
overspent(Decimal) –The amount of money overspent for the current month.
-
available_funds(Decimal) –The sum of all incomes plus the budget held from a previous month
-
to_budget–The amount of money available for budgeting.
-
month(date) –The month this budget applies to (always the first day of the month).
-
category_groups(list[BudgetCategoryGroup]) –List of BudgetCategoryGroup objects containing all budget categories.
-
income_category_groups(list[IncomeCategoryGroup]) –List of IncomeCategoryGroup objects containing all income categories.
-
received(Decimal) –Total income for this month.
-
budgeted(Decimal) –The amount of money distributed on all budgets for this month.
-
accumulated_balance(Decimal) –Sum of all balances from all categories.
-
spent–Expenses for the current month.
-
categories(Iterator[BudgetCategory]) –List all categories in this budget.
for_next_month
instance-attribute
for_next_month: Decimal
The amount of money held for the next month.
last_month_overspent
instance-attribute
last_month_overspent: Decimal
The overspent amount from the previous month.
from_last_month
instance-attribute
from_last_month: Decimal
The amount of money inherited from the previous month.
overspent
property
overspent: Decimal
The amount of money overspent for the current month.
This is equivalent to the sum of all negative accumulated balances in all categories. Always returns a negative number (or zero if there is no overspending).
available_funds
property
available_funds: Decimal
The sum of all incomes plus the budget held from a previous month
to_budget
property
The amount of money available for budgeting.
This is equivalent to the available funds minus the budgeted amount, minus the budget for the next month. If you had overspending from the previous month, it will also subtract from the total value.
month
instance-attribute
month: date
The month this budget applies to (always the first day of the month).
category_groups
instance-attribute
category_groups: list[BudgetCategoryGroup]
List of BudgetCategoryGroup objects containing all budget categories.
income_category_groups
instance-attribute
income_category_groups: list[IncomeCategoryGroup]
List of IncomeCategoryGroup objects containing all income categories.
budgeted
property
budgeted: Decimal
The amount of money distributed on all budgets for this month.
Keep in mind that, while frontend shows this as a negative number, the budgeted amount is always positive.
as_dict
as_dict() -> dict
Converts the envelope budget to a dictionary representation, including all category groups.
For simplicity, both the expenses and income category groups are combined into a single list, similar to how the JS API does it.
Source code in actual/budgets.py
from_category
from_category(
category: Categories,
) -> BudgetCategory | None
Returns the budget category for the given category if it exists.
Source code in actual/budgets.py
TrackingBudget
dataclass
TrackingBudget(
month: date,
category_groups: list[BudgetCategoryGroup],
income_category_groups: list[IncomeCategoryGroup],
)
Bases: BaseBudget
Budget information for tracking budgeting mode for a single month.
Tracking budgeting is an alternative budgeting mode that focuses on the simplicity of tracking expenses.
Parameters:
-
(monthdate) – -
(category_groupslist[BudgetCategoryGroup]) – -
(income_category_groupslist[IncomeCategoryGroup]) –
Methods:
-
as_dict–Converts the tracking budget to a dictionary representation, including all category groups.
-
from_category–Returns the budget category for the given category if it exists.
Attributes:
-
overspent(Decimal) –The amount of money overspent for the current month.
-
budgeted_income(Decimal) –The amount of income budgeted for the current month.
-
month(date) –The month this budget applies to (always the first day of the month).
-
category_groups(list[BudgetCategoryGroup]) –List of BudgetCategoryGroup objects containing all budget categories.
-
income_category_groups(list[IncomeCategoryGroup]) –List of IncomeCategoryGroup objects containing all income categories.
-
received(Decimal) –Total income for this month.
-
budgeted(Decimal) –The amount of money distributed on all budgets for this month.
-
accumulated_balance(Decimal) –Sum of all balances from all categories.
-
spent–Expenses for the current month.
-
categories(Iterator[BudgetCategory]) –List all categories in this budget.
overspent
property
overspent: Decimal
The amount of money overspent for the current month.
This is equivalent to the sum of income (positive) and expenses (negative). If you end up with a positive value, you have saved money, otherwise you have overspent.
budgeted_income
property
budgeted_income: Decimal
The amount of income budgeted for the current month.
month
instance-attribute
month: date
The month this budget applies to (always the first day of the month).
category_groups
instance-attribute
category_groups: list[BudgetCategoryGroup]
List of BudgetCategoryGroup objects containing all budget categories.
income_category_groups
instance-attribute
income_category_groups: list[IncomeCategoryGroup]
List of IncomeCategoryGroup objects containing all income categories.
budgeted
property
budgeted: Decimal
The amount of money distributed on all budgets for this month.
Keep in mind that, while frontend shows this as a negative number, the budgeted amount is always positive.
as_dict
as_dict() -> dict
Converts the tracking budget to a dictionary representation, including all category groups.
For simplicity, both the expenses and income category groups are combined into a single list, similar to how the JS API does it.
Source code in actual/budgets.py
from_category
from_category(
category: Categories,
) -> BudgetCategory | None
Returns the budget category for the given category if it exists.
Source code in actual/budgets.py
BudgetList
BudgetList(iterable, is_tracking_budget: bool = False)
Bases: list[EnvelopeBudget | TrackingBudget]
A list of budget objects with helper methods for accessing budget information.
This class extends the built-in list to provide convenient methods for working with multiple months of budget data.
Parameters:
-
–iterableThe list of EnvelopeBudget or TrackingBudget objects.
-
(is_tracking_budgetbool, default:False) –Whether the budgets are tracking budgets (True) or envelope budgets (False).
Methods:
-
from_month–Returns the budget for a particular month. If missing, will return None.
Attributes:
-
total_income(Decimal) –Returns the total income for all months in the list.
-
total_spent(Decimal) –Returns the total amount spent for all months in the list.
-
total_budgeted(Decimal) –Returns the total budgeted for all months in the list.
Source code in actual/budgets.py
total_income
property
total_income: Decimal
Returns the total income for all months in the list.
This is not a relevant metric in general as it is the simple sum of all income amounts.
total_spent
property
total_spent: Decimal
Returns the total amount spent for all months in the list.
total_budgeted
property
total_budgeted: Decimal
Returns the total budgeted for all months in the list.
This is not a relevant metric in general as it is the simple sum of all budgeted amounts.
from_month
from_month(
month: date,
) -> EnvelopeBudget | TrackingBudget | None
Returns the budget for a particular month. If missing, will return None.
Source code in actual/budgets.py
get_budget_history
get_budget_history(
s: Session, until: date | None = None
) -> BudgetList
Returns the budget history from the first available month to the given month, as iterable.
If no month is given, the current month is used.
Example:
import datetime
from actual import Actual
from actual.budgets import get_budget_history
with Actual("http://localhost:5006", password="mypass", file="Budget") as actual:
# get the history until the latest month
history = get_budget_history(actual.session)
# select the latest month
print(history[-1])
# If you want a similar object than the Actual JS API, you can convert it to a dictionary:
print(history[-1].as_dict())
Parameters:
-
(sSession) –Session from the Actual local database.
-
(untildate | None, default:None) –Month to get budgets for, as a date for that month. Use
datetime.date.today()if you want current data.