Skip to content

Targets (🧪Beta)

albert.collections.targets.TargetCollection

TargetCollection(*, session: AlbertSession)

Bases: BaseCollection

Manage Targets in the Albert platform (🧪 Beta).

A Target is a desired value or acceptable range for a measured property. It ties a data template and data column (the property being measured) to a target value constraint (Criterion, e.g. "greater than or equal to 90" or "between 10 and 20"), optionally scoped to a project and to specific parameter conditions. Targets let you express the performance a formulation is aiming for and compare results against it.

Targets are referenced by their Target ID (format TAR..., e.g. "TAR1").

This collection is accessed as client.targets.

Beta Feature!

Please do not use in production or without explicit guidance from Albert. You might otherwise have a bad experience. This feature currently falls outside of the Albert support contract, but we'd love your feedback!

Example

from albert import Albert
client = Albert()
target = client.targets.get_by_id(id="TAR1")
print(target.name, target.target_value)

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 target requests.

Methods:

Name Description
create

Create a new target.

get_by_id

Get a single target by its ID.

get_by_ids

Get many targets by their IDs.

delete

Delete a target 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/targets.py
def __init__(self, *, session: AlbertSession):
    """Initialize a TargetCollection.

    Parameters
    ----------
    session : AlbertSession
        The authenticated Albert session used for API calls.
    """
    super().__init__(session=session)
    self.base_path = f"/api/{TargetCollection._api_version}/targets"

base_path

base_path = f'/api/{TargetCollection._api_version}/targets'

create

create(*, target: Target) -> Target

Create a new target.

Example

from albert.resources.targets import (
    Target,
    TargetType,
    Criterion,
    ComparisonOperator,
)
target = client.targets.create(
    target=Target(
        name="Viscosity spec",
        type=TargetType.PERFORMANCE,
        data_template_id="DAT9999999",
        data_column_id="DAC9999999",
        target_value=Criterion(operator=ComparisonOperator.GTE, value=90),
        is_required=True,
    )
)

Parameters:

Name Type Description Default
target Target

The target to create.

required

Returns:

Type Description
Target

The newly created target, including its assigned Target ID.

Source code in src/albert/collections/targets.py
def create(self, *, target: Target) -> Target:
    """Create a new target.

    !!! example
        ```python
        from albert.resources.targets import (
            Target,
            TargetType,
            Criterion,
            ComparisonOperator,
        )
        target = client.targets.create(
            target=Target(
                name="Viscosity spec",
                type=TargetType.PERFORMANCE,
                data_template_id="DAT9999999",
                data_column_id="DAC9999999",
                target_value=Criterion(operator=ComparisonOperator.GTE, value=90),
                is_required=True,
            )
        )
        ```

    Parameters
    ----------
    target : Target
        The target to create.

    Returns
    -------
    Target
        The newly created target, including its assigned Target ID.
    """
    response = self.session.post(
        self.base_path,
        json=target.model_dump(by_alias=True, exclude_none=True, mode="json"),
    )
    return Target(**response.json())

get_by_id

get_by_id(
    *, id: TargetId, parent_id: ProjectId | None = None
) -> Target

Get a single target by its ID.

Example

target = client.targets.get_by_id(id="TAR1")

Parameters:

Name Type Description Default
id TargetId

The Target ID to retrieve (format TAR...).

required
parent_id ProjectId

The ID of a parent project to inherit the ACL (access control) policy from when the caller does not own the target record. Supply this if a plain lookup is denied for permission reasons.

None

Returns:

Type Description
Target

The fully populated target.

Source code in src/albert/collections/targets.py
@validate_call
def get_by_id(self, *, id: TargetId, parent_id: ProjectId | None = None) -> Target:
    """Get a single target by its ID.

    !!! example
        ```python
        target = client.targets.get_by_id(id="TAR1")
        ```

    Parameters
    ----------
    id : TargetId
        The Target ID to retrieve (format ``TAR...``).
    parent_id : ProjectId, optional
        The ID of a parent project to inherit the ACL (access control) policy
        from when the caller does not own the target record. Supply this if a
        plain lookup is denied for permission reasons.

    Returns
    -------
    Target
        The fully populated target.
    """
    url = f"{self.base_path}/{id}"
    params = {"parentId": parent_id} if parent_id is not None else None
    response = self.session.get(url, params=params)
    return Target(**response.json())

get_by_ids

get_by_ids(*, ids: list[TargetId]) -> list[Target]

Get many targets by their IDs.

Example

targets = client.targets.get_by_ids(ids=["TAR1", "TAR2"])

Parameters:

Name Type Description Default
ids list[TargetId]

The Target IDs to retrieve.

required

Returns:

Type Description
list[Target]

The matching targets. Targets not found are omitted.

Source code in src/albert/collections/targets.py
def get_by_ids(self, *, ids: list[TargetId]) -> list[Target]:
    """Get many targets by their IDs.

    !!! example
        ```python
        targets = client.targets.get_by_ids(ids=["TAR1", "TAR2"])
        ```

    Parameters
    ----------
    ids : list[TargetId]
        The Target IDs to retrieve.

    Returns
    -------
    list[Target]
        The matching targets. Targets not found are omitted.
    """
    url = f"{self.base_path}/ids"
    response = self.session.get(url, params={"id": ids})
    data = response.json()
    return [Target(**item) for item in data.get("Items", [])]

delete

delete(*, id: TargetId) -> None

Delete a target by its ID.

Example

client.targets.delete(id="TAR1")

Parameters:

Name Type Description Default
id TargetId

The Target ID to delete.

required

Returns:

Type Description
None
Source code in src/albert/collections/targets.py
def delete(self, *, id: TargetId) -> None:
    """Delete a target by its ID.

    !!! example
        ```python
        client.targets.delete(id="TAR1")
        ```

    Parameters
    ----------
    id : TargetId
        The Target ID to delete.

    Returns
    -------
    None
    """
    url = f"{self.base_path}/{id}"
    self.session.delete(url)