跳至内容

参考资料 hub_sdk/modules/teams.py

备注

该文件位于https://github.com/ultralytics/hub-sdk/blob/main/ hub_sdk/modules/teams .py。如果您发现问题,请通过提交 Pull Request🛠️ 帮助修复。谢谢🙏!



hub_sdk.modules.teams.Teams

垒球 CRUDClient

一个代表客户端的类,用于通过 CRUD 操作与团队进行交互。该类扩展了 CRUDClient 类的扩展,并提供与团队协同工作的特定方法。

属性

名称 类型 说明
id (str, None)

团队的唯一标识符(如有)。

data dict

用于存储团队数据的字典。

备注

id "属性在初始化时设置,可用于唯一标识一个团队。 data "属性用于存储从应用程序接口获取的团队数据。

源代码 hub_sdk/modules/teams.py
class Teams(CRUDClient):
    """
    A class representing a client for interacting with Teams through CRUD operations. This class extends the CRUDClient
    class and provides specific methods for working with Teams.

    Attributes:
        id (str, None): The unique identifier of the team, if available.
        data (dict): A dictionary to store team data.

    Note:
        The 'id' attribute is set during initialization and can be used to uniquely identify a team.
        The 'data' attribute is used to store team data fetched from the API.
    """

    def __init__(self, team_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None):
        """
        Initialize a Teams instance.

        Args:
            team_id (str, optional): The unique identifier of the team.
            headers (dict, optional): A dictionary of HTTP headers to be included in API requests.
        """
        super().__init__("teams", "team", headers)
        self.id = team_id
        self.data = {}
        if team_id:
            self.get_data()

    def get_data(self) -> None:
        """
        Retrieves data for the current team instance.

        If a valid team ID has been set, it sends a request to fetch the team data and stores it in the instance.
        If no team ID has been set, it logs an error message.

        Returns:
            (None): The method does not return a value.
        """
        if self.id:
            resp = super().read(self.id).json()
            self.data = resp.get("data", {})
            self.logger.debug("Team id is %s", self.id)
        else:
            self.logger.error("No team id has been set. Update the team id or create a team.")

    def create_team(self, team_data) -> None:
        """
        Creates a new team with the provided data and sets the team ID for the current instance.

        Args:
            team_data (dict): A dictionary containing the data for creating the team.

        Returns:
            (None): The method does not return a value.
        """
        resp = super().create(team_data).json()
        self.id = resp.get("data", {}).get("id")
        self.get_data()

    def delete(self, hard=False) -> Optional[Response]:
        """
        Delete the team resource represented by this instance.

        Args:
            hard (bool, optional): If True, perform a hard (permanent) delete.

        Note:
            The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
            In a soft delete, the team might be marked as deleted but retained in the system.
            In a hard delete, the team is permanently removed from the system.

        Returns:
            (Optional[Response]): The response from the delete request, or None if it fails.
        """
        return super().delete(self.id, hard)

    def update(self, data) -> Optional[Response]:
        """
        Update the team resource represented by this instance.

        Args:
            data (dict): The updated data for the team resource.

        Returns:
            (Optional[Response]): The response from the update request, or Noe if it fails.
        """
        return super().update(self.id, data)

__init__(team_id=None, headers=None)

初始化团队实例

参数

名称 类型 说明 默认值
team_id str

团队的唯一标识符。

None
headers dict

将包含在 API 请求中的 HTTP 标头字典。

None
源代码 hub_sdk/modules/teams.py
def __init__(self, team_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None):
    """
    Initialize a Teams instance.

    Args:
        team_id (str, optional): The unique identifier of the team.
        headers (dict, optional): A dictionary of HTTP headers to be included in API requests.
    """
    super().__init__("teams", "team", headers)
    self.id = team_id
    self.data = {}
    if team_id:
        self.get_data()

create_team(team_data)

使用提供的数据创建一个新团队,并为当前实例设置团队 ID。

参数

名称 类型 说明 默认值
team_data dict

包含创建团队数据的字典。

所需

返回:

类型 说明
None

该方法不返回值。

