─░├žeri─če ge├ž

Referans i├žin hub_sdk/base/crud_client.py

Not

Bu dosya https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/base/crud_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.base.crud_client.CRUDClient

├ťsler: APIClient

Belirli bir kaynakla etkile┼čim i├žin bir CRUD (Olu┼čtur, Oku, G├╝ncelle, Sil) istemcisini temsil eder.

Nitelikler:

─░sim Tip A├ž─▒klama
name str

CRUD i┼člemleri ile ili┼čkili ad (├Ârne─čin, "Kullan─▒c─▒").

logger Logger

G├╝nl├╝k tutma ama├žl─▒ bir logger ├Ârne─či.

Kaynak kodu hub_sdk/base/crud_client.py
class CRUDClient(APIClient):
    """
    Represents a CRUD (Create, Read, Update, Delete) client for interacting with a specific resource.

    Attributes:
        name (str): The name associated with the CRUD operations (e.g., "User").
        logger (logging.Logger): An instance of the logger for logging purposes.
    """

    def __init__(self, base_endpoint, name, headers):
        """
        Initialize a CRUDClient instance.

        Args:
            base_endpoint (str): The base endpoint URL for the API.
            name (str): The name associated with the CRUD operations (e.g., "User").
            headers (dict): Headers to be included in API requests.
        """
        super().__init__(f"{HUB_FUNCTIONS_ROOT}/v1/{base_endpoint}", headers)
        self.name = name
        self.logger = logger

    def create(self, data: dict) -> Optional[Response]:
        """
        Create a new entity using the API.

        Args:
            data (dict): The data to be sent as part of the creation request.

        Returns:
            (Optional[Response]): Response object from the create request, or None if upload fails.
        """
        try:
            return self.post("", json=data)
        except Exception as e:
            self.logger.error(f"Failed to create {self.name}: {e}")

    def read(self, id: str) -> Optional[Response]:
        """
        Retrieve details of a specific entity.

        Args:
            id (str): The unique identifier of the entity to retrieve.

        Returns:
            (Optional[Response]): Response object from the read request, or None if read fails.
        """
        try:
            return self.get(f"/{id}")
        except Exception as e:
            self.logger.error(f"Failed to read {self.name} with ID: {id}, {e}")

    def update(self, id: str, data: dict) -> Optional[Response]:
        """
        Update an existing entity using the API.

        Args:
            id (str): The unique identifier of the entity to update.
            data (dict): The updated data to be sent in the update request.

        Returns:
            (Optional[Response]): Response object from the update request, or None if update fails.
        """
        try:
            return self.patch(f"/{id}", json=data)
        except Exception as e:
            self.logger.error(f"Failed to update {self.name} with ID: {id}, {e}")

    def delete(self, id: str, hard: bool = False) -> Optional[Response]:
        """
        Delete an entity using the API.

        Args:
            id (str): The unique identifier of the entity to delete.
            hard (bool, optional): If True, perform a hard delete. If False, perform a soft delete.

        Returns:
            (Optional[Response]): Response object from the delete request, or None if delete fails.
        """
        try:
            return super().delete(f"/{id}", {"hard": hard})
        except Exception as e:
            self.logger.error(f"Failed to delete {self.name} with ID: {id}, {e}")

    def list(self, page: int = 0, limit: int = 10) -> Optional[Response]:
        """
        List entities using the API.

        Args:
            page (int, optional): The page number to retrieve.
            limit (int, optional): The maximum number of entities per page.

        Returns:
            (Optional[Response]): Response object from the list request, or None if it fails.
        """
        try:
            params = {"page": page, "limit": limit}
            return self.get("", params=params)
        except Exception as e:
            self.logger.error(f"Failed to list {self.name}: {e}")

__init__(base_endpoint, name, headers)

Bir CRUDClient ├Ârne─čini ba┼člat─▒n.

Parametreler:

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

API i├žin temel u├ž nokta URL'si.

gerekli
name str

CRUD i┼člemleri ile ili┼čkili ad (├Ârne─čin, "Kullan─▒c─▒").

gerekli
headers dict

API isteklerine dahil edilecek ba┼čl─▒klar.

gerekli
Kaynak kodu hub_sdk/base/crud_client.py
def __init__(self, base_endpoint, name, headers):
    """
    Initialize a CRUDClient instance.

    Args:
        base_endpoint (str): The base endpoint URL for the API.
        name (str): The name associated with the CRUD operations (e.g., "User").
        headers (dict): Headers to be included in API requests.
    """
    super().__init__(f"{HUB_FUNCTIONS_ROOT}/v1/{base_endpoint}", headers)
    self.name = name
    self.logger = logger

