Skip to content

Links

albert.collections.links.LinksCollection

LinksCollection(*, session: AlbertSession)

Bases: BaseCollection

LinksCollection is a collection class for managing Link entities in the Albert platform.

Parameters:

Name Type Description Default
session AlbertSession

The Albert session instance.

required

Methods:

Name Description
create

Creates a new link entity.

get_all

Get all link entities with optional filters.

get_by_id

Retrieves a link entity by its ID.

delete

Deletes a link entity by its ID.

Attributes:

Name Type Description
base_path
Source code in src/albert/collections/links.py
def __init__(self, *, session: AlbertSession):
    """
    Initializes the LinksCollection with the provided session.

    Parameters
    ----------
    session : AlbertSession
        The Albert session instance.
    """
    super().__init__(session=session)
    self.base_path = f"/api/{LinksCollection._api_version}/links"

base_path

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

create

create(*, links: list[Link]) -> list[Link]

Creates a new link entity.

Parameters:

Name Type Description Default
links list[Link]

List of Link entities to create.

required

Returns:

Type Description
Link

The created link entity.

Source code in src/albert/collections/links.py
def create(self, *, links: list[Link]) -> list[Link]:
    """
    Creates a new link entity.

    Parameters
    ----------
    links : list[Link]
        List of Link entities to create.

    Returns
    -------
    Link
        The created link entity.
    """
    response = self.session.post(
        self.base_path,
        json=[l.model_dump(by_alias=True, exclude_none=True, mode="json") for l in links],
    )
    return [Link(**l) for l in response.json()]

get_all

get_all(
    *,
    type: str | None = None,
    category: LinkCategory | None = None,
    id: str | None = None,
    start_key: str | None = None,
    max_items: int | None = None,
) -> Iterator[Link]

Get all link entities with optional filters.

Parameters:

Name Type Description Default
type str

The type of the link entities to return. Allowed values are parent, child, and all. If type is "all", both parent and child records for the given ID will be returned.

None
category LinkCategory

The category of the link entities to return. Allowed values are mention, linkedTask, and synthesis.

None
id str

The ID of the entity to fetch links for.

None
start_key str

The pagination key to start from.

None
max_items int

Maximum number of items to return in total. If None, fetches all available items.

None

Returns:

Type Description
Iterator[Link]

An iterator of Link entities.

Source code in src/albert/collections/links.py
def get_all(
    self,
    *,
    type: str | None = None,
    category: LinkCategory | None = None,
    id: str | None = None,
    start_key: str | None = None,
    max_items: int | None = None,
) -> Iterator[Link]:
    """
    Get all link entities with optional filters.

    Parameters
    ----------
    type : str, optional
        The type of the link entities to return. Allowed values are `parent`, `child`, and `all`.
        If type is "all", both parent and child records for the given ID will be returned.
    category : LinkCategory, optional
        The category of the link entities to return. Allowed values are `mention`, `linkedTask`, and `synthesis`.
    id : str, optional
        The ID of the entity to fetch links for.
    start_key : str, optional
        The pagination key to start from.
    max_items : int, optional
        Maximum number of items to return in total. If None, fetches all available items.

    Returns
    -------
    Iterator[Link]
        An iterator of Link entities.
    """
    params = {
        "type": type,
        "category": category,
        "id": id,
        "startKey": start_key,
    }

    return AlbertPaginator(
        mode=PaginationMode.KEY,
        path=self.base_path,
        session=self.session,
        params=params,
        max_items=max_items,
        deserialize=lambda items: [Link(**item) for item in items],
    )

get_by_id

get_by_id(*, id: LinkId) -> Link

Retrieves a link entity by its ID.

Parameters:

Name Type Description Default
id str

The ID of the link entity to retrieve.

required

Returns:

Type Description
Link

The retrieved link entity.

Source code in src/albert/collections/links.py
@validate_call
def get_by_id(self, *, id: LinkId) -> Link:
    """
    Retrieves a link entity by its ID.

    Parameters
    ----------
    id : str
        The ID of the link entity to retrieve.

    Returns
    -------
    Link
        The retrieved link entity.
    """
    path = f"{self.base_path}/{id}"
    response = self.session.get(path)
    return Link(**response.json())

delete

delete(*, id: LinkId) -> None

Deletes a link entity by its ID.

Parameters:

Name Type Description Default
id str

The ID of the link entity to delete.

required
Source code in src/albert/collections/links.py
@validate_call
def delete(self, *, id: LinkId) -> None:
    """
    Deletes a link entity by its ID.

    Parameters
    ----------
    id : str
        The ID of the link entity to delete.
    """
    path = f"{self.base_path}/{id}"
    self.session.delete(path)