源代码 hub_sdk/modules/teams.py
def create_team(self, team_data) -> None:
    """
    Creates a new team with the provided data and sets the team ID for the current instance.

    Args:
        team_data (dict): A dictionary containing the data for creating the team.

    Returns:
        (None): The method does not return a value.
    """
    resp = super().create(team_data).json()
    self.id = resp.get("data", {}).get("id")
    self.get_data()

delete(hard=False)

删除该实例所代表的团队资源。

参数

名称 类型 说明 默认值
hard bool

如果为 True,则执行硬(永久)删除。

False
备注

硬 "参数决定执行软删除(默认)还是硬删除。 在软删除中,团队可能被标记为已删除,但仍保留在系统中。 在硬删除中,团队将从系统中永久删除。

返回:

类型 说明
Optional[Response]

删除请求的响应,如果失败则为 "无"。

源代码 hub_sdk/modules/teams.py
def delete(self, hard=False) -> Optional[Response]:
    """
    Delete the team resource represented by this instance.

    Args:
        hard (bool, optional): If True, perform a hard (permanent) delete.

    Note:
        The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
        In a soft delete, the team might be marked as deleted but retained in the system.
        In a hard delete, the team is permanently removed from the system.

    Returns:
        (Optional[Response]): The response from the delete request, or None if it fails.
    """
    return super().delete(self.id, hard)

get_data()

读取当前团队实例的数据。

如果设置了有效的团队 ID,它就会发送请求获取团队数据并将其存储在实例中。 如果没有设置团队 ID,则会记录一条错误信息。

返回:

类型 说明
None

该方法不返回值。

源代码 hub_sdk/modules/teams.py
def get_data(self) -> None:
    """
    Retrieves data for the current team instance.

    If a valid team ID has been set, it sends a request to fetch the team data and stores it in the instance.
    If no team ID has been set, it logs an error message.

    Returns:
        (None): The method does not return a value.
    """
    if self.id:
        resp = super().read(self.id).json()
        self.data = resp.get("data", {})
        self.logger.debug("Team id is %s", self.id)
    else:
        self.logger.error("No team id has been set. Update the team id or create a team.")

update(data)

更新该实例所代表的团队资源。

参数

名称 类型 说明 默认值
data dict

团队资源的更新数据。

所需

返回:

类型 说明
Optional[Response]

更新请求的响应,如果失败则为 Noe。

源代码 hub_sdk/modules/teams.py
def update(self, data) -> Optional[Response]:
    """
    Update the team resource represented by this instance.

    Args:
        data (dict): The updated data for the team resource.

    Returns:
        (Optional[Response]): The response from the update request, or Noe if it fails.
    """
    return super().update(self.id, data)



hub_sdk.modules.teams.TeamList

垒球 PaginatedList

源代码 hub_sdk/modules/teams.py
class TeamList(PaginatedList):
    def __init__(self, page_size=None, public=None, headers=None):
        """
        Initialize a TeamList instance.

        Args:
            page_size (int, optional): The number of items to request per page.
            public (bool, optional): Whether the items should be publicly accessible.
            headers (dict, optional): Headers to be included in API requests.
        """
        base_endpoint = "datasets"
        if public:
            base_endpoint = f"public/{base_endpoint}"
        super().__init__(base_endpoint, "team", page_size, headers)

__init__(page_size=None, public=None, headers=None)

初始化一个 TeamList 实例。

参数

名称 类型 说明 默认值
page_size int

每页要申请的项目数。

None
public bool

项目是否应向公众开放。

None
headers dict

应包含在 API 请求中的标头。

None
源代码 hub_sdk/modules/teams.py
def __init__(self, page_size=None, public=None, headers=None):
    """
    Initialize a TeamList instance.

    Args:
        page_size (int, optional): The number of items to request per page.
        public (bool, optional): Whether the items should be publicly accessible.
        headers (dict, optional): Headers to be included in API requests.
    """
    base_endpoint = "datasets"
    if public:
        base_endpoint = f"public/{base_endpoint}"
    super().__init__(base_endpoint, "team", page_size, headers)