Database models
database
This file was partially generated using sqlacodegen using the downloaded version of the db.sqlite file export in order to update this file, you can generate the code with:
and patch the necessary models by merging the results. The BaseModel defines all models
that can be updated from the user, and must contain a unique id. Those models can then be converted automatically
into a protobuf change message using BaseModel.convert.
It is preferred to create database entries using the queries, rather than using the raw database model.
Classes:
-
TableColumnsEntry– -
BaseModel– -
Meta– -
Migrations– -
Accounts–Represents an account entity with detailed attributes describing account properties, transactions, and
-
Banks– -
Categories–Stores the category list, which is the classification applied on top of the transaction.
-
CategoryGroups–Stores the groups that the categories can belong to.
-
CategoryMapping– -
CreatedBudgets– -
CustomReports–Metadata for all the custom reports available on the Actual frontend.
-
Dashboard–A dashboard holds the JSON information in the
metacolumn. -
DashboardPages–Named collection of multiple Dashboard objects in one dashboard page.
-
Kvcache– -
KvcacheKey– -
MessagesClock– -
MessagesCrdt– -
Notes–Stores the description of each account.
-
PayeeMapping– -
Payees–Stores the individual payees.
-
Preferences–Stores the preferences for the user, using key/value pairs.
-
Rules–Stores all rules on the budget. The conditions and actions are stored separately using the JSON format.
-
Schedules–Stores the schedules defined by the user. Is also linked to a rule that executes it.
-
SchedulesJsonPaths– -
SchedulesNextDate– -
Tags– -
TransactionFilters– -
Transactions–Contains all transactions inserted into Actual.
-
ZeroBudgetMonths–Holds the amount of budget held for the next month for a specific budget id.
-
BaseBudgets–Hosts the shared code between both ZeroBudgets and
-
ReflectBudgets–Stores the budgets, when using tracking budget.
-
ZeroBudgets–Stores the budgets, when using envelope budget (default).
-
PendingTransactions–
Functions:
-
reflect_model–Reflects the current state of the database, containing the state of all remote tables and columns.
-
get_class_from_reflected_table_name–Returns, based on the defined tables on the reflected model the corresponding SQLAlchemy table.
-
get_attribute_from_reflected_table_name–Returns, based on the defined reflected model the corresponding and the SAColumn.
-
get_class_by_table_name–Returns, based on the defined tables
__tablename__the corresponding SQLModel object. -
get_attribute_by_table_name–Returns, based on the defined tables
__tablename__and the SAColumn name, the correct pydantic attribute. -
apply_change–This function upserts multiple changes into a table based on the
table_idas the primary key. -
strong_reference_session–References a session so that all object instances created on the session can be tracked.
TableColumnsEntry
BaseModel
Bases: SQLModel
Parameters:
-
(idstr) –
Methods:
-
convert–Convert the object into distinct entries for sync method. Based on the [original implementation](
-
changed–Returns a list of attributes changed.
-
delete–Deletes the model, by setting the
tombstoneattribute to 1. It is only possible to hard delete
convert
Convert the object into distinct entries for sync method. Based on the original implementation
Source code in actual/database.py
changed
Returns a list of attributes changed.
Source code in actual/database.py
delete
Deletes the model, by setting the tombstone attribute to 1. It is only possible to hard delete
transactions by updating and re-uploading the downloaded budget.
Source code in actual/database.py
Meta
Migrations
Accounts
Bases: BaseModel
Represents an account entity with detailed attributes describing account properties, transactions, and relationships.
This class is used to model financial accounts, and it includes methods and attributes necessary for managing and interacting with account-related data.
Parameters:
-
(idstr) – -
(account_idstr | None, default:None) – -
(namestr | None, default:None) – -
(balance_currentint | None, default:None) – -
(balance_availableint | None, default:None) – -
(balance_limitint | None, default:None) – -
(maskstr | None, default:None) – -
(official_namestr | None, default:None) – -
(subtypestr | None, default:None) – -
(bank_idstr | None, default:None) – -
(offbudgetint | None, default:None) – -
(closedint | None, default:None) – -
(tombstoneint | None, default:None) – -
(sort_orderfloat | None, default:None) – -
(typestr | None, default:None) – -
(account_sync_sourcestr | None, default:None) – -
(last_syncstr | None, default:None) – -
(last_reconciledstr | None, default:None) –
Attributes:
Banks
Categories
Bases: BaseModel
Stores the category list, which is the classification applied on top of the transaction.
Each category will belong to its own category group.
Parameters:
-
(idstr) – -
(hiddenbool) – -
(namestr | None, default:None) – -
(is_incomeint | None, default:None) – -
(cat_groupstr | None, default:None) – -
(sort_orderfloat | None, default:None) – -
(tombstoneint | None, default:None) – -
(goal_defstr | None, default:None) – -
(template_settingsdict | None, default:None) –
Attributes:
CategoryGroups
CreatedBudgets
CustomReports
Bases: BaseModel
Metadata for all the custom reports available on the Actual frontend.
Parameters:
-
(idstr) – -
(namestr | None, default:None) – -
(start_datestr | None, default:None) – -
(end_datestr | None, default:None) – -
(date_staticint | None, default:None) – -
(date_rangestr | None, default:None) – -
(modestr | None, default:None) – -
(group_bystr | None, default:None) – -
(balance_typestr | None, default:None) – -
(show_emptyint | None, default:None) – -
(show_offbudgetint | None, default:None) – -
(show_hiddenint | None, default:None) – -
(show_uncategorizedint | None, default:None) – -
(selected_categoriesstr | None, default:None) – -
(graph_typestr | None, default:None) – -
(conditionsstr | None, default:None) – -
(conditions_opstr | None, default:None) – -
(metadata_str | None, default:None) – -
(intervalstr | None, default:None) – -
(color_schemestr | None, default:None) – -
(tombstoneint | None, default:None) – -
(include_currentint | None, default:None) – -
(sort_bystr | None, default:None) – -
(trim_intervalsint | None, default:None) –
Dashboard
Bases: BaseModel
A dashboard holds the JSON information in the meta column.
These dashboards are grouped together in a DashboardPages object.
Parameters:
-
(idstr) – -
(typestr | None, default:None) – -
(widthint | None, default:None) – -
(heightint | None, default:None) – -
(xint | None, default:None) – -
(yint | None, default:None) – -
(metastr | None, default:None) – -
(tombstoneint | None, default:None) – -
(dashboard_page_idstr | None, default:None) –
DashboardPages
Kvcache
KvcacheKey
MessagesClock
Bases: SQLModel
Parameters:
Methods:
-
get_clock–Gets the clock from JSON text to a dictionary with fields
timestampandmerkle. -
set_clock–Sets the clock from a dictionary and stores it in the correct format.
-
get_timestamp–Gets the timestamp from the clock value directly as a HULC_Client.
-
set_timestamp–Sets the timestamp on the clock value based on the HULC_Client
get_clock
get_clock() -> dict
Gets the clock from JSON text to a dictionary with fields timestamp and merkle.
set_clock
set_clock(value: dict)
get_timestamp
get_timestamp() -> HULC_Client
Gets the timestamp from the clock value directly as a HULC_Client.
set_timestamp
set_timestamp(client: HULC_Client) -> None
Sets the timestamp on the clock value based on the HULC_Client provided.
Source code in actual/database.py
MessagesCrdt
Notes
Payees
Bases: BaseModel
Stores the individual payees.
Each payee is a unique identifier that can be assigned to a transaction. Certain payees have empty names and are
associated to the accounts themselves, representing the transfer between one account and another. These would
have the field account not set to None.
Parameters:
-
(idstr) – -
(namestr | None, default:None) – -
(categorystr | None, default:None) – -
(tombstoneint | None, default:None) – -
(transfer_acctstr | None, default:None) – -
(favoriteint | None, default:None) – -
(learn_categoriesbool | None) –
Attributes:
balance
property
balance: Decimal
Returns the current balance of the payee. Deleted transactions are ignored.
Preferences
Rules
Bases: BaseModel
Stores all rules on the budget. The conditions and actions are stored separately using the JSON format.
The conditions are stored as a text field, but can be retrieved as a model using get_ruleset.
Parameters:
-
(idstr) – -
(stagestr | None, default:None) – -
(conditionsstr | None, default:None) – -
(actionsstr | None, default:None) – -
(tombstoneint | None, default:None) – -
(conditions_opstr | None, default:None) –
Schedules
Bases: BaseModel
Stores the schedules defined by the user. Is also linked to a rule that executes it.
Parameters:
-
(idstr) – -
(rule_idstr | None, default:None) – -
(activeint | None, default:None) – -
(completedint | None, default:None) – -
(posts_transactionint | None, default:None) – -
(tombstoneint | None, default:None) – -
(namestr | None, default:None) –
SchedulesJsonPaths
SchedulesNextDate
Bases: BaseModel
Parameters:
-
(idstr) – -
(schedule_idstr | None, default:None) – -
(local_next_dateint | None, default:None) – -
(local_next_date_tsint | None, default:None) – -
(base_next_dateint | None, default:None) – -
(base_next_date_tsint | None, default:None) – -
(tombstoneint | None, default:None) –
Tags
Bases: BaseModel
Parameters:
-
(idstr) – -
(tagstr | None, default:None) – -
(colorstr | None, default:None) –Color in hex format (i.e. '#690CB0')
-
(descriptionstr | None, default:None) – -
(tombstoneint | None, default:None) –
Attributes:
-
transactions(Sequence[Transactions]) –Returns all transactions with this tag associated to them.
transactions
property
transactions: Sequence[Transactions]
Returns all transactions with this tag associated to them.
TransactionFilters
Transactions
Bases: BaseModel
Contains all transactions inserted into Actual.
Parameters:
-
(idstr) – -
(is_parentint | None, default:None) – -
(is_childint | None, default:None) – -
(acctstr) – -
(category_idstr | None, default:None) – -
(amountint | None, default:None) – -
(payee_idstr | None, default:None) – -
(notesstr | None, default:None) – -
(dateint | None, default:None) – -
(financial_idstr | None, default:None) – -
(typestr | None, default:None) – -
(locationstr | None, default:None) – -
(errorstr | None, default:None) – -
(imported_descriptionstr | None, default:None) – -
(starting_balance_flagint | None, default:None) – -
(transferred_idstr | None, default:None) – -
(sort_orderfloat | None, default:None) – -
(tombstoneint | None, default:None) – -
(clearedint | None, default:None) – -
(pendingint | None, default:None) – -
(parent_idstr | None, default:None) – -
(schedule_idstr | None, default:None) – -
(reconciledint | None, default:None) – -
(raw_synced_datastr | None, default:None) –
Methods:
-
get_date–Returns the transaction date as a datetime.date object, instead of as a string.
-
set_date–Sets the transaction date as a datetime.date object, instead of as a string.
-
set_amount–Sets the amount as a decimal.Decimal object, instead of as an integer representing the number of cents.
-
get_amount–Returns the amount as a decimal.Decimal, instead of as an integer representing the number of cents.
-
validate_cleared–Add an validator which ensures that clearing parent transactions also affects all splits
-
delete–Overload the delete() from the BaseModel so that we can properly delete any children splits
get_date
get_date() -> date
Returns the transaction date as a datetime.date object, instead of as a string.
set_date
set_date(date: date)
set_amount
Sets the amount as a decimal.Decimal object, instead of as an integer representing the number of cents.
get_amount
get_amount() -> Decimal
Returns the amount as a decimal.Decimal, instead of as an integer representing the number of cents.
validate_cleared
Add an validator which ensures that clearing parent transactions also affects all splits
Source code in actual/database.py
delete
Overload the delete() from the BaseModel so that we can properly delete any children splits as well. Otherwise things will not add up in the Actual GUI when calling delete() on a parent.
It is technically possible to call delete() a child transaction, that would probably also cause things to go out of sync ,but since that is not possible to do in the UI this case is not handled here and is left as undefined behaviour.
Neither is it handled if the tombstone flag is set directly on an object without using the delete() metod. If you are into this direct attribute modification you will have to handle the splits yourself.
Source code in actual/database.py
ZeroBudgetMonths
Bases: BaseModel
Holds the amount of budget held for the next month for a specific budget id.
Only applies to envelope budgets and is attached to a ZeroBudgets object.
The month data is stored on the id field instead of the default uuid as id. Here, Actual actually ignores the
previous models for the int dates and instead uses a string with "-" as separator (i.e., '2025-09'). The
buffered represents the amount held for the next month in cents as usual.
Parameters:
Methods:
-
get_month–Returns the month as a datetime.date object, instead of as a string.
-
set_month–Sets the month as a datetime.date object, instead of as a string.
-
set_amount–Sets the amount as a decimal.Decimal object, instead of as an integer representing the number of cents.
-
get_amount–Returns the amount being held for next month for a budget as a
decimal.Decimal.
BaseBudgets
Bases: BaseModel
Hosts the shared code between both ZeroBudgets and ReflectBudgets.
Each budget will represent a certain month in a certain category. When a budget is missing on the frontend, frontend will assume this value is zero, but the entity will be missing from the database.
Parameters:
-
(idstr) – -
(monthint | None, default:None) – -
(category_idstr | None, default:None) – -
(amountint | None, default:None) – -
(carryoverint | None, default:None) –
Methods:
-
get_date–Returns the transaction date as a datetime.date object, instead of as a string.
-
set_date–Sets the transaction date as a datetime.date object, instead of as a string.
-
set_amount–Sets the amount as a decimal.Decimal object, instead of as an integer representing the number of cents.
-
get_amount–Returns the amount as a decimal.Decimal, instead of as an integer representing the number of cents.
Attributes:
-
range(tuple[date, date]) –Range of the budget as a tuple [start, end).
-
balance(Decimal) –Returns the current spent balance of the budget.
-
notes(str | None) –Returns notes for the budget. If none is present, returns
None.
range
property
Range of the budget as a tuple [start, end).
The end date is not inclusive, as it represents the start of the next month.
balance
property
balance: Decimal
Returns the current spent balance of the budget.
The evaluation will take into account the budget month and only selected transactions for the combination month and category. Deleted transactions are ignored.
If you want to get the balance from the frontend, take a look at the query get_accumulated_budgeted_balance instead.
notes
property
writable
notes: str | None
Returns notes for the budget. If none is present, returns None.
get_date
get_date() -> date
Returns the transaction date as a datetime.date object, instead of as a string.
set_date
set_date(date: date)
Sets the transaction date as a datetime.date object, instead of as a string.
If the date value contains a day, it will be truncated and only the month and year will be inserted, as the budget applies to a month.
Source code in actual/database.py
set_amount
Sets the amount as a decimal.Decimal object, instead of as an integer representing the number of cents.
get_amount
get_amount() -> Decimal
Returns the amount as a decimal.Decimal, instead of as an integer representing the number of cents.
ReflectBudgets
Bases: BaseBudgets
Stores the budgets, when using tracking budget.
This table will only contain data for the entries which are created. If a combination of category and budget month is not existing, it is assumed that the budget is 0.
Parameters:
-
(idstr) – -
(monthint | None, default:None) – -
(category_idstr | None, default:None) – -
(amountint | None, default:None) – -
(carryoverint | None, default:None) – -
(goalint | None, default:None) – -
(long_goalint | None, default:None) –
ZeroBudgets
Bases: BaseBudgets
Stores the budgets, when using envelope budget (default).
This table will only contain data for the entries which are created. If a combination of category and budget month is not existing, it is assumed that the budget is 0.
Parameters:
-
(idstr) – -
(monthint | None, default:None) – -
(category_idstr | None, default:None) – -
(amountint | None, default:None) – -
(carryoverint | None, default:None) – -
(goalint | None, default:None) – -
(long_goalint | None, default:None) –
PendingTransactions
reflect_model
Reflects the current state of the database, containing the state of all remote tables and columns.
get_class_from_reflected_table_name
get_class_from_reflected_table_name(
metadata: MetaData, table_name: str
) -> Table | None
Returns, based on the defined tables on the reflected model the corresponding SQLAlchemy table.
If not found, returns None.
Source code in actual/database.py
get_attribute_from_reflected_table_name
get_attribute_from_reflected_table_name(
metadata: MetaData, table_name: str, column_name: str
) -> Column | None
Returns, based on the defined reflected model the corresponding and the SAColumn.
If not found, returns None.
Source code in actual/database.py
get_class_by_table_name
get_class_by_table_name(table_name: str) -> type[BaseModel]
Returns, based on the defined tables __tablename__ the corresponding SQLModel object.
If not found, raises ValueError.
Parameters:
-
(table_namestr) –SQL table name.
Returns:
Raises:
-
ValueError–Raises
ValueErrorif the table name is not existing.
Source code in actual/database.py
get_attribute_by_table_name
get_attribute_by_table_name(
table_name: str, column_name: str, reverse: bool = False
) -> str | None
Returns, based on the defined tables __tablename__ and the SAColumn name, the correct pydantic attribute.
The search can be reversed by setting the reverse flag to True. If not found, returns None.
Parameters:
-
(table_namestr) –SQL table name.
-
(column_namestr) –SQL column name.
-
(reversebool, default:False) –If true, reverses the search and returns the SAColumn from the Pydantic attribute.
Returns:
-
str | None–Pydantic attribute name or SAColumn name.
Source code in actual/database.py
apply_change
apply_change(
session: Session,
table: Table,
table_id: str,
values: dict[Column, str | int | float | None],
) -> None
This function upserts multiple changes into a table based on the table_id as the primary key.
All the values will be inserted as a new row, and if the id already exists, the values will be updated.
This function has no return value, as the insert statement was crafter to execute as quick as possible.
Source code in actual/database.py
strong_reference_session
References a session so that all object instances created on the session can be tracked.
This is used to make sure that every update on the budget via the library can be converted to a sync request that will be sent to the Actual server.