Skip to content

Sheets

albert.resources.sheets

AlbertException

AlbertException(message: str)

Bases: Exception

Source code in src/albert/exceptions.py
def __init__(self, message: str):
    super().__init__(message)
    self.message = message

message instance-attribute

message = message

BaseResource

Bases: BaseAlbertModel

The base resource for all Albert resources.

Attributes:

Name Type Description
status Status | None

The status of the resource, optional.

created AuditFields | None

Audit fields for the creation of the resource, optional.

updated AuditFields | None

Audit fields for the update of the resource, optional.

Methods:

Name Description
to_entity_link

created class-attribute instance-attribute

created: AuditFields | None = Field(
    default=None, alias="Created", exclude=True, frozen=True
)

status class-attribute instance-attribute

status: Status | None = Field(default=None)

updated class-attribute instance-attribute

updated: AuditFields | None = Field(
    default=None, alias="Updated", exclude=True, frozen=True
)
to_entity_link() -> EntityLink
Source code in src/albert/resources/base.py
def to_entity_link(self) -> EntityLink:
    if id := getattr(self, "id", None):
        return EntityLink(id=id)
    raise AlbertException(
        "A non-null 'id' is required to create an entity link. "
        "Ensure the linked object is registered and has a valid 'id'."
    )

BaseSessionResource

BaseSessionResource(**data)

Bases: BaseResource

Source code in src/albert/resources/base.py
def __init__(self, **data):
    super().__init__(**data)
    self._session = data.get("session")

session property

session: AlbertSession | None

Cell

Bases: BaseResource

A Cell in a Sheet

Attributes:

Name Type Description
column_id str

The column ID of the cell.

row_id str

The row ID of the cell.

value str | dict

The value of the cell. If the cell is an inventory item, this will be a dict.

type CellType

The type of the cell. Allowed values are INV, APP, BLK, Formula, TAG, PRC, PDC, BAT, TOT, TAS, DEF, LKP, FOR, and EXTINV.

name str | None

The name of the cell. Optional. Default is None.

calculation str

The calculation of the cell. Optional. Default is "".

design_id str

The design ID of the design this cell is in.

format dict

The format of the cell. Optional. Default is {}. The format is a dict with the keys bgColor and fontColor. The values are strings in the format RGB(255, 255, 255).

raw_value str

The raw value of the cell. If the cell is an inventory item, this will be the value of the inventory item. Read-only.

color str | None

The color of the cell. Read only.

calculation class-attribute instance-attribute

calculation: str = ''

color property

color

column_id class-attribute instance-attribute

column_id: str = Field(alias='colId')

design_id instance-attribute

design_id: str

format class-attribute instance-attribute

format: dict = Field(
    default_factory=dict, alias="cellFormat"
)

inventory_id class-attribute instance-attribute

inventory_id: str | None = Field(default=None)

name class-attribute instance-attribute

name: str | None = Field(default=None)

raw_value property

raw_value

row_id class-attribute instance-attribute

row_id: str = Field(alias='rowId')

type instance-attribute

type: CellType

value class-attribute instance-attribute

value: str | dict = ''

CellColor

Bases: str, Enum

The allowed colors for a cell

BLUE class-attribute instance-attribute

BLUE = 'RGB(214, 233, 255)'

GREEN class-attribute instance-attribute

GREEN = 'RGB(130, 222, 198)'

ORANGE class-attribute instance-attribute

ORANGE = 'RGB(255, 227, 210)'

PURPLE class-attribute instance-attribute

PURPLE = 'RGB(238, 215, 255)'

RED class-attribute instance-attribute

RED = 'RGB(255, 161, 161)'

WHITE class-attribute instance-attribute

WHITE = 'RGB(255, 255, 255)'

YELLOW class-attribute instance-attribute

YELLOW = 'RGB(254, 240, 159)'

CellType

Bases: str, Enum

The type of information in the Cell

APP class-attribute instance-attribute

APP = 'APP'

BAT class-attribute instance-attribute

BAT = 'BAT'

BLANK class-attribute instance-attribute

