μ½˜ν…μΈ λ‘œ κ±΄λ„ˆλ›°κΈ°

μ°Έμ‘° hub_sdk/hub_client.py

μ°Έκ³ 

이 νŒŒμΌμ€ https://github.com/ultralytics/ hub-sdk/blob/main/ hub_sdk/ hub_client .pyμ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€. 문제λ₯Ό λ°œκ²¬ν•˜λ©΄ ν’€ λ¦¬ν€˜μŠ€νŠΈ (πŸ› οΈ)λ₯Ό μ œμΆœν•˜μ—¬ 문제λ₯Ό ν•΄κ²°ν•˜λ„λ‘ λ„μ™€μ£Όμ„Έμš”. κ°μ‚¬ν•©λ‹ˆλ‹€ πŸ™!



hub_sdk.hub_client.HUBClient

기지: Auth

HUB μ„œλΉ„μŠ€μ™€ μƒν˜Έ μž‘μš©ν•˜μ—¬ 인증 κΈ°λŠ₯을 ν™•μž₯ν•˜κΈ° μœ„ν•œ ν΄λΌμ΄μ–ΈνŠΈ ν΄λž˜μŠ€μž…λ‹ˆλ‹€.

속성:

이름 μœ ν˜• μ„€λͺ…
authenticated bool

ν΄λΌμ΄μ–ΈνŠΈκ°€ μΈμ¦λ˜μ—ˆλŠ”μ§€ μ—¬λΆ€λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€.

api_key str

인증을 μœ„ν•œ API ν‚€μž…λ‹ˆλ‹€.

id_token str

인증을 μœ„ν•œ ID ν† ν°μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
class HUBClient(Auth):
    """
    A client class for interacting with a HUB service, extending authentication capabilities.

    Attributes:
        authenticated (bool): Indicates whether the client is authenticated.
        api_key (str): The API key for authentication.
        id_token (str): The identity token for authentication.
    """

    def __init__(self, credentials: Optional[Dict] = None):
        """
        Initializes the HUBClient instance.

        Args:
            credentials (dict, optional): A dictionary containing authentication credentials.
                            If None, the client will attempt to retrieve the API key
                            from the environment variable "HUB_API_KEY".
        """
        super().__init__()
        self.authenticated = False
        if not credentials:
            self.api_key = os.environ.get("HUB_API_KEY")  # Safely retrieve the API key from an environment variable.
            credentials = {"api_key": self.api_key}

        self.login(**credentials)

    def login(self, api_key=None, id_token=None, email=None, password=None):
        """
        Logs in the client using provided authentication credentials.

        Args:
            api_key (str, optional): The API key for authentication.
            id_token (str, optional): The identity token for authentication.
            email (str, optional): User's email.
            password (str, optional): User's password.
        """
        self.api_key = api_key
        self.id_token = id_token
        if (
            (self.api_key or self.id_token)
            and self.authenticate()
            or not self.api_key
            and not self.id_token
            and email
            and password
            and self.authorize(email, password)
        ):
            self.authenticated = True

    @require_authentication
    def model(self, model_id: Optional[str] = None) -> Models:
        """
        Returns an instance of the Models class for interacting with models.

        Args:
            model_id (str, optional): The identifier of the model. If provided,
                returns an instance associated with the specified model_id.

        Returns:
            (Models): An instance of the Models class.
        """
        return Models(model_id, self.get_auth_header())

    @require_authentication
    def dataset(self, dataset_id: str = None) -> DatasetList:
        """
        Returns an instance of the Datasets class for interacting with datasets.

        Args:
            dataset_id (str, optional): The identifier of the dataset. If provided,
                returns an instance associated with the specified dataset_id.

        Returns:
            (Datasets): An instance of the Datasets class.
        """
        raise Exception("Coming Soon")

    @require_authentication
    def team(self, arg):
        """Returns an instance of the Teams class for interacting with teams."""
        raise Exception("Coming Soon")

    @require_authentication
    def project(self, project_id: Optional[str] = None) -> Projects:
        """
        Returns an instance of the Projects class for interacting with Projects.

        Args:
            project_id (str, optional): The identifier of the project. If provided,
                returns an instance associated with the specified project_id.

        Returns:
            (Projects): An instance of the Projects class.
        """
        raise Exception("Coming Soon")

    @require_authentication
    def user(self, user_id: Optional[str] = None) -> Users:
        """
        Returns an instance of the Users class for interacting with Projects.

        Args:
            user_id (str, optional): The identifier of the user. If provided,
                returns an instance associated with the specified user_id.

        Returns:
            (Users): An instance of the Projects class.
        """
        return Users(user_id, self.get_auth_header())

    @require_authentication
    def model_list(self, page_size: Optional[int] = None, public: Optional[bool] = None) -> ModelList:
        """
        Returns a ModelList instance for interacting with a list of models.

        Args:
            page_size (int, optional): The number of models per page.
            public (bool, optional): Pass true to retrieve list of Public models list.

        Returns:
            (ModelList): An instance of the ModelList class.
        """
        return ModelList(page_size, public, self.get_auth_header())

    @require_authentication
    def project_list(self, page_size: Optional[int] = None, public: Optional[bool] = None) -> ProjectList:
        """
        Returns a ProjectList instance for interacting with a list of projects.

        Args:
            page_size (int, optional): The number of projects per page.
            public (bool, optional): Pass true to retrieve list of Public models list.

        Returns:
            (ProjectList): An instance of the ProjectList class.
        """
        raise Exception("Coming Soon")

    @require_authentication
    def dataset_list(self, page_size: Optional[int] = None, public: Optional[bool] = None) -> DatasetList:
        """
        Returns a DatasetList instance for interacting with a list of datasets.

        Args:
            page_size (int, optional): The number of datasets per page.
            public (bool, optional): Pass true to retrieve list of Public dataset list.

        Returns:
            (DatasetList): An instance of the DatasetList class.
        """
        raise Exception("Coming Soon")

    @require_authentication
    def team_list(self, page_size=None, public=None):
        """Fetches a list of team members with optional pagination."""
        raise Exception("Coming Soon")

