aixplain.v2.resource
BaseResource Objects
class BaseResource()
Base class for all resources.
Attributes:
context
- Aixplain: The Aixplain instance.RESOURCE_PATH
- str: The resource path.
__init__
def __init__(obj: Union[dict, Any])
Initialize a BaseResource instance.
Arguments:
obj
- dict: Dictionary containing the resource's attributes.
__getattr__
def __getattr__(key: str) -> Any
Return the value corresponding to the key from the wrapped dictionary if found, otherwise raise an AttributeError.
Arguments:
key
- str: Attribute name to retrieve from the resource.
Returns:
Any
- Value corresponding to the specified key.
Raises:
AttributeError
- If the key is not found in the wrapped dictionary.
save
def save()
Save the resource.
If the resource has an ID, it will be updated, otherwise it will be created.
BaseListParams Objects
class BaseListParams(TypedDict)
Base class for all list parameters.
Attributes:
query
- str: The query string.ownership
- Tuple[OwnershipType, List[OwnershipType]]: The ownership type.sort_by
- SortBy: The attribute to sort by.sort_order
- SortOrder: The order to sort by.page_number
- int: The page number.page_size
- int: The page size.
BaseGetParams Objects
class BaseGetParams(TypedDict)
Base class for all get parameters.
Attributes:
id
- str: The resource ID.
BaseCreateParams Objects
class BaseCreateParams(TypedDict)
Base class for all create parameters.
Attributes:
name
- str: The name of the resource.
BareCreateParams Objects
class BareCreateParams(BaseCreateParams)
Default implementation of create parameters.
BareListParams Objects
class BareListParams(BaseListParams)
Default implementation of list parameters.
BareGetParams Objects
class BareGetParams(BaseGetParams)
Default implementation of get parameters.
Page Objects
class Page(Generic[R])
Page of resources.
Attributes:
items
- List[R]: The list of resources.total
- int: The total number of resources.
ListResourceMixin Objects
class ListResourceMixin(Generic[L, R])
Mixin for listing resources.
Attributes:
PAGINATE_PATH
- str: The path for pagination.PAGINATE_METHOD
- str: The method for pagination.PAGINATE_ITEMS_KEY
- str: The key for the response.PAGINATE_TOTAL_KEY
- str: The key for the total number of resources.PAGINATE_PAGE_TOTAL_KEY
- str: The key for the total number of pages.PAGINATE_DEFAULT_PAGE_NUMBER
- int: The default page number.PAGINATE_DEFAULT_PAGE_SIZE
- int: The default page size.
list
@classmethod
def list(cls: Type[R], **kwargs: Unpack[L]) -> Page[R]
List resources across the first n pages with optional filtering.
Arguments:
kwargs
- Unpack[L]: The keyword arguments.
Returns:
Page[R]
- Page of BaseResource instances
GetResourceMixin Objects
class GetResourceMixin(Generic[G, R])
Mixin for getting a resource.
get
@classmethod
def get(cls: Type[R], id: Any, **kwargs: Unpack[G]) -> R
Retrieve a single resource by its ID (or other get parameters).
Arguments:
id
- Any: The ID of the resource to get.kwargs
- Unpack[G]: Get parameters to pass to the request.
Returns:
BaseResource
- Instance of the BaseResource class.
Raises:
ValueError
- If 'RESOURCE_PATH' is not defined by the subclass.
CreateResourceMixin Objects
class CreateResourceMixin(Generic[C, R])
Mixin for creating a resource.
create
@classmethod
def create(cls, *args, **kwargs: Unpack[C]) -> R
Create a resource.
Arguments:
kwargs
- Unpack[C]: The keyword arguments.
Returns:
BaseResource
- The created resource.