Skip to content

Breakthrough Model

albert.collections.btmodel.BTModelSessionCollection

BTModelSessionCollection(*, session: AlbertSession)

Bases: BaseCollection

BTModelSessionCollection is a collection class for managing Breakthrough model session entities.

Parameters:

Name Type Description Default
session AlbertSession

The Albert session instance.

required

Attributes:

Name Type Description
base_path str

The base path for BTModelSession API requests.

Methods:

Name Description
create
get_by_id
update
delete

Delete a BTModelSession by ID.

Source code in src/albert/collections/btmodel.py
def __init__(self, *, session: AlbertSession):
    super().__init__(session=session)
    self.base_path = f"/api/{BTModelSessionCollection._api_version}/btmodel"

base_path

base_path = f'/api/{_api_version}/btmodel'

create

create(*, model_session: BTModelSession) -> BTModelSession
Source code in src/albert/collections/btmodel.py
@validate_call
def create(self, *, model_session: BTModelSession) -> BTModelSession:
    response = self.session.post(
        self.base_path,
        json=model_session.model_dump(mode="json", by_alias=True, exclude_none=True),
    )
    return BTModelSession(**response.json())

get_by_id

get_by_id(*, id: BTModelSessionId) -> BTModelSession
Source code in src/albert/collections/btmodel.py
@validate_call
def get_by_id(self, *, id: BTModelSessionId) -> BTModelSession:
    response = self.session.get(f"{self.base_path}/{id}")
    return BTModelSession(**response.json())

update

update(*, model_session: BTModelSession) -> BTModelSession
Source code in src/albert/collections/btmodel.py
@validate_call
def update(self, *, model_session: BTModelSession) -> BTModelSession:
    path = f"{self.base_path}/{model_session.id}"
    payload = self._generate_patch_payload(
        existing=self.get_by_id(id=model_session.id),
        updated=model_session,
    )
    self.session.patch(path, json=payload.model_dump(mode="json", by_alias=True))
    return self.get_by_id(id=model_session.id)

delete

delete(*, id: BTModelSessionId) -> None

Delete a BTModelSession by ID.

Parameters:

Name Type Description Default
id BTModelSessionId

The ID of the BTModelSession to delete.

required

Returns:

Type Description
None
Source code in src/albert/collections/btmodel.py
@validate_call
def delete(self, *, id: BTModelSessionId) -> None:
    """Delete a BTModelSession by ID.

    Parameters
    ----------
    id : BTModelSessionId
        The ID of the BTModelSession to delete.

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

albert.collections.btmodel.BTModelCollection

BTModelCollection(*, session: AlbertSession)

Bases: BaseCollection

BTModelCollection is a collection class for managing Breakthrough model entities.

Breakthrough models can be associated with a parent Breakthrough model session, or a detached without a parent.

Parameters:

Name Type Description Default
session AlbertSession

The Albert session instance.

required

Methods:

Name Description
create

Create a new BTModel instance.

get_by_id

Retrieve a BTModel by its ID.

update

Update an existing BTModel.

delete

Delete a BTModel by ID.

Source code in src/albert/collections/btmodel.py
def __init__(self, *, session: AlbertSession):
    super().__init__(session=session)

create

create(
    *,
    model: BTModel,
    parent_id: BTModelSessionId | None = None,
) -> BTModel

Create a new BTModel instance.

Parameters:

Name Type Description Default
model BTModel

The BTModel instance to create.

required
parent_id BTModelSessionId | None

The optional ID of the parent BTModelSession.

None

Returns:

Type Description
BTModel

The created BTModel instance.

Source code in src/albert/collections/btmodel.py
@validate_call
def create(self, *, model: BTModel, parent_id: BTModelSessionId | None = None) -> BTModel:
    """
    Create a new BTModel instance.

    Parameters
    ----------
    model : BTModel
        The BTModel instance to create.
    parent_id : BTModelSessionId | None
        The optional ID of the parent BTModelSession.

    Returns
    -------
    BTModel
        The created BTModel instance.
    """
    base_path = self._get_base_path(parent_id)
    response = self.session.post(
        base_path,
        json=model.model_dump(mode="json", by_alias=True, exclude_none=True),
    )
    return BTModel(**response.json())

get_by_id

get_by_id(
    *,
    id: BTModelId,
    parent_id: BTModelSessionId | None = None,
) -> BTModel

Retrieve a BTModel by its ID.

Parameters:

Name Type Description Default
id BTModelId

The ID of the BTModel to retrieve.

required
parent_id BTModelSessionId | None

The optional ID of the parent BTModelSession.

None

Returns:

Type Description
BTModel

The retrieved BTModel instance.

Source code in src/albert/collections/btmodel.py
@validate_call
def get_by_id(self, *, id: BTModelId, parent_id: BTModelSessionId | None = None) -> BTModel:
    """
    Retrieve a BTModel by its ID.

    Parameters
    ----------
    id : BTModelId
        The ID of the BTModel to retrieve.
    parent_id : BTModelSessionId | None
        The optional ID of the parent BTModelSession.

    Returns
    -------
    BTModel
        The retrieved BTModel instance.
    """
    base_path = self._get_base_path(parent_id)
    response = self.session.get(f"{base_path}/{id}")
    return BTModel(**response.json())

update

update(
    *,
    model: BTModel,
    parent_id: BTModelSessionId | None = None,
) -> BTModel

Update an existing BTModel.

Parameters:

Name Type Description Default
model BTModel

The BTModel instance with updated data.

required
parent_id BTModelSessionId | None

The optional ID of the parent BTModelSession.

None

Returns:

Type Description
BTModel

The updated BTModel instance.

Source code in src/albert/collections/btmodel.py
@validate_call
def update(self, *, model: BTModel, parent_id: BTModelSessionId | None = None) -> BTModel:
    """
    Update an existing BTModel.

    Parameters
    ----------
    model : BTModel
        The BTModel instance with updated data.
    parent_id : BTModelSessionId | None
        The optional ID of the parent BTModelSession.

    Returns
    -------
    BTModel
        The updated BTModel instance.
    """
    base_path = self._get_base_path(parent_id)
    payload = self._generate_patch_payload(
        existing=self.get_by_id(id=model.id, parent_id=parent_id),
        updated=model,
        generate_metadata_diff=False,
    )
    self.session.patch(
        f"{base_path}/{model.id}",
        json=payload.model_dump(mode="json", by_alias=True),
    )
    return self.get_by_id(id=model.id, parent_id=parent_id)

delete

delete(
    *,
    id: BTModelId,
    parent_id: BTModelSessionId | None = None,
) -> None

Delete a BTModel by ID.

Parameters:

Name Type Description Default
id BTModelId

The ID of the BTModel to delete.

required
parent_id BTModelSessionId | None

The optional ID of the parent BTModelSession.

None

Returns:

Type Description
None
Source code in src/albert/collections/btmodel.py
@validate_call
def delete(self, *, id: BTModelId, parent_id: BTModelSessionId | None = None) -> None:
    """Delete a BTModel by ID.

    Parameters
    ----------
    id : BTModelId
        The ID of the BTModel to delete.
    parent_id : BTModelSessionId | None
        The optional ID of the parent BTModelSession.

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