BLANK = 'BLK'

BTI class-attribute instance-attribute

BTI = 'BTI'

DEF class-attribute instance-attribute

DEF = 'DEF'

EXTINV class-attribute instance-attribute

EXTINV = 'EXTINV'

FOR class-attribute instance-attribute

FOR = 'FOR'

FORMULA class-attribute instance-attribute

FORMULA = 'Formula'

INVENTORY class-attribute instance-attribute

INVENTORY = 'INV'

LKP class-attribute instance-attribute

LKP = 'LKP'

PDC class-attribute instance-attribute

PDC = 'PDC'

PRICE class-attribute instance-attribute

PRICE = 'PRC'

TAG class-attribute instance-attribute

TAG = 'TAG'

TAS class-attribute instance-attribute

TAS = 'TAS'

TOTAL class-attribute instance-attribute

TOTAL = 'TOT'

Column

Column(**data)

Bases: BaseSessionResource

A column in a Sheet

Attributes:

Name Type Description
column_id str

The column ID of the column.

name str | None

The name of the column. Optional. Default is None.

type CellType

The type of the column. Allowed values are INV, APP, BLK, Formula, TAG, PRC, PDC, BAT, TOT, TAS, DEF, LKP, FOR, and EXTINV.

sheet Sheet

The sheet the column is in.

cells list[Cell]

The cells in the column. Read-only.

df_name str

The name of the column in the DataFrame. Read-only

Methods:

Name Description
recolor_cells
rename
Source code in src/albert/resources/base.py
def __init__(self, **data):
    super().__init__(**data)
    self._session = data.get("session")

cells property

cells: list[Cell]

column_id class-attribute instance-attribute

column_id: str = Field(alias='colId')

df_name property

df_name

inventory_id class-attribute instance-attribute

inventory_id: str | None = Field(default=None, exclude=True)

name class-attribute instance-attribute

name: str | None = Field(default=None)

sheet instance-attribute

sheet: Sheet

type instance-attribute

type: CellType

recolor_cells

recolor_cells(color: CellColor)
Source code in src/albert/resources/sheets.py
def recolor_cells(self, color: CellColor):
    new_cells = []
    for c in self.cells:
        cell_copy = c.model_copy(update={"format": {"bgColor": color.value}})
        new_cells.append(cell_copy)
    return self.sheet.update_cells(cells=new_cells)

rename

rename(new_name)
Source code in src/albert/resources/sheets.py
def rename(self, new_name):
    payload = {
        "data": [
            {
                "operation": "update",
                "attribute": "name",
                "colId": self.column_id,
                "oldValue": self.name,
                "newValue": new_name,
            }
        ]
    }

    self.session.patch(
        url=f"/api/v3/worksheet/sheet/{self.sheet.id}/columns",
        json=payload,
    )

    if self.sheet._grid is not None:  # if I have a grid loaded into memory, adjust it.
        self.sheet.grid = None
        # self.sheet._grid.rename(axis=1, mapper={self.name:new_name})
    self.name = new_name
    return self

Component

Bases: BaseResource

Represents an amount of an inventory item in a formulation

Attributes:

Name Type Description
inventory_item InventoryItem

The inventory item in the component

amount float

The amount of the inventory item in the component

cell Cell

The cell that the component is in. Read-only.

amount instance-attribute

amount: float

cell property

cell

inventory_item instance-attribute

inventory_item: InventoryItem

Design

Design(**data)

Bases: BaseSessionResource

A Design in a Sheet. Designs are sheet subsections that are largly abstracted away from the user.

Attributes:

Name Type Description
id str

The Albert ID of the design.

design_type DesignType

The type of the design. Allowed values are apps, products, and results.

state DesignState | None

The state of the design. Optional. Default is None.

grid DataFrame | None

The grid of the design. Optional. Default is None. Read-only.

rows list[Row] | None

The rows of the design. Optional. Default is None. Read-only.

columns list[Column] | None

The columns of the design. Optional. Default is None. Read-only.

