Lists
albert.collections.lists.ListsCollection
Bases: BaseCollection
Manage List Items in the Albert platform.
A List Item is a single allowed value in a configurable list of options, such
as the choices offered by a dropdown custom field or a fixed set of category
values. Each item has a name, a category
(ListItemCategory, e.g. userDefined or
inventory), and a list_type that ties it to the specific list it
belongs to.
List Items most often populate the lists defined by list-type Custom
Fields: a CustomField with
LIST creates a new list
whose list_type is typically the field's name, and each selectable option
is a List Item with that same list_type. To offer choices on such a field,
add List Items here with a matching list_type (see
CustomFieldCollection). Some
list_type values are instead built-in platform lists (e.g. projectState,
casCategory, inventoryFunction).
This collection is accessed as client.lists.
Example
from albert import Albert
from albert.resources.lists import ListItem
client = Albert()
# Populate the options for a dropdown custom field with stage-gate values
stages = [
"1. Discovery",
"2. Concept Validation",
"3. Proof of Concept",
"4. Prototype Development",
]
# Get the custom field this list is associated with
stage_gate_field = client.custom_fields.get_by_id(id="CTF123")
# Create the list items
for s in stages:
item = ListItem(
name=s,
category=stage_gate_field.category,
list_type=stage_gate_field.name,
)
client.lists.create(list_item=item)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for list requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new list item. |
get_by_id |
Get a single list item by its ID. |
get_all |
Iterate over list items with optional filters. |
get_matching_item |
Find a list item by name within a given list type. |
update |
Update an existing list item. |
delete |
Delete a list item by its ID. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/lists.py
get_all
get_all(
*,
names: list[str] | None = None,
category: ListItemCategory | None = None,
list_type: str | None = None,
order_by: OrderBy = DESCENDING,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[ListItem]
Iterate over list items, with optional filters.
Results are fetched page by page as you iterate, so this scales to large result sets without loading everything at once.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
One or more item names to filter by. |
None
|
category
|
ListItemCategory
|
Restrict results to a single category (e.g. |
None
|
list_type
|
str
|
Restrict results to a single list type (often a custom field name). |
None
|
order_by
|
OrderBy
|
Sort direction for results. Defaults to |
DESCENDING
|
start_key
|
str
|
Pagination key to resume iteration from a previous position. |
None
|
max_items
|
int
|
Maximum number of items to return in total. If None, iterates over all matching items. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[ListItem]
|
An iterator over the matching list items. |
Source code in src/albert/collections/lists.py
get_by_id
Get a single list item by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the list item to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
ListItem
|
The fully populated list item. |
Source code in src/albert/collections/lists.py
create
Create a new list item.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_item
|
ListItem
|
The list item to create. |
required |
Returns:
| Type | Description |
|---|---|
ListItem
|
The newly created list item, including its assigned ID. |
Source code in src/albert/collections/lists.py
delete
delete(*, id: str) -> None
Delete a list item by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the list item to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/lists.py
get_matching_item
Find a list item by name within a given list type.
Performs a ranked search and returns the first item whose name matches
name (case-insensitive) within the given list type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the item to retrieve. |
required |
list_type
|
str
|
The list type to search within (often the name of a custom field). |
required |
Returns:
| Type | Description |
|---|---|
ListItem or None
|
The matching list item, or None if no item with that name and list type exists. |
Source code in src/albert/collections/lists.py
update
Update an existing list item.
Fetch a list item (e.g. via get_by_id), modify its name, then pass
it here. The item is matched by its id. If nothing changed, the
existing item is returned unmodified.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list_item
|
ListItem
|
The list item carrying the desired changes. Must have its |
ListItem
|
Returns:
| Type | Description |
|---|---|
ListItem
|
The updated list item, re-fetched from Albert. |
Notes
The following fields can be updated: name.