__init__(credentials=None)

HUBClient μΈμŠ€ν„΄μŠ€λ₯Ό μ΄ˆκΈ°ν™”ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
credentials dict

인증 자격 증λͺ…이 ν¬ν•¨λœ λ”•μ…”λ„ˆλ¦¬μž…λ‹ˆλ‹€. None인 경우, ν΄λΌμ΄μ–ΈνŠΈλŠ” ν™˜κ²½ λ³€μˆ˜μΈ HUB λ₯Ό κ²€μƒ‰ν•˜λ €κ³  μ‹œλ„ν•©λ‹ˆλ‹€.

None
의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
def __init__(self, credentials: Optional[Dict] = None):
    """
    Initializes the HUBClient instance.

    Args:
        credentials (dict, optional): A dictionary containing authentication credentials.
                        If None, the client will attempt to retrieve the API key
                        from the environment variable "HUB_API_KEY".
    """
    super().__init__()
    self.authenticated = False
    if not credentials:
        self.api_key = os.environ.get("HUB_API_KEY")  # Safely retrieve the API key from an environment variable.
        credentials = {"api_key": self.api_key}

    self.login(**credentials)

dataset(dataset_id=None)

데이터 μ„ΈνŠΈμ™€ μƒν˜Έ μž‘μš©ν•˜κΈ° μœ„ν•œ 데이터 μ„ΈνŠΈ 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
dataset_id str

데이터 μ§‘ν•©μ˜ μ‹λ³„μžμž…λ‹ˆλ‹€. 제곡된 경우, λŠ” μ§€μ •λœ dataset_id와 μ—°κ΄€λœ μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
Datasets

λ°μ΄ν„°μ„ΈνŠΈ 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def dataset(self, dataset_id: str = None) -> DatasetList:
    """
    Returns an instance of the Datasets class for interacting with datasets.

    Args:
        dataset_id (str, optional): The identifier of the dataset. If provided,
            returns an instance associated with the specified dataset_id.

    Returns:
        (Datasets): An instance of the Datasets class.
    """
    raise Exception("Coming Soon")

dataset_list(page_size=None, public=None)

데이터 μ„ΈνŠΈ λͺ©λ‘κ³Ό μƒν˜Έ μž‘μš©ν•  수 μžˆλŠ” DatasetList μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
page_size int

