Skip to content

Custom Fields

albert.resources.custom_fields

Attributes:

Name Type Description
Default

Default

Default = Annotated[
    StringDefault | NumberDefault | ListDefault,
    Field(discriminator="type"),
]

FieldType

Bases: str, Enum

The type of the custom field.

Attributes:

Name Type Description
LIST
STRING
NUMBER

LIST

LIST = 'list'

STRING

STRING = 'string'

NUMBER

NUMBER = 'number'

ServiceType

Bases: str, Enum

The service type the custom field is associated with

Attributes:

Name Type Description
INVENTORIES
LOTS
PROJECTS
TASKS
USERS
PARAMETERS
DATA_COLUMNS
DATA_TEMPLATES
PARAMETER_GROUPS
CAS

INVENTORIES

INVENTORIES = 'inventories'

LOTS

LOTS = 'lots'

PROJECTS

PROJECTS = 'projects'

TASKS

TASKS = 'tasks'

USERS

USERS = 'users'

PARAMETERS

PARAMETERS = 'parameters'

DATA_COLUMNS

DATA_COLUMNS = 'datacolumns'

DATA_TEMPLATES

DATA_TEMPLATES = 'datatemplates'

PARAMETER_GROUPS

PARAMETER_GROUPS = 'parametergroups'

CAS

CAS = 'cas'

FieldCategory

Bases: str, Enum

The ACL level of the custom field

Attributes:

Name Type Description
BUSINESS_DEFINED
USER_DEFINED

BUSINESS_DEFINED

BUSINESS_DEFINED = 'businessDefined'

USER_DEFINED

USER_DEFINED = 'userDefined'

EntityCategory

Bases: str, Enum

The entity category of the custom field. Only some categories are allowed for certain services

Attributes:

Name Type Description
FORMULAS
RAW_MATERIALS
CONSUMABLES
EQUIPMENT
PROPERTY
BATCH
GENERAL

FORMULAS

FORMULAS = 'Formulas'

RAW_MATERIALS

RAW_MATERIALS = 'RawMaterials'

CONSUMABLES

CONSUMABLES = 'Consumables'

EQUIPMENT

EQUIPMENT = 'Equipment'

PROPERTY

PROPERTY = 'Property'

BATCH

BATCH = 'Batch'

GENERAL

GENERAL = 'General'

UIComponent

Bases: str, Enum

The UI component available to the custom field

Attributes:

Name Type Description
CREATE
DETAILS

CREATE

CREATE = 'create'

DETAILS

DETAILS = 'details'

CustomFieldApiMethod

Bases: str, Enum

HTTP methods supported by API-driven custom fields.

Attributes:

Name Type Description
GET

GET

GET = 'GET'

CustomFieldAPI

Bases: BaseAlbertModel

Configuration for API-backed custom fields.

Show JSON schema:
{
  "$defs": {
    "CustomFieldApiMethod": {
      "description": "HTTP methods supported by API-driven custom fields.",
      "enum": [
        "GET"
      ],
      "title": "CustomFieldApiMethod",
      "type": "string"
    }
  },
  "description": "Configuration for API-backed custom fields.",
  "properties": {
    "endpoint": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Endpoint"
    },
    "method": {
      "anyOf": [
        {
          "$ref": "#/$defs/CustomFieldApiMethod"
        },
        {
          "type": "null"
        }
      ],
      "default": null
    },
    "queryParamsField": {
      "anyOf": [
        {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Queryparamsfield"
    }
  },
  "title": "CustomFieldAPI",
  "type": "object"
}

Fields:

endpoint

endpoint: str | None = None

method

method: CustomFieldApiMethod | None = None

query_params_field

query_params_field: list[str] | None = None

ListDefaultValue

Bases: BaseAlbertModel

Show JSON schema:
{
  "properties": {
    "albertId": {
      "title": "Albertid",
      "type": "string"
    },
    "name": {
      "title": "Name",
      "type": "string"
    }
  },
  "required": [
    "albertId",
    "name"
  ],
  "title": "ListDefaultValue",
  "type": "object"
}

Fields:

id

id: str

name

name: str

StringDefault

Bases: BaseAlbertModel

Show JSON schema:
{
  "properties": {
    "type": {
      "const": "string",
      "default": "string",
      "title": "Type",
      "type": "string"
    },
    "value": {
      "title": "Value",
      "type": "string"
    }
  },
  "required": [
    "value"
  ],
  "title": "StringDefault",
  "type": "object"
}

Fields:

type

value

value: str

NumberDefault

Bases: BaseAlbertModel

Show JSON schema:
{
  "properties": {
    "type": {
      "const": "number",
      "default": "number",
      "title": "Type",
      "type": "string"
    },
    "value": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "number"
        }
      ],
      "title": "Value"
    }
  },
  "required": [
    "value"
  ],
  "title": "NumberDefault",
  "type": "object"
}

Fields:

type

value

value: int | float

ListDefault

Bases: BaseAlbertModel

Note

For multi-select custom fields, value must be list[ListDefaultValue].

Show JSON schema:
{
  "$defs": {
    "ListDefaultValue": {
      "properties": {
        "albertId": {
          "title": "Albertid",
          "type": "string"
        },
        "name": {
          "title": "Name",
          "type": "string"
        }
      },
      "required": [
        "albertId",
        "name"
      ],
      "title": "ListDefaultValue",
      "type": "object"
    }
  },
  "description": "!!! note\n    For multi-select custom fields, `value` must be `list[ListDefaultValue]`.",
  "properties": {
    "type": {
      "const": "list",
      "default": "list",
      "title": "Type",
      "type": "string"
    },
    "value": {
      "anyOf": [
        {
          "$ref": "#/$defs/ListDefaultValue"
        },
        {
          "items": {
            "$ref": "#/$defs/ListDefaultValue"
          },
          "type": "array"
        }
      ],
      "title": "Value"
    }
  },
  "required": [
    "value"
  ],
  "title": "ListDefault",
  "type": "object"
}