Source code in src/albert/resources/base.py
def __init__(self, **data):
    super().__init__(**data)
    self._session = data.get("session")

columns property

columns: list[Column]

design_type class-attribute instance-attribute

design_type: DesignType = Field(alias='designType')

grid property

grid

id class-attribute instance-attribute

id: str = Field(alias='albertId')

rows property

rows: list[Row]

sheet property

sheet

state class-attribute instance-attribute

state: DesignState | None = Field({})

DesignState

Bases: BaseResource

The state of a Design

collapsed class-attribute instance-attribute

collapsed: bool | None = False

DesignType

Bases: str, Enum

The type of Design

APPS class-attribute instance-attribute

APPS = 'apps'

PRODUCTS class-attribute instance-attribute

PRODUCTS = 'products'

RESULTS class-attribute instance-attribute

RESULTS = 'results'

InventoryItem

Bases: BaseTaggedResource

An InventoryItem is a Pydantic model representing an item in the inventory. Can be a raw material, consumable, equipment, or formula. Note: Formulas should be registered via the Worksheet collection / Sheet resource.

Returns:

Type Description
InventoryItem

An InventoryItem that can be used to represent an item in the inventory. Can be a raw material, consumable, equipment, or formula.

Attributes:

Name Type Description
name str

The name of the InventoryItem.

id str | None

The Albert ID of the InventoryItem. Set when the InventoryItem is retrieved from Albert.

description str | None

The description of the InventoryItem.

category InventoryCategory

The category of the InventoryItem. Allowed values are RawMaterials, Consumables, Equipment, and Formulas.

unit_category InventoryUnitCategory

The unit category of the InventoryItem. Can be mass, volume, length, pressure, or units. By default, mass is used for RawMaterials and Formulas, and units is used for Equipment and Consumables.

security_class SecurityClass | None

The security class of the InventoryItem. Optional. Can be confidential, shared, or restricted.

company Company | str | None

The company associated with the InventoryItem. Can be a Company object or a string. If a String is provided, a Company object with the name of the provided string will be first-or-created.

minimum list[InventoryMinimum] | None

The minimum amount of the InventoryItem that must be kept in stock at a given Location. Optional.

alias str | None

An alias for the InventoryItem. Optional.

cas list[CasAmount] | None

The CAS numbers associated with the InventoryItem. This is how a compositional breakdown can be provided. Optional.

metadata dict[str, str | list[EntityLink] | EntityLink] | None

Metadata associated with the InventoryItem. Optional. Allowed metadata fields can be found in the CustomFields documentation.

project_id str | None

The project ID associated with the InventoryItem. Read Only. Required for Formulas.

formula_id str | None

The formula ID associated with the InventoryItem. Read Only.

tags list[str | Tag] | None

The tags associated with the InventoryItem. Optional. If a string is provided, a Tag object with the name of the provided string will be first-or-created.

Methods:

Name Description
set_unit_category

Set unit category from category if not defined.

validate_company_string
validate_formula_fields

Ensure required fields are present for formulas.

validate_un_number

acls class-attribute instance-attribute

acls: list[ACL] = Field(default_factory=list, alias='ACL')

alias class-attribute instance-attribute

alias: str | None = Field(default=None)

cas class-attribute instance-attribute

cas: list[CasAmount] | None = Field(
    default=None, alias="Cas"
)

category instance-attribute

company class-attribute instance-attribute

company: SerializeAsEntityLink[Company] | None = Field(
    default=None, alias="Company"
)

description class-attribute instance-attribute

description: str | None = None

formula_id class-attribute instance-attribute

formula_id: str | None = Field(
    default=None,
    alias="formulaId",
    exclude=True,
    frozen=True,
)

id class-attribute instance-attribute

id: str | None = Field(None, alias='albertId')

metadata class-attribute instance-attribute

metadata: dict[str, MetadataItem] | None = Field(
    alias="Metadata", default=None
)

minimum class-attribute instance-attribute

minimum: list[InventoryMinimum] | None = Field(default=None)

name class-attribute instance-attribute

name: str | None = None

