Skip to content

anytype.ListView

Bases: APIWrapper

Source code in anytype/listview.py
class ListView(APIWrapper):
    def __init__(self):
        self._apiEndpoints: apiEndpoints | None = None
        self.space_id = ""
        self.list_id = ""
        self.id = ""
        self.name = ""

    @requires_auth
    def get_objectsinlistview(self, offset=0, limit=100) -> list[Object]:
        """
        Retrieve a list of objects displayed in the current list view.

        Sends a request to the API to fetch objects from a specific list view within a space,
        using pagination parameters.

        Parameters:
            offset (int, optional): The starting index for pagination. Defaults to 0.
            limit (int, optional): The maximum number of objects to retrieve. Defaults to 100.

        Returns:
            list[Object]: A list of Object instances parsed from the API response.
        """
        response = self._apiEndpoints.getObjectsInList(
            self.space_id, self.list_id, self.id, offset, limit
        )

        return [Object._from_api(self._apiEndpoints, data) for data in response.get("data", [])]

    def add_objectinlistview(self, obj: Object) -> None:
        """
        Add a one object to the current list view.

        This method assumes the object are already created and adds them to the
        current list view context in the space.

        Parameters:
            obj Object: One Object instances to be added to the list view.

        Returns:
            None

        Raises:
            Exception: If the API call to add objects to the list view fails.
        """
        self.add_objectsinlistview([obj])

    @requires_auth
    def add_objectsinlistview(self, objs: list[Object]) -> None:
        """
        Add a list of objects to the current list view.

        This method assumes the objects are already created and adds them to the
        current list view context in the space.

        Parameters:
            objs (list[Object]): A list of Object instances to be added to the list view.

        Returns:
            None

        Raises:
            Exception: If the API call to add objects to the list view fails.
        """
        id_lists = [obj.id for obj in objs]
        payload = {"objects": id_lists}
        response = self._apiEndpoints.addObjectsToList(self.space_id, self.list_id, payload)
        # TODO: implement

    @requires_auth
    def delete_objectinlistview(self, obj: Object | str) -> None:
        """
        Remove an object from the current list view.

        This does not delete the object from the space, only removes its association
        with the specific list view.

        Parameters:
            obj (Object): The Object instance to be removed from the list view.

        Returns:
            None

        Raises:
            Exception: If the API call to remove the object from the list view fails.
        """
        if isinstance(obj, Object):
            objId = obj.id
        else:
            objId = obj
        assert objId != ""
        self._apiEndpoints.deleteObjectsFromList(self.space_id, self.list_id, objId)

    def __repr__(self) -> str:
        return f"<ListView(name={self.name})>"

add_objectinlistview(obj)

Add a one object to the current list view.

This method assumes the object are already created and adds them to the current list view context in the space.

Parameters:

Name Type Description Default
obj Object

One Object instances to be added to the list view.

required

Returns:

Type Description
None

None

Raises:

Type Description
Exception

If the API call to add objects to the list view fails.

Source code in anytype/listview.py
def add_objectinlistview(self, obj: Object) -> None:
    """
    Add a one object to the current list view.

    This method assumes the object are already created and adds them to the
    current list view context in the space.

    Parameters:
        obj Object: One Object instances to be added to the list view.

    Returns:
        None

    Raises:
        Exception: If the API call to add objects to the list view fails.
    """
    self.add_objectsinlistview([obj])

add_objectsinlistview(objs)

Add a list of objects to the current list view.

This method assumes the objects are already created and adds them to the current list view context in the space.

Parameters:

Name Type Description Default
objs list[Object]

A list of Object instances to be added to the list view.

required

Returns:

Type Description
None

None

Raises:

Type Description
Exception

If the API call to add objects to the list view fails.

Source code in anytype/listview.py
@requires_auth
def add_objectsinlistview(self, objs: list[Object]) -> None:
    """
    Add a list of objects to the current list view.

    This method assumes the objects are already created and adds them to the
    current list view context in the space.

    Parameters:
        objs (list[Object]): A list of Object instances to be added to the list view.

    Returns:
        None

    Raises:
        Exception: If the API call to add objects to the list view fails.
    """
    id_lists = [obj.id for obj in objs]
    payload = {"objects": id_lists}
    response = self._apiEndpoints.addObjectsToList(self.space_id, self.list_id, payload)

delete_objectinlistview(obj)

Remove an object from the current list view.

This does not delete the object from the space, only removes its association with the specific list view.

Parameters:

Name Type Description Default
obj Object

The Object instance to be removed from the list view.

required

Returns:

Type Description
None

None

Raises:

Type Description
Exception

If the API call to remove the object from the list view fails.

Source code in anytype/listview.py
@requires_auth
def delete_objectinlistview(self, obj: Object | str) -> None:
    """
    Remove an object from the current list view.

    This does not delete the object from the space, only removes its association
    with the specific list view.

    Parameters:
        obj (Object): The Object instance to be removed from the list view.

    Returns:
        None

    Raises:
        Exception: If the API call to remove the object from the list view fails.
    """
    if isinstance(obj, Object):
        objId = obj.id
    else:
        objId = obj
    assert objId != ""
    self._apiEndpoints.deleteObjectsFromList(self.space_id, self.list_id, objId)

get_objectsinlistview(offset=0, limit=100)

Retrieve a list of objects displayed in the current list view.

Sends a request to the API to fetch objects from a specific list view within a space, using pagination parameters.

Parameters:

Name Type Description Default
offset int

The starting index for pagination. Defaults to 0.

0
limit int

The maximum number of objects to retrieve. Defaults to 100.

100

Returns:

Type Description
list[Object]

list[Object]: A list of Object instances parsed from the API response.

Source code in anytype/listview.py
@requires_auth
def get_objectsinlistview(self, offset=0, limit=100) -> list[Object]:
    """
    Retrieve a list of objects displayed in the current list view.

    Sends a request to the API to fetch objects from a specific list view within a space,
    using pagination parameters.

    Parameters:
        offset (int, optional): The starting index for pagination. Defaults to 0.
        limit (int, optional): The maximum number of objects to retrieve. Defaults to 100.

    Returns:
        list[Object]: A list of Object instances parsed from the API response.
    """
    response = self._apiEndpoints.getObjectsInList(
        self.space_id, self.list_id, self.id, offset, limit
    )

    return [Object._from_api(self._apiEndpoints, data) for data in response.get("data", [])]