Fields:

type

type: Literal[LIST] = LIST

CustomField

Bases: BaseResource

A custom field for an entity in Albert.

Returns:

Type Description
CustomField

A CustomField that can be used to attach Metadata to an entity in Albert.

Attributes:

Name Type Description
name str

The name of the custom field. Cannot contain spaces.

id str | None

The Albert ID of the custom field.

field_type FieldType

The type of the custom field. Allowed values are list, string, and number. string and list fields are searchable; number fields are not searchable.

display_name str

The display name of the custom field. Can contain spaces.

searchable bool | None

Whether the custom field is searchable, optional. Defaults to False. This is supported for list and string fields; number fields can not be searchable.

service ServiceType

The service type the custom field is associated with.

hidden bool | None

Whether the custom field is hidden, optional. Defaults to False.

lookup_column bool | None

Whether the custom field is a lookup column, optional. Defaults to False. Only allowed for inventories.

lookup_row bool | None

Whether the custom field is a lookup row, optional. Defaults to False. Only allowed for formulas in inventories.

category FieldCategory | None

The category of the custom field, optional. Defaults to None. Required for list fields. Allowed values are businessDefined and userDefined.

min int | float | None

The minimum value of the custom field, optional. Defaults to None.

max int | float | None

The maximum value of the custom field, optional. Defaults to None.

entity_categories list[EntityCategory] | None

The entity categories of the custom field, optional. Defaults to None. Required for lookup row fields. Allowed values are Formulas, RawMaterials, Consumables, Equipment, Property, Batch, and General.

custom_entity_categories list[str] | None

Custom entity categories that define where the field is valid.

ui_components list[UIComponent] | None

The UI components available to the custom field, optional. Defaults to None. Allowed values are create and details.

default Default | None

The default value of the custom field, optional. Defaults to None.

editable bool | None

Decides whether the field should be editable on UI or not.

api CustomFieldAPI | None

API configuration for fields backed by remote data sources.

Methods:

Name Description
confirm_field_compatability
ensure_default_has_type

name

name: str

id

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

field_type

field_type: FieldType = Field(alias='type')

display_name

display_name: str = Field(alias='labelName', max_length=40)

searchable

searchable: bool | None = Field(
    default=None, alias="search"
)

service

service: ServiceType

hidden

hidden: bool | None = Field(default=None)

lookup_column

lookup_column: bool | None = Field(
    default=None, alias="lkpColumn"
)

lookup_row

lookup_row: bool | None = Field(
    default=None, alias="lkpRow"
)

category

category: FieldCategory | None = Field(default=None)

min

min: int | float | None = Field(default=None)

max

max: int | float | None = Field(default=None)

entity_categories

entity_categories: list[EntityCategory] | None = Field(
    default=None, alias="entityCategory"
)

custom_entity_categories

custom_entity_categories: list[str] | None = Field(
    default=None, alias="customEntityCategory"
)

ui_components

ui_components: list[UIComponent] | None = Field(
    default=None, alias="ui_components"
)

required

required: bool | None = Field(default=None)

multiselect

multiselect: bool | None = Field(default=None)

editable

editable: bool | None = Field(default=None)

pattern

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

default

default: Default | None = Field(default=None)

api

api: CustomFieldAPI | None = Field(default=None)

confirm_field_compatability

confirm_field_compatability() -> CustomField
Source code in src/albert/resources/custom_fields.py
@model_validator(mode="after")
def confirm_field_compatability(self) -> CustomField:
    if self.field_type == FieldType.LIST and self.category is None:
        raise ValueError("Category must be set for list fields")
    return self

ensure_default_has_type

ensure_default_has_type(v: Any) -> Any
Source code in src/albert/resources/custom_fields.py
@field_validator("default", mode="before")
@classmethod
def ensure_default_has_type(cls, v: Any) -> Any:
    if v is None:
        return v

    if isinstance(v, dict) and "type" in v:
        return v

    if isinstance(v, dict) and "value" in v:
        raw_val = v["value"]

        if isinstance(raw_val, str):
            inferred_type = FieldType.STRING
        elif isinstance(raw_val, (int | float)):
            inferred_type = FieldType.NUMBER
        elif isinstance(raw_val, dict) and "albertId" in raw_val or isinstance(raw_val, list):
            inferred_type = FieldType.LIST
        else:
            raise ValueError(f"Cannot infer default type from value: {raw_val!r}")

        return {"type": inferred_type, "value": raw_val}

    return v

SearchableCustomField

Bases: BaseAlbertModel

Metadata describing custom fields exposed to search.

Show JSON schema:
{
  "description": "Metadata describing custom fields exposed to search.",
  "properties": {
    "label": {
      "title": "Label",
      "type": "string"
    },
    "type": {
      "title": "Type",
      "type": "string"
    },
    "isSortable": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Issortable"
    },
    "sortByParam": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Sortbyparam"
    },
    "isCustom": {
      "title": "Iscustom",
      "type": "boolean"
    }
  },
  "required": [
    "label",
    "type",
    "isCustom"
  ],
  "title": "SearchableCustomField",
  "type": "object"
}

Fields:

label

label: str

type

type: str

is_sortable

is_sortable: bool | None = None

sort_by_param

sort_by_param: str | None = None

is_custom

is_custom: bool