─░├žeri─če ge├ž

Referans i├žin hub_sdk/hub_client.py

Not

Bu dosya https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/hub_client .py adresinde mevcuttur. Bir sorun tespit ederseniz, l├╝tfen bir ├çekme ─░ste─či ­čŤá´ŞĆ ile katk─▒da bulunarak d├╝zeltmeye yard─▒mc─▒ olun. Te┼čekk├╝rler ­čÖĆ!



hub_sdk.hub_client.HUBClient

├ťsler: Auth

Kimlik do─črulama yeteneklerini geni┼čleten bir HUB hizmeti ile etkile┼čim i├žin bir istemci s─▒n─▒f─▒.

Nitelikler:

─░sim Tip A├ž─▒klama
authenticated bool

─░stemcinin kimli─činin do─črulan─▒p do─črulanmad─▒─č─▒n─▒ g├Âsterir.

api_key str

Kimlik do─črulama i├žin API anahtar─▒.

id_token str

Kimlik do─črulama i├žin kimlik belirteci.

Kaynak kodu 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) -> Datasets:
        """
        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.
        """
        return Datasets(dataset_id, self.get_auth_header())

    @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.
        """
        return Projects(project_id, self.get_auth_header())

    @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] = 10, 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] = 10, 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.
        """
        return ProjectList(page_size, public, self.get_auth_header())

    @require_authentication
    def dataset_list(self, page_size: Optional[int] = 10, 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.
        """
        return DatasetList(page_size, public, self.get_auth_header())

    @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 ├Ârne─čini ba┼člat─▒r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
credentials dict

Kimlik do─črulama bilgilerini i├žeren bir s├Âzl├╝k. Yok ise, istemci API anahtar─▒n─▒ almaya ├žal─▒┼čacakt─▒r "HUB_API_KEY" ortam de─či┼čkeninden.

None
Kaynak kodu 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)

Veri k├╝meleriyle etkile┼čim i├žin Datasets s─▒n─▒f─▒n─▒n bir ├Ârne─čini d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
dataset_id str

Veri k├╝mesinin tan─▒mlay─▒c─▒s─▒. Sa─članm─▒┼čsa, belirtilen dataset_id ile ili┼čkili bir ├Ârnek d├Ând├╝r├╝r.

None

─░ade:

Tip A├ž─▒klama
Datasets

Datasets s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu hub_sdk/hub_client.py
@require_authentication
def dataset(self, dataset_id: str = None) -> Datasets:
    """
    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.
    """
    return Datasets(dataset_id, self.get_auth_header())

dataset_list(page_size=10, public=None)

Bir veri k├╝meleri listesiyle etkile┼čim i├žin bir DatasetList ├Ârne─či d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
page_size int

Sayfa ba┼č─▒na veri k├╝mesi say─▒s─▒.

10
public bool

Genel veri k├╝mesi listesini almak i├žin true de─čerini ge├žin.

None

─░ade:

Tip A├ž─▒klama
DatasetList

DatasetList s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu hub_sdk/hub_client.py
@require_authentication
def dataset_list(self, page_size: Optional[int] = 10, 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.
    """
    return DatasetList(page_size, public, self.get_auth_header())

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

Sa─članan kimlik do─črulama bilgilerini kullanarak istemcide oturum a├žar.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
api_key str

Kimlik do─črulama i├žin API anahtar─▒.

None
id_token str

Kimlik do─črulama i├žin kimlik belirteci.

None
email str

Kullan─▒c─▒n─▒n e-postas─▒.

None
password str

Kullan─▒c─▒ ┼čifresi.

None
Kaynak kodu 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)

Modellerle etkile┼čim i├žin Models s─▒n─▒f─▒n─▒n bir ├Ârne─čini d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
model_id str

Modelin tan─▒mlay─▒c─▒s─▒. Sa─članm─▒┼čsa, belirtilen model_id ile ili┼čkili bir ├Ârnek d├Ând├╝r├╝r.

None

─░ade:

Tip A├ž─▒klama
Models

Models s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu 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=10, public=None)

Bir model listesiyle etkile┼čim i├žin bir ModelList ├Ârne─či d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
page_size int

Sayfa ba┼č─▒na model say─▒s─▒.

10
public bool

Genel modeller listesini almak i├žin true de─čerini ge├žin.

None

─░ade:

Tip A├ž─▒klama
ModelList

ModelList s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu hub_sdk/hub_client.py
@require_authentication
def model_list(self, page_size: Optional[int] = 10, 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)

Projects ile etkile┼čim i├žin Projects s─▒n─▒f─▒n─▒n bir ├Ârne─čini d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
project_id str

Projenin tan─▒mlay─▒c─▒s─▒. Sa─članm─▒┼čsa, belirtilen project_id ile ili┼čkili bir ├Ârnek d├Ând├╝r├╝r.

None

─░ade:

Tip A├ž─▒klama
Projects

Projeler s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu 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.
    """
    return Projects(project_id, self.get_auth_header())

project_list(page_size=10, public=None)

Bir proje listesiyle etkile┼čim i├žin bir ProjectList ├Ârne─či d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
page_size int

Sayfa ba┼č─▒na d├╝┼čen proje say─▒s─▒.

10
public bool

Genel modeller listesini almak i├žin true de─čerini ge├žin.

None

─░ade:

Tip A├ž─▒klama
ProjectList

ProjectList s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu hub_sdk/hub_client.py
@require_authentication
def project_list(self, page_size: Optional[int] = 10, 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.
    """
    return ProjectList(page_size, public, self.get_auth_header())

team(arg)

Ekiplerle etkile┼čim i├žin Teams s─▒n─▒f─▒n─▒n bir ├Ârne─čini d├Ând├╝r├╝r.

Kaynak kodu 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)

─░ste─če ba─čl─▒ sayfaland─▒rma ile ekip ├╝yelerinin bir listesini getirir.

Kaynak kodu 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)

Projects ile etkile┼čim i├žin Users s─▒n─▒f─▒n─▒n bir ├Ârne─čini d├Ând├╝r├╝r.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
user_id str

Kullan─▒c─▒n─▒n tan─▒mlay─▒c─▒s─▒. E─čer sa─članm─▒┼čsa, belirtilen user_id ile ili┼čkili bir ├Ârnek d├Ând├╝r├╝r.

None

─░ade:

Tip A├ž─▒klama
Users

Projeler s─▒n─▒f─▒n─▒n bir ├Ârne─či.

Kaynak kodu 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)

Sar─▒lm─▒┼č y├Ântemin yaln─▒zca istemcinin kimli─či do─čruland─▒─č─▒nda y├╝r├╝t├╝lebilmesini sa─člayan bir dekorat├Âr i┼člevi.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
func callable

Sar─▒lacak y├Ântem.

gerekli

─░ade:

Tip A├ž─▒klama
callable

Sarma y├Ântemi.

Kaynak kodu 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