project_id class-attribute instance-attribute

project_id: str | None = Field(
    default=None, alias="parentId"
)

recent_atachment_id class-attribute instance-attribute

recent_atachment_id: str | None = Field(
    default=None,
    alias="recentAttachmentId",
    exclude=True,
    frozen=True,
)

security_class class-attribute instance-attribute

security_class: SecurityClass | None = Field(
    default=None, alias="class"
)

symbols class-attribute instance-attribute

symbols: list[dict] | None = Field(
    default=None, alias="Symbols", exclude=True, frozen=True
)

task_config class-attribute instance-attribute

task_config: list[dict] | None = Field(
    default=None,
    alias="TaskConfig",
    exclude=True,
    frozen=True,
)

un_number class-attribute instance-attribute

un_number: str | None = Field(
    default=None,
    alias="unNumber",
    exclude=True,
    frozen=True,
)

unit_category class-attribute instance-attribute

unit_category: InventoryUnitCategory | None = Field(
    default=None, alias="unitCategory"
)

set_unit_category

set_unit_category() -> InventoryItem

Set unit category from category if not defined.

Source code in src/albert/resources/inventory.py
@model_validator(mode="after")
def set_unit_category(self) -> "InventoryItem":
    """Set unit category from category if not defined."""
    if self.unit_category is None:
        if self.category in [InventoryCategory.RAW_MATERIALS, InventoryCategory.FORMULAS]:
            object.__setattr__(self, "unit_category", InventoryUnitCategory.MASS)
        elif self.category in [InventoryCategory.EQUIPMENT, InventoryCategory.CONSUMABLES]:
            object.__setattr__(self, "unit_category", InventoryUnitCategory.UNITS)
    return self

validate_company_string classmethod

validate_company_string(value: Any) -> Any
Source code in src/albert/resources/inventory.py
@field_validator("company", mode="before")
@classmethod
def validate_company_string(cls, value: Any) -> Any:
    if isinstance(value, str):
        value = Company(name=value)
    return value

validate_formula_fields

validate_formula_fields() -> InventoryItem

Ensure required fields are present for formulas.

Source code in src/albert/resources/inventory.py
@model_validator(mode="after")
def validate_formula_fields(self) -> "InventoryItem":
    """Ensure required fields are present for formulas."""
    if self.category == InventoryCategory.FORMULAS and not self.project_id and not self.id:
        # Some legacy on platform formulas don't have a project_id so check if its already on platform
        raise ValueError("A project_id must be supplied for all formulas.")
    return self

validate_un_number classmethod

validate_un_number(value: Any) -> Any
Source code in src/albert/resources/inventory.py
@field_validator("un_number", mode="before")
@classmethod
def validate_un_number(cls, value: Any) -> Any:
    if value == "N/A":
        value = None
    return value

Row

Row(**data)

Bases: BaseSessionResource

A row in a Sheet

Attributes:

Name Type Description
row_id str

The row ID of the row.

type CellType

The type of the row. Allowed values are INV, APP, BLK, Formula, TAG, PRC, PDC, BAT, TOT, TAS, DEF, LKP, FOR, and EXTINV.

design Design

The design the row is in.

sheet Sheet

The sheet the row is in.

name str | None

The name of the row. Optional. Default is None.

inventory_id str | None

The inventory ID of the row. Optional. Default is None.

manufacturer str | None

The manufacturer of the row. Optional. Default is None.

row_unique_id str

The unique ID of the row. Read-only.

cells list[Cell]

The cells in the row. Read-only.

Methods:

Name Description
recolor_cells
Source code in src/albert/resources/base.py
def __init__(self, **data):
    super().__init__(**data)
    self._session = data.get("session")

cells property

cells: list[Cell]

design instance-attribute

design: Design

inventory_id class-attribute instance-attribute

inventory_id: str | None = Field(default=None, alias='id')

manufacturer class-attribute instance-attribute

manufacturer: str | None = Field(default=None)

name class-attribute instance-attribute

name: str | None = Field(default=None)

row_id class-attribute instance-attribute

