Workflows
albert.collections.workflows
AlbertSession
AlbertSession(
*,
base_url: str,
token: str | None = None,
client_credentials: ClientCredentials | None = None,
retries: int | None = None,
)
Bases: Session
A session that has a base URL, which is prefixed to all request URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_url
|
str
|
The base URL to prefix to all requests. (e.g., "https://sandbox.albertinvent.com") |
required |
retries
|
int
|
The number of retries for failed requests. Defaults to 3. |
None
|
client_credentials
|
ClientCredentials | None
|
The client credentials for programmatic authentication. Optional if token is provided. |
None
|
token
|
str | None
|
The JWT token for authentication. Optional if client credentials are provided. |
None
|
Methods:
Name | Description |
---|---|
request |
|
Source code in src/albert/session.py
request
Source code in src/albert/session.py
BaseCollection
BaseCollection(*, session: AlbertSession)
BaseCollection is the base class for all collection classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
AlbertSession
|
The Albert API Session instance. |
required |
Source code in src/albert/collections/base.py
Workflow
Bases: BaseResource
A Pydantic Class representing a workflow in Albert.
Workflows are combinations of Data Templates and Parameter groups and their associated setpoints.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the workflow. |
parameter_group_setpoints |
list[ParameterGroupSetpoints]
|
The setpoints to apply to the parameter groups in the workflow. |
id |
str | None
|
The AlbertID of the workflow. This is set when a workflow is retrived from the platform. |
Methods:
Name | Description |
---|---|
get_interval_id |
Get the interval ID for a set of parameter values. |
model_post_init |
|
id
class-attribute
instance-attribute
id: str | None = Field(
alias="albertId",
default=None,
validation_alias=AliasChoices(
"albertId", "existingAlbertId"
),
exclude=True,
)
interval_combinations
class-attribute
instance-attribute
interval_combinations: list[IntervalCombination] | None = (
Field(default=None, alias="IntervalCombinations")
)
parameter_group_setpoints
class-attribute
instance-attribute
parameter_group_setpoints: list[ParameterGroupSetpoints] = (
Field(alias="ParameterGroups")
)
get_interval_id
Get the interval ID for a set of parameter values.
This method matches parameter values to intervals defined in the workflow and constructs a composite interval ID. For multiple parameters, the interval IDs are joined with 'X'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameter_values
|
dict[str, any]
|
Dictionary mapping parameter names to their values. Values can be numbers or strings that match the interval values defined in the workflow. |
required |
Returns:
Type | Description |
---|---|
str
|
The composite interval ID string. For a single parameter this is just the interval ID. For multiple parameters, interval IDs are joined with 'X' (e.g. "ROW1XROW2"). |
Raises:
Type | Description |
---|---|
ValueError
|
If any parameter value does not match a defined interval in the workflow. |
Examples:
>>> workflow = Workflow(...)
>>> # Single parameter
>>> workflow.get_interval_id({"Temperature": 25})
'ROW1'
>>> # Multiple parameters
>>> workflow.get_interval_id({"Temperature": 25, "Time": 60})
'ROW1XROW2'
>>> # Non-matching value raises error
>>> workflow.get_interval_id({"Temperature": 999})
AlbertException: No matching interval found for parameter 'Temperature' with value '999'
Source code in src/albert/resources/workflows.py
WorkflowCollection
WorkflowCollection(*, session: AlbertSession)
Bases: BaseCollection
WorkflowCollection is a collection class for managing Workflow entities in the Albert platform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Methods:
Name | Description |
---|---|
create |
Create or return matching workflows for the provided list of workflows. |
get_by_id |
Retrieve a Workflow by its ID. |
get_by_ids |
Returns a list of Workflow objects by their IDs. |
list |
List all workflows. Unlikly to be used in production. |
Source code in src/albert/collections/workflows.py
create
Create or return matching workflows for the provided list of workflows. This endpoint automatically tries to find an existing workflow with the same parameter setpoints, and will either return the existing workflow or create a new one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
workflows
|
list[Workflow]
|
A list of Workflow objects to find or create. |
required |
Returns:
Type | Description |
---|---|
list[Workflow]
|
A list of created or found Workflow objects. |
Source code in src/albert/collections/workflows.py
get_by_id
get_by_ids
Returns a list of Workflow objects by their IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
list[str]
|
The list of Workflow IDs to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[Workflow]
|
The list of Workflow objects matching the provided IDs. |
Source code in src/albert/collections/workflows.py
list
List all workflows. Unlikly to be used in production.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
limit
|
int
|
The number of workflows to return, by default 50. |
50
|
Yields:
Type | Description |
---|---|
Iterator[Workflow]
|
An iterator of Workflow objects. |