Skip to content

Notes

albert.collections.notes.NotesCollection

NotesCollection(*, session: AlbertSession)

Bases: BaseCollection

NotesCollection is a collection class for managing Note entities in the Albert platform.

Methods:

Name Description
create

Creates a new note.

get_by_id

Retrieves a note by its ID.

update

Updates a note.

delete

Deletes a note by its ID.

get_by_parent_id

Get all notes by their parent ID.

Attributes:

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

base_path

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

create

create(*, note: Note) -> Note

Creates a new note.

Parameters:

Name Type Description Default
note str

The note content.

required

Returns:

Type Description
Note

The created note.

Source code in src/albert/collections/notes.py
def create(self, *, note: Note) -> Note:
    """
    Creates a new note.

    Parameters
    ----------
    note : str
        The note content.

    Returns
    -------
    Note
        The created note.
    """
    response = self.session.post(
        self.base_path, json=note.model_dump(by_alias=True, exclude_unset=True, mode="json")
    )
    return Note(**response.json())

get_by_id

get_by_id(*, id: str) -> Note

Retrieves a note by its ID.

Parameters:

Name Type Description Default
id str

The ID of the note to retrieve.

required

Returns:

Type Description
Note

The note if found, None otherwise.

Source code in src/albert/collections/notes.py
def get_by_id(self, *, id: str) -> Note:
    """
    Retrieves a note by its ID.

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

    Returns
    -------
    Note
        The note if found, None otherwise.
    """
    response = self.session.get(f"{self.base_path}/{id}")
    return Note(**response.json())

update

update(*, note: Note) -> Note

Updates a note.

Parameters:

Name Type Description Default
note Note

The note to update. The note must have an ID.

required

Returns:

Type Description
Note

The updated note as returned by the server.

Source code in src/albert/collections/notes.py
def update(self, *, note: Note) -> Note:
    """Updates a note.

    Parameters
    ----------
    note : Note
        The note to update. The note must have an ID.

    Returns
    -------
    Note
        The updated note as returned by the server.
    """
    patch = self._generate_patch_payload(
        existing=self.get_by_id(id=note.id), updated=note, generate_metadata_diff=False
    )
    self.session.patch(
        f"{self.base_path}/{note.id}",
        json=patch.model_dump(mode="json", by_alias=True, exclude_unset=True),
    )
    return self.get_by_id(id=note.id)

delete

delete(*, id: str) -> None

Deletes a note by its ID.

Parameters:

Name Type Description Default
id str

The ID of the note to delete.

required
Source code in src/albert/collections/notes.py
def delete(self, *, id: str) -> None:
    """
    Deletes a note by its ID.

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

get_by_parent_id

get_by_parent_id(
    *, parent_id: str, order_by: OrderBy = DESCENDING
) -> list[Note]

Get all notes by their parent ID.

Parameters:

Name Type Description Default
parent_id str

The parent ID of the notes to list.

required
order_by OrderBy

The order to list notes in. Default is DESCENDING.

DESCENDING

Returns:

Type Description
list[Note]

A list of Note entities.

Source code in src/albert/collections/notes.py
def get_by_parent_id(
    self,
    *,
    parent_id: str,
    order_by: OrderBy = OrderBy.DESCENDING,
) -> list[Note]:
    """
    Get all notes by their parent ID.

    Parameters
    ----------
    parent_id : str
        The parent ID of the notes to list.
    order_by : OrderBy, optional
        The order to list notes in. Default is DESCENDING.

    Returns
    -------
    list[Note]
        A list of Note entities.
    """
    params = {
        "parentId": parent_id,
        "orderBy": order_by.value,
    }
    response = self.session.get(
        url=self.base_path,
        params=params,
    )
    return [Note(**x) for x in response.json()["Items"]]