row_id: str = Field(alias='rowId')

row_unique_id property

row_unique_id

sheet instance-attribute

sheet: Sheet

type instance-attribute

type: CellType

recolor_cells

recolor_cells(color: CellColor)
Source code in src/albert/resources/sheets.py
def recolor_cells(self, color: CellColor):
    new_cells = []
    for c in self.cells:
        cell_copy = c.model_copy(update={"format": {"bgColor": color.value}})
        cell_copy.format = {"bgColor": color.value}
        new_cells.append(cell_copy)
    return self.sheet.update_cells(cells=new_cells)

Sheet

Sheet(**data)

Bases: BaseSessionResource

A Sheet in Albert

Attributes:

Name Type Description
id str

The Albert ID of the sheet.

name str

The name of the sheet.

hidden bool

Whether the sheet is hidden.

designs list[Design]

The designs of the sheet.

project_id str

The Albert ID of the project the sheet is in.

grid DataFrame | None

The grid of the sheet. Optional. Default is None. Read-only.

columns list[Column]

The columns of the sheet. Read-only.

rows list[Row]

The rows of the sheet. Read-only.

Methods:

Name Description
add_blank_column
add_blank_row
add_formulation
add_formulation_columns
add_inventory_row
delete_column
delete_row
get_column
rename
set_session
set_sheet_fields
update_cells
Source code in src/albert/resources/base.py
def __init__(self, **data):
    super().__init__(**data)
    self._session = data.get("session")

app_design property

app_design

columns property

columns: list[Column]

The columns of a given sheet

designs class-attribute instance-attribute

designs: list[Design] = Field(alias='Designs')

formulations class-attribute instance-attribute

formulations: list[SheetFormulationRef] = Field(
    default_factory=list, alias="Formulas"
)

grid property writable

grid

hidden instance-attribute

hidden: bool

id class-attribute instance-attribute

id: str = Field(alias='albertId')

leftmost_pinned_column property

leftmost_pinned_column

The leftmost pinned column in the sheet

name instance-attribute

name: str

product_design property

product_design

project_id instance-attribute

project_id: str

result_design property

result_design

rows property

rows: list[Row]

The rows of a given sheet

add_blank_column

add_blank_column(*, name: str, position: dict = None)
Source code in src/albert/resources/sheets.py
def add_blank_column(self, *, name: str, position: dict = None):
    if position is None:
        position = {"reference_id": self.leftmost_pinned_column, "position": "rightOf"}
    endpoint = f"/api/v3/worksheet/sheet/{self.id}/columns"
    payload = [
        {
            "type": "BLK",
            "name": name,
            "referenceId": position["reference_id"],
            "position": position["position"],
        }
    ]

    response = self.session.post(endpoint, json=payload)

    data = response.json()
    data[0]["sheet"] = self
    data[0]["session"] = self.session
    self.grid = None  # reset the known grid. We could probably make this nicer later.
    return Column(**data[0])

add_blank_row

add_blank_row(
    *,
    row_name: str,
    design: DesignType | str | None = PRODUCTS,
    position: dict | None = None,
)
Source code in src/albert/resources/sheets.py
def add_blank_row(
    self,
    *,
    row_name: str,
    design: DesignType | str | None = DesignType.PRODUCTS,
    position: dict | None = None,
):
    if design == DesignType.RESULTS:
        raise AlbertException("You cannot add rows to the results design")
    if position is None:
        position = {"reference_id": "ROW1", "position": "above"}
    endpoint = f"/api/v3/worksheet/design/{self._get_design_id(design=design)}/rows"

    payload = [
        {
            "type": "BLK",
            "name": row_name,
            "referenceId": position["reference_id"],
            "position": position["position"],
        }
    ]

    response = self.session.post(endpoint, json=payload)

    self.grid = None
    row_dict = response.json()[0]
    return Row(
        rowId=row_dict["rowId"],
        type=row_dict["type"],
        session=self.session,
        design=self._get_design(design=design),
        name=row_dict["name"],
        sheet=self,
    )