νŽ˜μ΄μ§€λ‹Ή 데이터 μ„ΈνŠΈ μˆ˜μž…λ‹ˆλ‹€.

None
public bool

참을 μ „λ‹¬ν•˜λ©΄ 곡개 데이터 μ„ΈνŠΈ λͺ©λ‘μ΄ κ²€μƒ‰λ©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
DatasetList

DatasetList 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def dataset_list(self, page_size: Optional[int] = None, public: Optional[bool] = None) -> DatasetList:
    """
    Returns a DatasetList instance for interacting with a list of datasets.

    Args:
        page_size (int, optional): The number of datasets per page.
        public (bool, optional): Pass true to retrieve list of Public dataset list.

    Returns:
        (DatasetList): An instance of the DatasetList class.
    """
    raise Exception("Coming Soon")

login(api_key=None, id_token=None, email=None, password=None)

제곡된 인증 자격 증λͺ…을 μ‚¬μš©ν•˜μ—¬ ν΄λΌμ΄μ–ΈνŠΈμ— λ‘œκ·ΈμΈν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
api_key str

인증을 μœ„ν•œ API ν‚€μž…λ‹ˆλ‹€.

None
id_token str

인증을 μœ„ν•œ ID ν† ν°μž…λ‹ˆλ‹€.

None
email str

μ‚¬μš©μžμ˜ 이메일.

None
password str

μ‚¬μš©μžμ˜ λΉ„λ°€λ²ˆν˜Έμž…λ‹ˆλ‹€.

None
의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
def login(self, api_key=None, id_token=None, email=None, password=None):
    """
    Logs in the client using provided authentication credentials.

    Args:
        api_key (str, optional): The API key for authentication.
        id_token (str, optional): The identity token for authentication.
        email (str, optional): User's email.
        password (str, optional): User's password.
    """
    self.api_key = api_key
    self.id_token = id_token
    if (
        (self.api_key or self.id_token)
        and self.authenticate()
        or not self.api_key
        and not self.id_token
        and email
        and password
        and self.authorize(email, password)
    ):
        self.authenticated = True

model(model_id=None)

λͺ¨λΈκ³Ό μƒν˜Έμž‘μš©ν•  수 μžˆλŠ” λͺ¨λΈ 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
model_id str

λͺ¨λΈμ˜ μ‹λ³„μžμž…λ‹ˆλ‹€. 제곡된 경우, λŠ” μ§€μ •λœ model_id와 μ—°κ΄€λœ μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
Models

λͺ¨λΈ 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def model(self, model_id: Optional[str] = None) -> Models:
    """
    Returns an instance of the Models class for interacting with models.

    Args:
        model_id (str, optional): The identifier of the model. If provided,
            returns an instance associated with the specified model_id.

    Returns:
        (Models): An instance of the Models class.
    """
    return Models(model_id, self.get_auth_header())

model_list(page_size=None, public=None)

λͺ¨λΈ λͺ©λ‘κ³Ό μƒν˜Έμž‘μš©ν•  수 μžˆλŠ” ModelList μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
page_size int

νŽ˜μ΄μ§€λ‹Ή λͺ¨λΈ μˆ˜μž…λ‹ˆλ‹€.

None
public bool

참을 μ „λ‹¬ν•˜λ©΄ 곡개 λͺ¨λΈ λͺ©λ‘ λͺ©λ‘μ„ κ²€μƒ‰ν•©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
ModelList

ModelList 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def model_list(self, page_size: Optional[int] = None, public: Optional[bool] = None) -> ModelList:
    """
    Returns a ModelList instance for interacting with a list of models.

    Args:
        page_size (int, optional): The number of models per page.
        public (bool, optional): Pass true to retrieve list of Public models list.

    Returns:
        (ModelList): An instance of the ModelList class.
    """
    return ModelList(page_size, public, self.get_auth_header())

project(project_id=None)

ν”„λ‘œμ νŠΈμ™€ μƒν˜Έμž‘μš©ν•˜κΈ° μœ„ν•œ ν”„λ‘œμ νŠΈ 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
project_id str

ν”„λ‘œμ νŠΈμ˜ μ‹λ³„μžμž…λ‹ˆλ‹€. 제곡된 경우, λŠ” μ§€μ •λœ project_id와 μ—°κ΄€λœ μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
Projects

