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 (list or string) 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'

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 and string. String fields cannot be searchable and are used to set uncontrolled metadata. List fields can be searchable and are used to set controlled metadata.

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.

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 | None

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

max int | 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.

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.

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')

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 | None = Field(default=None)

max

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

entity_categories

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

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)

pattern

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

default

default: Default | 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