add_formulation

add_formulation(
    *,
    formulation_name: str,
    components: list[Component],
    enforce_order: bool = False,
) -> Column
Source code in src/albert/resources/sheets.py
def add_formulation(
    self, *, formulation_name: str, components: list[Component], enforce_order: bool = False
) -> "Column":
    existing_formulation_names = [x.name for x in self.columns]
    if formulation_name not in existing_formulation_names:
        col = self.add_formulation_columns(formulation_names=[formulation_name])[0]
    else:
        # get the existing column and clear it out to put the new formulation in
        col = self.get_column(column_name=formulation_name)
        self._clear_formulation_from_column(column=col)
    col_id = col.column_id

    all_cells = []
    self.grid = None  # reset the grid for saftey

    for component in components:
        row_id = self._get_row_id_for_component(
            inventory_item=component.inventory_item,
            existing_cells=all_cells,
            enforce_order=enforce_order,
        )
        if row_id is None:
            raise AlbertException(f"no component with id {component.inventory_item.id}")
        this_cell = Cell(
            column_id=col_id,
            row_id=row_id,
            value=str(component.amount),
            calculation="",
            type=CellType.INVENTORY,
            design_id=self.product_design.id,
            name=formulation_name,
            inventory_id=col.inventory_id,
        )
        all_cells.append(this_cell)

    self.update_cells(cells=all_cells)
    return self.get_column(column_id=col_id)

add_formulation_columns

add_formulation_columns(
    *,
    formulation_names: list[str],
    starting_position: dict | None = None,
) -> list[Column]
Source code in src/albert/resources/sheets.py
def add_formulation_columns(
    self,
    *,
    formulation_names: list[str],
    starting_position: dict | None = None,
) -> list["Column"]:
    if starting_position is None:
        starting_position = {
            "reference_id": self.leftmost_pinned_column,
            "position": "rightOf",
        }
    sheet_id = self.id

    endpoint = f"/api/v3/worksheet/sheet/{sheet_id}/columns"

    # In case a user supplied a single formulation name instead of a list
    formulation_names = (
        formulation_names if isinstance(formulation_names, list) else [formulation_names]
    )

    payload = []
    for formulation_name in (
        formulation_names
    ):  # IS there a limit to the number I can add at once? Need to check this.
        # define payload for this item
        payload.append(
            {
                "type": "INV",
                "name": formulation_name,
                "referenceId": starting_position["reference_id"],  # initially defined column
                "position": starting_position["position"],
            }
        )
    response = self.session.post(endpoint, json=payload)

    self.grid = None
    new_dicts = self._reformat_formulation_addition_payload(response_json=response.json())
    return [Column(**x) for x in new_dicts]

add_inventory_row

add_inventory_row(
    *, inventory_id: str, position: dict | None = None
)
Source code in src/albert/resources/sheets.py
def add_inventory_row(
    self,
    *,
    inventory_id: str,
    position: dict | None = None,
):
    if position is None:
        position = {"reference_id": "ROW1", "position": "above"}
    design_id = self.product_design.id
    endpoint = f"/api/v3/worksheet/design/{design_id}/rows"

    payload = {
        "type": "INV",
        "id": ("INV" + inventory_id if not inventory_id.startswith("INV") else inventory_id),
        "referenceId": position["reference_id"],
        "position": position["position"],
    }

    response = self.session.post(endpoint, json=payload)

    self.grid = None
    row_dict = response.json()
    return Row(
        rowId=row_dict["rowId"],
        inventory_id=inventory_id,
        type=row_dict["type"],
        session=self.session,
        design=self.product_design,
        sheet=self,
        name=row_dict["name"],
        id=row_dict["id"],
        manufacturer=row_dict["manufacturer"],
    )

delete_column

delete_column(*, column_id: str) -> None
Source code in src/albert/resources/sheets.py
def delete_column(self, *, column_id: str) -> None:
    endpoint = f"/api/v3/worksheet/sheet/{self.id}/columns"
    payload = [{"colId": column_id}]
    self.session.delete(endpoint, json=payload)

    if self._grid is not None:  # if I have a grid loaded into memory, adjust it.
        self.grid = None