ν”„λ‘œμ νŠΈ 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def project(self, project_id: Optional[str] = None) -> Projects:
    """
    Returns an instance of the Projects class for interacting with Projects.

    Args:
        project_id (str, optional): The identifier of the project. If provided,
            returns an instance associated with the specified project_id.

    Returns:
        (Projects): An instance of the Projects class.
    """
    raise Exception("Coming Soon")

project_list(page_size=None, public=None)

ν”„λ‘œμ νŠΈ λͺ©λ‘κ³Ό μƒν˜Έμž‘μš©ν•  수 μžˆλŠ” ProjectList μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
page_size int

νŽ˜μ΄μ§€λ‹Ή ν”„λ‘œμ νŠΈ μˆ˜μž…λ‹ˆλ‹€.

None
public bool

참을 μ „λ‹¬ν•˜λ©΄ 곡개 λͺ¨λΈ λͺ©λ‘ λͺ©λ‘μ„ κ²€μƒ‰ν•©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
ProjectList

ProjectList 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def project_list(self, page_size: Optional[int] = None, public: Optional[bool] = None) -> ProjectList:
    """
    Returns a ProjectList instance for interacting with a list of projects.

    Args:
        page_size (int, optional): The number of projects per page.
        public (bool, optional): Pass true to retrieve list of Public models list.

    Returns:
        (ProjectList): An instance of the ProjectList class.
    """
    raise Exception("Coming Soon")

team(arg)

νŒ€κ³Ό μƒν˜Έ μž‘μš©ν•  수 μžˆλŠ” Teams 클래슀의 μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def team(self, arg):
    """Returns an instance of the Teams class for interacting with teams."""
    raise Exception("Coming Soon")

team_list(page_size=None, public=None)

νŽ˜μ΄μ§€ 맀김 μ˜΅μ…˜μ΄ μžˆλŠ” νŒ€μ› λͺ©λ‘μ„ κ°€μ Έμ˜΅λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def team_list(self, page_size=None, public=None):
    """Fetches a list of team members with optional pagination."""
    raise Exception("Coming Soon")

user(user_id=None)

ν”„λ‘œμ νŠΈμ™€ μƒν˜Έμž‘μš©ν•˜κΈ° μœ„ν•œ μ‚¬μš©μž 클래슀 μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
user_id str

μ‚¬μš©μžμ˜ μ‹λ³„μžμž…λ‹ˆλ‹€. 제곡된 경우, λŠ” μ§€μ •λœ user_id와 μ—°κ΄€λœ μΈμŠ€ν„΄μŠ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

None

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
Users

ν”„λ‘œμ νŠΈ 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
@require_authentication
def user(self, user_id: Optional[str] = None) -> Users:
    """
    Returns an instance of the Users class for interacting with Projects.

    Args:
        user_id (str, optional): The identifier of the user. If provided,
            returns an instance associated with the specified user_id.

    Returns:
        (Users): An instance of the Projects class.
    """
    return Users(user_id, self.get_auth_header())



hub_sdk.hub_client.require_authentication(func)

ν΄λΌμ΄μ–ΈνŠΈκ°€ 인증된 κ²½μš°μ—λ§Œ λž˜ν•‘λœ λ©”μ„œλ“œλ₯Ό μ‹€ν–‰ν•  수 μžˆλ„λ‘ ν•˜λŠ” λ°μ½”λ ˆμ΄ν„° ν•¨μˆ˜μž…λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
func callable

λž˜ν•‘ν•  λ©”μ„œλ“œμž…λ‹ˆλ‹€.

ν•„μˆ˜

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
callable

λž˜ν•‘λœ 방법.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/hub_client.py
def require_authentication(func) -> callable:
    """
    A decorator function to ensure that the wrapped method can only be executed if the client is authenticated.

    Args:
        func (callable): The method to be wrapped.

    Returns:
        (callable): The wrapped method.
    """

    def wrapper(self, *args, **kwargs):
        """Decorator to ensure a method is called only if the user is authenticated."""
        if not self.authenticated and not kwargs.get("public"):
            raise PermissionError("Access Denied: Authentication required.")
        return func(self, *args, **kwargs)

    return wrapper