Budgets in SDK

Manage credits across orders and jobs using the SDK.

Overview

A budget helps you organize and track credit usage in your UP42 account by grouping orders and processing jobs by cost center. This provides better visibility into spending and can be linked to a project ID for internal tracking.

Assign a budget when creating orders or processing jobs to attribute credit consumption.

View repository

Class: Budget

A data class that represents a budget in the system.

Attributes

AttributeDescription
id

str

The budget ID.

name

str

The name of the budget.

status

BudgetStatus

The budget status.

created_by

str

The ID of the user who created the budget.

created_at

str

The timestamp when the budget was created.

updated_at

str

The timestamp when the budget was last updated.

description

Optional[str]

The description of the budget.

external_id

Optional[str]

The ID of the external project associated with the budget.

Python
# Select a budget
budget_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch budget info
budget = up42.Budget.get(budget_id=budget_id)
# Define output
print(f"Budget details for ID: {budget.id}")
print(f"Name: {budget.name}")
print(f"Status: {budget.status}")
print(f"Description: {budget.description}")
print(f"External ID: {budget.external_id}")

Methods

all

Retrieves all budgets, with optional filtering. Returns Iterator[Budget]. Use itertools.islice to offset and limit the results.

ParameterDescription
status

Optional[List[BudgetStatus]]

Budget statuses. Use to search for budgets with any of the provided statuses.

sort_by

Optional[utils.SortingField]

The results sorting method that arranges elements in ascending or descending order based on a chosen field. To view the list of possible values, see BudgetSorting.

Python
from itertools import islice
# Search for budgets
budgets = up42.Budget.all(
status=["ACTIVE"],
sort_by=up42.BudgetSorting.updated_at.desc,
)
# Define output
for budget in islice(budgets, 0, 5): # Print first 5 results
print(f"- Budget ID: {budget.id}")
print(f" Name: {budget.name}")
print(f" Status: {budget.status}")
print(f" Updated at: {budget.updated_at}\n")

get

Retrieves a specific budget by its ID. Returns Budget.

ParameterDescription
budget_id

str

The budget ID.

Python
# Select a budget
budget_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch budget info
budget = up42.Budget.get(budget_id=budget_id)
# Define output
print(f"Budget details for ID: {budget.id}")
print(f"Name: {budget.name}")
print(f"Status: {budget.status}")

get_usage

Retrieves the credit usage for a budget. Credit consumption is recorded when orders or processing jobs reach a specific status or substatus. Returns BudgetUsage.

Python
# Select a budget
budget_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch credit usage
budget = up42.Budget.get(budget_id=budget_id)
usage = budget.get_usage()
# Define output
print(f"Budget ID: {usage.budget_id}")
print(f"Consumed credits: {usage.consumed_credits}")

Class: BudgetUsage

A data class that represents the credit usage of a budget.

Attributes

AttributeDescription
budget_id

str

The budget ID.

consumed_credits

int

The number of credits consumed by all transactions associated with this budget.

Python
# Select a budget
budget_id = "a0d443a2-41e8-4995-8b54-a5cc4c448227"
# Fetch credit usage
budget = up42.Budget.get(budget_id=budget_id)
usage = budget.get_usage()
# Define output
print(f"Budget ID: {usage.budget_id}")
print(f"Consumed credits: {usage.consumed_credits}")

Class: BudgetSettings

A data class that represents the budget enforcement settings for an account.

Attributes

AttributeDescription
enforcement_enabled

bool

Indicates whether budget enforcement is enabled for the account. When enabled, a valid budget ID is required for orders and processing jobs.

budget_setting_id

Optional[str]

The budget setting ID.

Python
# Fetch budget settings
settings = up42.BudgetSettings.get()
# Define output
print(f"Enforcement enabled: {settings.enforcement_enabled}")
print(f"Budget setting ID: {settings.budget_setting_id}")

Methods

get

Retrieves the budget enforcement settings for the account. Returns BudgetSettings.

Python
# Fetch budget settings
settings = up42.BudgetSettings.get()
# Define output
print(f"Enforcement enabled: {settings.enforcement_enabled}")

Class: BudgetSorting

A class that provides sorting options for budgets.

Attributes

AttributeDescription
updated_at

utils.SortingField

Sorts by update date. The default order is ascending.

Python
from itertools import islice
# Sort by update date, from the most recent to the earliest
budgets_sorted = up42.Budget.all(sort_by=up42.BudgetSorting.updated_at.desc)
# Define output
for budget in islice(budgets_sorted, 0, 5): # Print first 5 results
print(f"- Budget ID: {budget.id}")
print(f" Name: {budget.name}")
print(f" Updated at: {budget.updated_at}\n")

Learn more

API docs | Budgets Console docs | Budget management