delete_row

delete_row(*, row_id: str, design_id: str) -> None
Source code in src/albert/resources/sheets.py
def delete_row(self, *, row_id: str, design_id: str) -> None:
    endpoint = f"/api/v3/worksheet/design/{design_id}/rows"
    payload = [{"rowId": row_id}]
    self.session.delete(endpoint, json=payload)

    if self._grid is not None:  # if I have a grid loaded into memory, adjust it.
        self.grid = None

get_column

get_column(
    *,
    column_id: None | str = None,
    column_name: str | None = None,
)
Source code in src/albert/resources/sheets.py
def get_column(self, *, column_id: None | str = None, column_name: str | None = None):
    if column_id is None and column_name is None:
        raise AlbertException("Either a column name or id must be provided")
    else:
        matching_series = self._find_column(column_id=column_id, column_name=column_name)
        first_item = matching_series.iloc[0]
        inv_id = first_item.inventory_id
        if inv_id is not None and not inv_id.startswith("INV"):
            inv_id = "INV" + inv_id
        return Column(
            name=first_item.name,
            colId=first_item.column_id,
            type=first_item.type,
            sheet=self,
            session=self.session,
            inventory_id=first_item.inventory_id,
        )

rename

rename(*, new_name: str)
Source code in src/albert/resources/sheets.py
def rename(self, *, new_name: str):
    endpoint = f"/api/v3/worksheet/sheet/{self.id}"

    payload = [{"attribute": "name", "operation": "update", "newValue": new_name}]

    self.session.patch(endpoint, json=payload)

    self.name = new_name
    return self

set_session

set_session()
Source code in src/albert/resources/sheets.py
@model_validator(mode="after")
def set_session(self):
    if self.session is not None:
        for d in self.designs:
            d._session = self.session
    return self

set_sheet_fields

set_sheet_fields() -> Sheet
Source code in src/albert/resources/sheets.py
@model_validator(mode="after")
def set_sheet_fields(self: "Sheet") -> "Sheet":
    for _idx, d in enumerate(self.designs):  # Instead of creating a new list
        d._sheet = self  # Set the reference to the sheet
        if d.design_type == DesignType.APPS:
            self._app_design = d
        elif d.design_type == DesignType.PRODUCTS:
            self._product_design = d
        elif d.design_type == DesignType.RESULTS:
            self._result_design = d
    return self

update_cells

update_cells(*, cells: list[Cell])
Source code in src/albert/resources/sheets.py
def update_cells(self, *, cells: list[Cell]):
    request_path_dict = {}
    updated = []
    failed = []
    # sort by design ID
    for c in cells:
        if c.design_id not in request_path_dict:
            request_path_dict[c.design_id] = [c]
        else:
            request_path_dict[c.design_id].append(c)

    for design_id, cell_list in request_path_dict.items():
        payload = []
        for cell in cell_list:
            change_dict = self._get_cell_changes(cell=cell)
            if change_dict is not None:
                payload.append(change_dict)

        if payload == []:
            continue

        this_url = f"/api/v3/worksheet/{design_id}/values"
        response = self.session.patch(
            this_url,
            json=payload,
        )

        if response.status_code == 204:
            # They all updated
            updated.extend(cell_list)
        elif response.status_code == 206:
            # Some updated and some did not.
            cell_results = self._filter_cells(cells=cell_list, response_dict=response.json())
            updated.extend(cell_results[0])
            failed.extend(cell_results[1])
    # reset the in-memory grid after updates
    self.grid = None
    return (updated, failed)

SheetFormulationRef

Bases: BaseAlbertModel

A reference to a formulation in a sheet

hidden class-attribute instance-attribute

hidden: bool = Field(
    description="Whether the formulation is hidden"
)

id class-attribute instance-attribute

id: str = Field(
    description="The Albert ID of the inventory item that is the formulation"
)

name class-attribute instance-attribute

name: str = Field(description="The name of the formulation")