Project Documentation
Micro YNAB - a small SDK for YNAB API
__main__
account()
budget()
category()
cli()
format_table(data, headers=None)
Format a table from sequences of strings with optional headers, properly handling Unicode characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Sequence[Sequence[str]]
|
Sequence of sequences where each inner sequence represents a row |
required |
headers
|
Sequence[str] | None
|
Optional sequence of column headers |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted table as string with aligned columns |
Source code in src/uynab/__main__.py
get_string_display_width(s)
Calculate the display width of a string, handling emoji and other Unicode characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
Input string |
required |
Returns:
| Type | Description |
|---|---|
int
|
Display width of the string |
Source code in src/uynab/__main__.py
get_ynab_client()
Get a YNABClient instance, prompting for an API token if not already set.
Source code in src/uynab/__main__.py
list_accounts(budget_id)
List accounts for a specific budget.
Source code in src/uynab/__main__.py
list_budgets()
List all available budgets.
Source code in src/uynab/__main__.py
list_categories(budget_id)
List categories for a specific budget.
Source code in src/uynab/__main__.py
list_payees(budget_id, json_output)
List payees for a specific budget.
Source code in src/uynab/__main__.py
parse_all_account_list(accounts)
Parse a list of Account objects into a list of tuples with basic account information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accounts
|
list[Account]
|
A list of Account objects to be parsed. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple]
|
list[tuple[str, float, UUID]]: A list of tuples where each tuple contains: - account name (str) - account balance (float) - account ID (UUID) |
Source code in src/uynab/__main__.py
parse_all_budget_list(budgets)
Convert a list of BudgetSummary objects into a list of tuples containing budget names and IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budgets
|
list[BudgetSummary]
|
List of BudgetSummary objects to process |
required |
Returns:
| Type | Description |
|---|---|
list[tuple]
|
list[tuple[str, UUID]]: List of tuples where each tuple contains (budget_name, budget_id) |
Source code in src/uynab/__main__.py
parse_all_category_list(categories)
Transforms a list of CategoryGroup objects into a list of tuples for display purposes.
Each tuple in the resulting list contains either: - A category group header: ("--- Category Group ---", "--- {group_name} ---") - A category entry: (category_name, category_id)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
categories
|
list[CategoryGroup]
|
List of CategoryGroup objects to be parsed |
required |
Returns:
| Type | Description |
|---|---|
list[tuple]
|
list[tuple[str, UUID]]: List of tuples containing category group headers and category entries |
Source code in src/uynab/__main__.py
client
YNABClient
Bases: Client
A client for interacting with the YNAB (You Need A Budget) API.
Attributes:
| Name | Type | Description |
|---|---|---|
api_token |
str
|
The API token for authenticating requests. |
base_url |
str
|
The base URL for the YNAB API. |
session |
Session
|
The session object for making HTTP requests. |
Methods:
| Name | Description |
|---|---|
request |
Makes an HTTP request to the YNAB API. |
Properties
account (AccountService): Returns the account service. budget (BudgetService): Returns the budget service. category (CategoryService): Returns the category service. payee (PayeeService): Returns the payee service. transaction (TransactionService): Returns the transaction service.
Source code in src/uynab/client.py
set_token(new_token)
Safely update the API token after the client instance is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_token
|
str
|
New API token. |
required |
Source code in src/uynab/client.py
model
account
Model account module
This module defines the data models for representing financial accounts and their related responses and requests.
Classes:
| Name | Description |
|---|---|
Account |
Represents a financial account with various attributes such as id, name, type, balance, etc. |
ResponseDataAccount |
Represents the response data for a single account. |
ResponseAccount |
Represents the response for a single account. |
ResponseDataAccounts |
Represents the response data for a list of accounts. |
ResponseAccounts |
Represents the response for a list of accounts. |
RequestAccount |
Represents the request data for creating or updating an account. |
RequestDataAccount |
Represents the request data wrapper for an account. |
Account
Bases: BaseModel
Account model representing a financial account.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Unique identifier for the account. |
name |
str
|
Name of the account. |
type |
str
|
Type of the account (e.g., checking, savings). |
on_budget |
bool
|
Indicates if the account is on budget. |
closed |
bool
|
Indicates if the account is closed. |
note |
Optional[str]
|
Additional notes about the account. |
balance |
int
|
Current balance of the account. |
cleared_balance |
int
|
Cleared balance of the account. |
uncleared_balance |
int
|
Uncleared balance of the account. |
transfer_payee_id |
UUID
|
Identifier for the transfer payee. |
direct_import_linked |
bool
|
Indicates if the account is linked for direct import. |
direct_import_in_error |
bool
|
Indicates if there is an error with direct import. |
last_reconciled_at |
Optional[str]
|
Timestamp of the last reconciliation. |
debt_original_balance |
Optional[int]
|
Original balance of the debt. |
debt_interest_rates |
dict[datetime, int]
|
Interest rates of the debt over time. |
debt_minimum_payments |
dict[datetime, int]
|
Minimum payments of the debt over time. |
debt_escrow_amounts |
dict[datetime, int]
|
Escrow amounts of the debt over time. |
deleted |
bool
|
Indicates if the account is deleted. |
Source code in src/uynab/model/account.py
RequestAccount
Bases: BaseModel
RequestAccount model representing an account request. Attributes: name (str): The name of the account. type (str): The type of the account. balance (int): The balance of the account.
Source code in src/uynab/model/account.py
RequestDataAccount
Bases: BaseModel
RequestDataAccount is a data model that represents the request data for an account.
Attributes:
| Name | Type | Description |
|---|---|---|
account |
RequestAccount
|
An instance of RequestAccount containing the account details. |
Source code in src/uynab/model/account.py
ResponseAccount
ResponseAccounts
ResponseDataAccount
ResponseDataAccounts
Bases: BaseModel
ResponseDataAccounts is a model representing the response data for a list of accounts.
Source code in src/uynab/model/account.py
budget
Model budget module.
This module defines the models related to budgets in the application using Pydantic BaseModel.
Classes:
| Name | Description |
|---|---|
Budget |
Represents a budget with various attributes such as accounts, payees, categories, and transactions. |
ResponseDataBudget |
Represents the response data for a single budget. |
ResponseBudget |
Represents the response structure for a single budget. |
ResponseDataBudgets |
Represents the response data for multiple budgets. |
ResponseBudgets |
Represents the response structure for multiple budgets. |
BudgetSettings |
Represents the settings for a budget, including date and currency formats. |
ResponseDataBudgetSettings |
Represents the response data for budget settings. |
ResponseBudgetSettings |
Represents the response structure for budget settings. |
Budget
Bases: BaseModel
A class representing a budget in the application.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
The unique identifier of the budget. |
name |
str
|
The name of the budget. |
last_modified_on |
datetime
|
The date and time when the budget was last modified. |
first_month |
datetime
|
The first month of the budget. |
last_month |
datetime
|
The last month of the budget. |
date_format |
DateFormat
|
The date format used in the budget. |
currency_format |
CurrencyFormat
|
The currency format used in the budget. |
accounts |
list[Account]
|
A list of accounts associated with the budget. |
payees |
list[Payee]
|
A list of payees associated with the budget. |
payee_locations |
list[dict]
|
A list of payee locations associated with the budget. |
category_groups |
list[CategoryGroup]
|
A list of category groups in the budget. |
categories |
list[Category]
|
A list of categories in the budget. |
months |
list[Month]
|
A list of months in the budget. |
transactions |
list[TransactionSummary]
|
A list of transactions in the budget. |
subtransactions |
list[Subtransaction]
|
A list of subtransactions in the budget. |
scheduled_transactions |
list[dict]
|
A list of scheduled transactions in the budget. |
scheduled_subtransactions |
list[dict]
|
A list of scheduled subtransactions in the budget. |
Source code in src/uynab/model/budget.py
BudgetSettings
Bases: BaseModel
A class used to represent the settings for a budget.
Attributes:
| Name | Type | Description |
|---|---|---|
date_format |
dict
|
A dictionary representing the format for dates. |
currency_format |
dict
|
A dictionary representing the format for currency. |
Source code in src/uynab/model/budget.py
BudgetSummary
Bases: BaseModel
BudgetSummary model representing a summary of a budget. Attributes: id (UUID): Unique identifier for the budget. name (str): Name of the budget. last_modified_on (datetime): Timestamp of the last modification. first_month (datetime): The first month of the budget. last_month (datetime): The last month of the budget. date_format (Optional[DateFormat]): The date format used in the budget. currency_format (Optional[CurrencyFormat]): The currency format used in the budget.
Source code in src/uynab/model/budget.py
ResponseBudget
Bases: BaseModel
ResponseBudget is a model representing the response structure for a budget.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataBudget
|
The data attribute containing the budget details. |
Source code in src/uynab/model/budget.py
ResponseBudgetSettings
Bases: BaseModel
ResponseBudgetSettings is a model representing the settings of a budget response.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataBudgetSettings
|
The data containing the budget settings. |
Source code in src/uynab/model/budget.py
ResponseBudgets
Bases: BaseModel
ResponseBudgets is a model representing the response structure for budget-related data.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataBudgets
|
The data attribute containing budget-related information. |
Source code in src/uynab/model/budget.py
ResponseDataBudget
Bases: BaseModel
ResponseDataBudget is a model representing the response data for a budget.
Attributes:
| Name | Type | Description |
|---|---|---|
budget |
Budget
|
The budget data. |
server_knowledge |
int
|
The server knowledge value. |
Source code in src/uynab/model/budget.py
ResponseDataBudgetSettings
Bases: BaseModel
ResponseDataBudgetSettings is a model representing the settings of a budget response.
Attributes:
| Name | Type | Description |
|---|---|---|
settings |
BudgetSettings
|
The settings of the budget. |
Source code in src/uynab/model/budget.py
ResponseDataBudgets
Bases: BaseModel
ResponseDataBudgets is a model representing the response data for budgets.
Attributes:
| Name | Type | Description |
|---|---|---|
budgets |
list[BudgetSummary]
|
A list of Budget objects. |
default_budget |
Optional[BudgetSummary]
|
The default Budget object. |
Source code in src/uynab/model/budget.py
category
Model category module.
This module defines models for representing financial categories and category groups within a budgeting application.
Classes:
| Name | Description |
|---|---|
Category |
Represents a financial category with various attributes such as id, name, budgeted amount, and goal details. |
ResponseDataCategory |
Represents the response data for a single category. |
ResponseCategory |
Represents the response structure for a category. |
CategoryGroup |
Represents a group of categories with attributes such as id, name, and a list of categories. |
ResponseDataCategoryGroup |
Represents the response data for a category group, including server knowledge. |
ResponseCategoryGroup |
Represents the response structure for a category group. |
Each class uses Pydantic's BaseModel to enforce type validation and provide serialization/deserialization capabilities.
Category
Bases: BaseModel
Category model representing a financial category.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Unique identifier for the category. |
category_group_id |
UUID
|
Identifier for the category group. |
category_group_name |
str
|
Name of the category group. |
name |
str
|
Name of the category. |
hidden |
bool
|
Indicates if the category is hidden. |
original_category_group_id |
Optional[UUID]
|
Original identifier for the category group, if any. |
note |
Optional[str]
|
Additional notes for the category. |
budgeted |
int
|
Budgeted amount for the category. |
activity |
int
|
Activity amount for the category. |
balance |
int
|
Balance amount for the category. |
goal_type |
Optional[Literal['TB', 'TBD', 'MF', 'NEED', 'DEBT']]
|
Type of goal associated with the category. |
goal_needs_whole_amount |
Optional[bool]
|
Indicates if the goal needs the whole amount. |
goal_day |
Optional[int]
|
Day associated with the goal. |
goal_cadence |
Optional[int]
|
Cadence of the goal. |
goal_cadence_frequency |
Optional[int]
|
Frequency of the goal cadence. |
goal_creation_month |
Optional[str]
|
Month when the goal was created. |
goal_target |
Optional[int]
|
Target amount for the goal. |
goal_target_month |
Optional[str]
|
Target month for the goal. |
goal_percentage_complete |
Optional[int]
|
Percentage of goal completion. |
goal_months_to_budget |
Optional[int]
|
Number of months to budget for the goal. |
goal_under_funded |
Optional[int]
|
Amount underfunded for the goal. |
goal_overall_funded |
Optional[int]
|
Overall funded amount for the goal. |
goal_overall_left |
Optional[int]
|
Overall amount left for the goal. |
deleted |
bool
|
Indicates if the category is deleted. |
Source code in src/uynab/model/category.py
CategoryGroup
Bases: BaseModel
Represents a group of categories in the budgeting application.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
The unique identifier of the category group. |
name |
str
|
The name of the category group. |
hidden |
bool
|
Indicates whether the category group is hidden. |
deleted |
bool
|
Indicates whether the category group is deleted. |
categories |
list[Category]
|
A list of categories that belong to this group. |
Source code in src/uynab/model/category.py
ResponseCategory
Bases: BaseModel
ResponseCategory is a model representing the response structure for a category.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataCategory
|
The data attribute containing the category details. |
Source code in src/uynab/model/category.py
ResponseCategoryGroup
Bases: BaseModel
ResponseCategoryGroup represents a category group in the response model.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataCategoryGroup
|
The data associated with the category group. |
Source code in src/uynab/model/category.py
ResponseDataCategory
Bases: BaseModel
ResponseDataCategory is a model that represents the response data for a category.
Attributes:
| Name | Type | Description |
|---|---|---|
category |
Category
|
The category object associated with the response. |
Source code in src/uynab/model/category.py
ResponseDataCategoryGroup
Bases: BaseModel
ResponseDataCategoryGroup represents the response data for a category group.
Attributes:
| Name | Type | Description |
|---|---|---|
category_groups |
list[CategoryGroup]
|
A list of category groups. |
server_knowledge |
int
|
The server knowledge value. |
Source code in src/uynab/model/category.py
payee
Model payee module.
This module contains Pydantic models for validating and managing data structures related to payees in the YNAB API. These models ensure consistency when working with API request and response payloads.
Classes:
| Name | Description |
|---|---|
- Payee |
Represents a single payee object. |
- ResponseDataPayee |
Wraps a single payee in the response's |
- ResponsePayee |
Represents the full API response for a single payee. |
- ResponseDataPayees |
Wraps a list of payees and server knowledge metadata. |
- ResponsePayees |
Represents the full API response for multiple payees. |
- RequestPayee |
Represents the structure of a single payee in request payloads. |
- RequestDataPayee |
Wraps the |
Example Usage
from uynab.model.payee import Payee, ResponsePayee
# Validating a single payee response
response_data = {
"data": {
"payee": {
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "Test Payee",
"transfer_account_id": None,
"deleted": False
}
}
}
validated_response = ResponsePayee(**response_data)
print(validated_response.data.payee.name) # Output: Test Payee
Payee
Bases: BaseModel
Represents a payee in the YNAB system.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
The unique identifier of the payee. |
name |
str
|
The name of the payee. |
transfer_account_id |
Optional[str]
|
The ID of the associated transfer account, if applicable. |
deleted |
bool
|
Indicates whether the payee has been deleted. |
Source code in src/uynab/model/payee.py
RequestDataPayee
Bases: BaseModel
Represents the structure of the payee field in a request payload.
Attributes:
| Name | Type | Description |
|---|---|---|
payee |
RequestPayee
|
The wrapper for the payee data in the request payload. |
Source code in src/uynab/model/payee.py
RequestPayee
Bases: BaseModel
Represents the structure of a request payload to update a payee.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The new name of the payee. |
Source code in src/uynab/model/payee.py
ResponseDataPayee
Bases: BaseModel
Represents the structure of the data field in a response containing a single payee.
Attributes:
| Name | Type | Description |
|---|---|---|
payee |
Payee
|
The payee object returned in the response. |
Source code in src/uynab/model/payee.py
ResponseDataPayees
Bases: BaseModel
Represents the structure of the data field in a response containing multiple payees.
Attributes:
| Name | Type | Description |
|---|---|---|
payees |
list[Payee]
|
A list of payee objects. |
server_knowledge |
int
|
A server-provided knowledge value for caching or synchronization. |
Source code in src/uynab/model/payee.py
ResponsePayee
Bases: BaseModel
Represents the full API response containing a single payee.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataPayee
|
The wrapper for the payee data in the response. |
Source code in src/uynab/model/payee.py
ResponsePayees
Bases: BaseModel
Represents the full API response containing multiple payees.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataPayees
|
The wrapper for the list of payee data and metadata in the response. |
Source code in src/uynab/model/payee.py
transaction
Model transaction module
This module defines various Pydantic models for representing financial transactions and their related data.
Classes:
| Name | Description |
|---|---|
Subtransaction |
Represents a subtransaction within a transaction. |
SaveSubTransaction |
Represents a sub-transaction to be saved. |
TransactionDetail |
Represents the details of a financial transaction. |
TransactionSummary |
Represents a summary of a financial transaction. |
NewTransaction |
Represents a new financial transaction. |
ResponseDataTransaction |
Represents the response data for a transaction. |
ResponseTransaction |
Represents a transaction response. |
ResponseDataTransactions |
Represents the response data for multiple transactions. |
ResponseTransactions |
Represents the response containing transaction data. |
ResponseDataSaveTransactions |
Represents the response data for saving transactions. |
ResponseSaveTransactions |
Represents the response received after saving transactions. |
NewTransaction
Bases: BaseModel
NewTransaction model representing a financial transaction.
Attributes:
| Name | Type | Description |
|---|---|---|
account_id |
UUID
|
The unique identifier for the account. |
date |
date
|
The date of the transaction. |
amount |
int
|
The amount of the transaction in the smallest currency unit (e.g., cents). |
payee_id |
Optional[UUID]
|
The unique identifier for the payee (optional). |
payee_name |
Optional[str]
|
The name of the payee (optional). |
category_id |
Optional[UUID]
|
The unique identifier for the category (optional). |
memo |
Optional[str]
|
A memo or note associated with the transaction (optional). |
cleared |
Literal['cleared', 'uncleared', 'reconciled']
|
The cleared status of the transaction. |
approved |
bool
|
Whether the transaction is approved. |
flag_color |
Optional[str]
|
The color of the flag associated with the transaction (optional). |
import_id |
Optional[str]
|
The import identifier for the transaction (optional). |
subtransactions |
list[SaveSubTransaction]
|
A list of subtransactions associated with this transaction. |
Source code in src/uynab/model/transaction.py
ResponseDataSaveTransactions
Bases: BaseModel
ResponseDataSaveTransactions is a model representing the response data for saving transactions.
Attributes:
| Name | Type | Description |
|---|---|---|
transaction_ids |
list[str]
|
A list of transaction IDs. |
transactions |
list[TransactionDetail]
|
A list of transaction details. |
duplicate_import_ids |
list[str]
|
A list of duplicate import IDs. |
server_knowledge |
int
|
The server knowledge value. |
Source code in src/uynab/model/transaction.py
ResponseDataTransaction
Bases: BaseModel
ResponseDataTransaction is a model that represents the response data for a transaction.
Attributes:
| Name | Type | Description |
|---|---|---|
transaction |
TransactionDetail
|
Detailed information about the transaction. |
Source code in src/uynab/model/transaction.py
ResponseDataTransactions
Bases: BaseModel
ResponseDataTransactions is a model representing the response data for transactions.
Attributes:
| Name | Type | Description |
|---|---|---|
transactions |
list[TransactionDetail]
|
A list of transaction details. |
server_knowledge |
int
|
An integer representing the server's knowledge of the current state. |
Source code in src/uynab/model/transaction.py
ResponseSaveTransactions
Bases: BaseModel
ResponseSaveTransactions is a model representing the response received after saving transactions.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataSaveTransactions
|
The data related to the saved transactions. |
Source code in src/uynab/model/transaction.py
ResponseTransaction
Bases: BaseModel
ResponseTransaction is a model representing a transaction response.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataTransaction
|
The data associated with the transaction response. |
Source code in src/uynab/model/transaction.py
ResponseTransactions
Bases: BaseModel
ResponseTransactions is a model that represents the response containing transaction data.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ResponseDataTransactions
|
The transaction data included in the response. |
Source code in src/uynab/model/transaction.py
SaveSubTransaction
Bases: BaseModel
Represents a sub-transaction to be saved.
Attributes:
| Name | Type | Description |
|---|---|---|
amount |
int
|
The amount of the sub-transaction. |
payee_id |
Optional[UUID]
|
The ID of the payee associated with the sub-transaction. |
payee_name |
Optional[str]
|
The name of the payee associated with the sub-transaction. |
category_id |
Optional[UUID]
|
The ID of the category associated with the sub-transaction. |
memo |
Optional[str]
|
An optional memo for the sub-transaction. |
Source code in src/uynab/model/transaction.py
Subtransaction
Bases: BaseModel
Represents a subtransaction within a transaction.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Unique identifier for the subtransaction. |
transaction_id |
UUID
|
Unique identifier for the parent transaction. |
amount |
int
|
The amount of the subtransaction. |
memo |
Optional[str]
|
An optional memo for the subtransaction. |
payee_id |
Optional[UUID]
|
Optional unique identifier for the payee. |
payee_name |
Optional[str]
|
Optional name of the payee. |
category_id |
Optional[UUID]
|
Optional unique identifier for the category. |
category_name |
Optional[str]
|
Optional name of the category. |
transfer_account_id |
Optional[UUID]
|
Optional unique identifier for the transfer account. |
transfer_transaction_id |
Optional[UUID]
|
Optional unique identifier for the transfer transaction. |
deleted |
bool
|
Indicates whether the subtransaction is deleted. |
Source code in src/uynab/model/transaction.py
TransactionDetail
Bases: BaseModel
TransactionDetail represents the details of a financial transaction.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the transaction. |
date |
date
|
The date of the transaction. |
amount |
int
|
The amount of the transaction in the smallest currency unit (e.g., cents). |
memo |
Optional[str]
|
A memo or note associated with the transaction. |
cleared |
Literal['cleared', 'uncleared', 'reconciled']
|
The cleared status of the transaction. |
approved |
bool
|
Indicates whether the transaction is approved. |
flag_color |
Optional[FlagColor]
|
The color of the flag associated with the transaction. |
flag_name |
Optional[str]
|
The name of the flag associated with the transaction. |
account_id |
UUID
|
The unique identifier of the account associated with the transaction. |
payee_id |
Optional[UUID]
|
The unique identifier of the payee associated with the transaction. |
category_id |
Optional[UUID]
|
The unique identifier of the category associated with the transaction. |
transfer_account_id |
Optional[UUID]
|
The unique identifier of the transfer account associated with the transaction. |
transfer_transaction_id |
Optional[str]
|
The unique identifier of the transfer transaction associated with the transaction. |
matched_transaction_id |
Optional[str]
|
The unique identifier of the matched transaction associated with the transaction. |
import_id |
Optional[UUID]
|
The unique identifier of the import associated with the transaction. |
import_payee_name |
Optional[str]
|
The name of the payee as imported. |
import_payee_name_original |
Optional[str]
|
The original name of the payee as imported. |
debt_transaction_type |
Optional[str]
|
The type of debt transaction. |
deleted |
bool
|
Indicates whether the transaction is deleted. |
account_name |
str
|
The name of the account associated with the transaction. |
payee_name |
Optional[str]
|
The name of the payee associated with the transaction. |
category_name |
Optional[str]
|
The name of the category associated with the transaction. |
subtransactions |
list[Subtransaction]
|
A list of subtransactions associated with the transaction. |
Source code in src/uynab/model/transaction.py
TransactionSummary
Bases: BaseModel
TransactionSummary represents a summary of a financial transaction.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the transaction. |
date |
date
|
The date of the transaction. |
amount |
int
|
The amount of the transaction in the smallest currency unit (e.g., cents). |
memo |
Optional[str]
|
A memo or note associated with the transaction. |
cleared |
Literal['cleared', 'uncleared', 'reconciled']
|
The cleared status of the transaction. |
approved |
bool
|
Indicates whether the transaction is approved. |
flag_color |
Optional[FlagColor]
|
The color of the flag associated with the transaction. |
flag_name |
Optional[str]
|
The name of the flag associated with the transaction. |
account_id |
UUID
|
The unique identifier of the account associated with the transaction. |
payee_id |
Optional[UUID]
|
The unique identifier of the payee associated with the transaction. |
category_id |
Optional[UUID]
|
The unique identifier of the category associated with the transaction. |
transfer_account_id |
Optional[UUID]
|
The unique identifier of the transfer account associated with the transaction. |
transfer_transaction_id |
Optional[str]
|
The unique identifier of the transfer transaction associated with the transaction. |
matched_transaction_id |
Optional[str]
|
The unique identifier of the matched transaction. |
import_id |
Optional[UUID]
|
The unique identifier of the import associated with the transaction. |
import_payee_name |
Optional[str]
|
The name of the payee as imported. |
import_payee_name_original |
Optional[str]
|
The original name of the payee as imported. |
debt_transaction_type |
Optional[str]
|
The type of debt transaction. |
deleted |
bool
|
Indicates whether the transaction is deleted. |
Source code in src/uynab/model/transaction.py
utils
CurrencyFormat
Bases: BaseModel
CurrencyFormat is a model that represents the formatting details for a specific currency.
Attributes:
| Name | Type | Description |
|---|---|---|
iso_code |
str
|
The ISO 4217 code for the currency (e.g., 'USD' for US Dollar). |
example_format |
str
|
An example of how the currency is formatted (e.g., '$1,234.56'). |
decimal_digits |
int
|
The number of decimal digits used in the currency (e.g., 2 for USD). |
decimal_separator |
str
|
The character used to separate the integer part from the fractional part (e.g., '.' for USD). |
symbol_first |
bool
|
Indicates whether the currency symbol appears before the amount (True) or after (False). |
group_separator |
str
|
The character used to separate groups of thousands (e.g., ',' for USD). |
currency_symbol |
str
|
The symbol used to represent the currency (e.g., '$' for USD). |
display_symbol |
bool
|
Indicates whether the currency symbol should be displayed (True) or not (False). |
Source code in src/uynab/model/utils.py
DateFormat
Bases: BaseModel
A class used to represent a Date Format.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
str
|
A string representing the date format. For example: "YYYY-MM-DD" |
Source code in src/uynab/model/utils.py
FlagColor
Bases: StrEnum
A class used to represent the color of a flag.
Attributes:
| Name | Type | Description |
|---|---|---|
RED |
A red flag. |
|
ORANGE |
An orange flag. |
|
YELLOW |
A yellow flag. |
|
GREEN |
A green flag. |
|
BLUE |
A blue flag. |
|
PURPLE |
A purple flag. |
Source code in src/uynab/model/utils.py
Month
Bases: BaseModel
Represents a financial month with various attributes.
Attributes:
| Name | Type | Description |
|---|---|---|
month |
datetime
|
The month this instance represents. |
note |
Optional[str]
|
An optional note for the month. |
income |
int
|
The total income for the month. |
budgeted |
int
|
The total amount budgeted for the month. |
activity |
int
|
The total financial activity for the month. |
to_be_budgeted |
int
|
The amount left to be budgeted for the month. |
age_of_money |
int
|
The age of money in days. |
deleted |
bool
|
Indicates if the month record is deleted. |
categories |
list[Category]
|
A list of categories associated with the month. |
Source code in src/uynab/model/utils.py
service
account
Service account module
This module provides the AccountService class for interacting with accounts in the YNAB (You Need A Budget) API.
Classes:
| Name | Description |
|---|---|
AccountService |
A service class for performing operations related to accounts in a YNAB budget. |
budget
Service budget module
This module provides the BudgetService class for interacting with budget-related endpoints of the YNAB API.
Classes:
| Name | Description |
|---|---|
BudgetService |
A service class for retrieving and managing budgets and their settings. |
BudgetService
Bases: YNABService
Source code in src/uynab/service/budget.py
get_all_budgets()
Retrieve all budgets from the API. This method performs an API call to fetch all budgets and returns them as a list of Budget objects. Returns: list[Budget]: A list of Budget objects retrieved from the API.
Source code in src/uynab/service/budget.py
get_budget(budget_id)
Retrieve a budget by its ID. Args: budget_id (UUID): The ID of the budget to retrieve. Returns: Budget: The budget object corresponding to the provided ID.
Source code in src/uynab/service/budget.py
get_budget_settings(budget_id)
Retrieve the settings for a specific budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The ID of the budget for which to retrieve settings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
BudgetSettings |
BudgetSettings
|
The settings of the specified budget. |
Source code in src/uynab/service/budget.py
category
Service category module.
This module provides services for interacting with categories and category groups within a budget in the YNAB (You Need A Budget) application.
Classes:
| Name | Description |
|---|---|
CategoryService |
A service class for retrieving category groups and categories from a specified budget. |
CategoryService
Bases: YNABService
Source code in src/uynab/service/category.py
get_all_categories(budget_id)
Retrieve all category groups for a given budget. Inside the category group there are categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
Returns:
| Type | Description |
|---|---|
list[CategoryGroup]
|
list[CategoryGroup]: A list of category groups associated with the budget. |
Source code in src/uynab/service/category.py
get_category(budget_id, category_id)
Retrieve a specific category from a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
category_id
|
UUID
|
The unique identifier of the category. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Category |
Category
|
The category object retrieved from the budget. |
Source code in src/uynab/service/category.py
payee
Service payee module.
This module provides the PayeeService class, which encapsulates operations related to payees
in the YNAB API. It acts as an interface to manage payees for a given budget, including retrieving
payee details, fetching all payees, and updating payee information.
Classes:
| Name | Description |
|---|---|
- PayeeService |
A service for managing YNAB payees, providing methods to interact with the API. |
Example Usage
from uynab.client import YNABClient
from uynab.service.payee import PayeeService
# Initialize the API client
client = YNABClient(api_token="your-token")
# Initialize the PayeeService
payee_service = PayeeService(client)
# Fetch all payees for a specific budget
budget_id = "some-budget-id"
payees = payee_service.get_all_payees(budget_id)
# Fetch details of a specific payee
payee_id = "some-payee-id"
payee = payee_service.get_payee(budget_id, payee_id)
# Update a specific payee
updated_payee = payee_service.update_payee(
budget_id, payee_id, {"payee": {"name": "New Payee Name"}}
)
PayeeService
Bases: YNABService
A service for managing payees in the YNAB API.
This class provides methods to interact with the payees associated with a specific budget, including fetching all payees, retrieving details for a single payee, and updating payee details.
Attributes:
| Name | Type | Description |
|---|---|---|
client |
Client
|
An instance of the YNAB API client used for making requests. |
Methods:
| Name | Description |
|---|---|
get_all_payees |
UUID) -> list[Payee]: Fetch all payees associated with a specific budget. |
get_payee |
UUID, payee_id: UUID) -> Payee: Retrieve details for a single payee by ID. |
update_payee |
UUID, payee_id: UUID, data: dict) -> Payee: Update the details of a specific payee. |
Source code in src/uynab/service/payee.py
get_all_payees(budget_id)
Fetch all payees for the specific budget
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
An ID for a budget from which all payees will be fetched |
required |
Returns:
| Type | Description |
|---|---|
list[Payee]
|
list[Payee]: List of all payees for specified budget |
Source code in src/uynab/service/payee.py
get_payee(budget_id, payee_id)
Fetch a single payee
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
An ID for the budget from which payee will be fetched |
required |
payee_id
|
UUID
|
An ID of a payee to fetch |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Payee |
Payee
|
Fetched payee |
Source code in src/uynab/service/payee.py
update_payee(budget_id, payee_id, data)
Update a single payee
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
An ID for the budget from which payee will be updated |
required |
payee_id
|
UUID
|
An ID of a payee to update |
required |
data
|
dict
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Payee |
Payee
|
Updated payee |
Source code in src/uynab/service/payee.py
service
Service module
This module provides the YNABService class, which handles communication with the YNAB API.
Classes:
| Name | Description |
|---|---|
YNABService |
A service class to handle communication with YNAB. |
YNABService
A service class to handle communication with YNAB.
Attributes:
| Name | Type | Description |
|---|---|---|
client |
Client
|
The client used for communication with YNAB. |
Methods:
| Name | Description |
|---|---|
perform_api_call |
Model, method: str, endpoint: str, data: dict | None = None) -> dict: Sends a request to the specified endpoint using the given method and data. |
Source code in src/uynab/service/service.py
__init__(client)
Initialize service class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
client for communication with YNAB |
required |
perform_api_call(model, method, endpoint, params=None, data=None)
Perform an API call using the specified method and endpoint, and return the response as a model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
The model class to instantiate with the response data. |
required |
method
|
str
|
The HTTP method to use for the API call (e.g., 'GET', 'POST'). |
required |
endpoint
|
str
|
The API endpoint to call. |
required |
params
|
dict
|
The query parameters to send with the API call. Defaults to None. |
None
|
data
|
Any
|
The data to send with the API call. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Model |
Model
|
An instance of the model class populated with the response data. |
Raises:
| Type | Description |
|---|---|
ResponseError
|
If the response data cannot be validated against the model. |
Source code in src/uynab/service/service.py
transaction
Service transaction module
This module provides the TransactionService class, which is responsible for managing transactions
within a budget in the YNAB (You Need A Budget) system. The service includes methods to retrieve,
create, update, and delete transactions, as well as to retrieve transactions by account, category,
payee, and month.
Classes:
| Name | Description |
|---|---|
TransactionService |
A service class for managing transactions in a YNAB budget. |
TransactionService
Bases: YNABService
Source code in src/uynab/service/transaction.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
create_transactions(budget_id, transactions)
Create new transactions in a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
transactions
|
NewTransaction
|
The transaction object to be created. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TransactionDetail |
list[TransactionDetail]
|
The created transaction object. |
Source code in src/uynab/service/transaction.py
delete_transaction(budget_id, transaction_id)
Delete a specific transaction from a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
transaction_id
|
UUID
|
The unique identifier of the transaction. |
required |
Source code in src/uynab/service/transaction.py
get_all_transactions(budget_id, since_date=None, last_knowledge_of_server=None)
Retrieve all transactions for a given budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
since_date
|
date
|
The date from which to retrieve transactions. ISO formatted (e.g. 2024-01-01). Defaults to None. |
None
|
last_knowledge_of_server
|
int
|
The last knowledge of the server. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[TransactionDetail]
|
list[TransactionDetail]: A list of transactions associated with the budget. |
Source code in src/uynab/service/transaction.py
get_transaction(budget_id, transaction_id)
Retrieve a specific transaction from a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
transaction_id
|
UUID
|
The unique identifier of the transaction. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TransactionDetail |
TransactionDetail
|
The transaction object retrieved from the budget. |
Source code in src/uynab/service/transaction.py
get_transactions_by_account(budget_id, account_id, since_date=None, last_knowledge_of_server=None)
Retrieve all transactions for a specific account in a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
account_id
|
UUID
|
The unique identifier of the account. |
required |
since_date
|
date
|
The date from which to retrieve transactions. ISO formatted (e.g. 2024-01-01). Defaults to None. |
None
|
last_knowledge_of_server
|
int
|
The last knowledge of the server. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[TransactionDetail]
|
list[TransactionDetail]: A list of transactions associated with the account. |
Source code in src/uynab/service/transaction.py
get_transactions_by_category(budget_id, category_id, since_date=None, last_knowledge_of_server=None)
Retrieve all transactions for a specific category in a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
category_id
|
UUID
|
The unique identifier of the category. |
required |
since_date
|
date
|
The date from which to retrieve transactions. ISO formatted (e.g. 2024-01-01). Defaults to None. |
None
|
last_knowledge_of_server
|
int
|
The last knowledge of the server. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[TransactionDetail]
|
list[TransactionDetail]: A list of transactions associated with the category. |
Source code in src/uynab/service/transaction.py
get_transactions_by_month(budget_id, month, since_date=None, last_knowledge_of_server=None)
Retrieve all transactions for a specific month in a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
month
|
date
|
The budget month for which to retrieve transactions. ISO formatted (e.g. 2024-01-01) |
required |
since_date
|
date
|
The date from which to retrieve transactions. ISO formatted (e.g. 2024-01-01). Defaults to None. |
None
|
last_knowledge_of_server
|
int
|
The last knowledge of the server. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[TransactionDetail]
|
list[TransactionDetail]: A list of transactions associated with the month. |
Source code in src/uynab/service/transaction.py
get_transactions_by_payee(budget_id, payee_id, since_date=None, last_knowledge_of_server=None)
Retrieve all transactions for a specific payee in a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
payee_id
|
UUID
|
The unique identifier of the payee. |
required |
since_date
|
date
|
The date from which to retrieve transactions. ISO formatted (e.g. 2024-01-01). Defaults to None. |
None
|
last_knowledge_of_server
|
int
|
The last knowledge of the server. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[TransactionDetail]
|
list[TransactionDetail]: A list of transactions associated with the payee. |
Source code in src/uynab/service/transaction.py
update_transaction(budget_id, transaction_id, transaction)
Update existing transactions in a budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
transaction_id
|
str
|
The unique identifier of the transaction. |
required |
transaction
|
NewTransaction
|
The transaction object with updated data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Transaction |
TransactionDetail
|
The updated transaction object. |
Source code in src/uynab/service/transaction.py
update_transactions(budget_id, transactions)
Updates a list of transactions for a given budget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
budget_id
|
UUID
|
The unique identifier of the budget. |
required |
transactions
|
list[SaveTransactionWithIdOrImportId]
|
A list of transactions to be updated. |
required |
Returns:
| Type | Description |
|---|---|
list[TransactionDetail]
|
list[TransactionDetail]: A list of updated transaction details. |