create(data)

API kullanarak yeni bir varl─▒k olu┼čturun.

Parametreler:

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

Olu┼čturma iste─činin bir par├žas─▒ olarak g├Ânderilecek veriler.

gerekli

─░ade:

Tip A├ž─▒klama
Optional[Response]

Olu┼čturma iste─činden gelen yan─▒t nesnesi veya y├╝kleme ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/base/crud_client.py
def create(self, data: dict) -> Optional[Response]:
    """
    Create a new entity using the API.

    Args:
        data (dict): The data to be sent as part of the creation request.

    Returns:
        (Optional[Response]): Response object from the create request, or None if upload fails.
    """
    try:
        return self.post("", json=data)
    except Exception as e:
        self.logger.error(f"Failed to create {self.name}: {e}")

delete(id, hard=False)

API kullanarak bir varl─▒─č─▒ silin.

Parametreler:

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

Silinecek varl─▒─č─▒n benzersiz tan─▒mlay─▒c─▒s─▒.

gerekli
hard bool

True ise, sert bir silme i┼člemi ger├žekle┼čtirin. False ise, yumu┼čak bir silme i┼člemi ger├žekle┼čtirin.

False

─░ade:

Tip A├ž─▒klama
Optional[Response]

Silme iste─činden gelen yan─▒t nesnesi veya silme ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/base/crud_client.py
def delete(self, id: str, hard: bool = False) -> Optional[Response]:
    """
    Delete an entity using the API.

    Args:
        id (str): The unique identifier of the entity to delete.
        hard (bool, optional): If True, perform a hard delete. If False, perform a soft delete.

    Returns:
        (Optional[Response]): Response object from the delete request, or None if delete fails.
    """
    try:
        return super().delete(f"/{id}", {"hard": hard})
    except Exception as e:
        self.logger.error(f"Failed to delete {self.name} with ID: {id}, {e}")

list(page=0, limit=10)

API kullanan varl─▒klar─▒ listeleyin.

Parametreler:

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

Al─▒nacak sayfa numaras─▒.

0
limit int

Sayfa ba┼č─▒na maksimum varl─▒k say─▒s─▒.

10

─░ade:

Tip A├ž─▒klama
Optional[Response]

Liste iste─činden gelen yan─▒t nesnesi veya ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/base/crud_client.py
def list(self, page: int = 0, limit: int = 10) -> Optional[Response]:
    """
    List entities using the API.

    Args:
        page (int, optional): The page number to retrieve.
        limit (int, optional): The maximum number of entities per page.

    Returns:
        (Optional[Response]): Response object from the list request, or None if it fails.
    """
    try:
        params = {"page": page, "limit": limit}
        return self.get("", params=params)
    except Exception as e:
        self.logger.error(f"Failed to list {self.name}: {e}")

read(id)

Belirli bir varl─▒─č─▒n ayr─▒nt─▒lar─▒n─▒ al─▒n.

Parametreler:

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

Al─▒nacak varl─▒─č─▒n benzersiz tan─▒mlay─▒c─▒s─▒.

gerekli

─░ade:

Tip A├ž─▒klama
Optional[Response]

Okuma iste─činden gelen yan─▒t nesnesi veya okuma ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/base/crud_client.py
def read(self, id: str) -> Optional[Response]:
    """
    Retrieve details of a specific entity.

    Args:
        id (str): The unique identifier of the entity to retrieve.

    Returns:
        (Optional[Response]): Response object from the read request, or None if read fails.
    """
    try:
        return self.get(f"/{id}")
    except Exception as e:
        self.logger.error(f"Failed to read {self.name} with ID: {id}, {e}")

update(id, data)

API kullanarak mevcut bir varl─▒─č─▒ g├╝ncelleyin.

Parametreler:

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

G├╝ncellenecek varl─▒─č─▒n benzersiz tan─▒mlay─▒c─▒s─▒.

gerekli
data dict

G├╝ncelleme iste─činde g├Ânderilecek g├╝ncellenmi┼č veriler.

gerekli

─░ade:

Tip A├ž─▒klama
Optional[Response]

G├╝ncelleme iste─činden gelen yan─▒t nesnesi veya g├╝ncelleme ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/base/crud_client.py
def update(self, id: str, data: dict) -> Optional[Response]:
    """
    Update an existing entity using the API.

    Args:
        id (str): The unique identifier of the entity to update.
        data (dict): The updated data to be sent in the update request.

    Returns:
        (Optional[Response]): Response object from the update request, or None if update fails.
    """
    try:
        return self.patch(f"/{id}", json=data)
    except Exception as e:
        self.logger.error(f"Failed to update {self.name} with ID: {id}, {e}")