Skip to main content
Version: 1.0

aixplain.v2.resource

BaseResource Objects

class BaseResource()

[view_source]

Base class for all resources.

Attributes:

  • context - Aixplain: The Aixplain instance.
  • RESOURCE_PATH - str: The resource path.

__init__

def __init__(obj: Union[dict, Any])

[view_source]

Initialize a BaseResource instance.

Arguments:

  • obj - dict: Dictionary containing the resource's attributes.

__getattr__

def __getattr__(key: str) -> Any

[view_source]

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()

[view_source]

Save the resource.

If the resource has an ID, it will be updated, otherwise it will be created.

BaseListParams Objects

class BaseListParams(TypedDict)

[view_source]

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)

[view_source]

Base class for all get parameters.

Attributes:

  • id - str: The resource ID.

BaseCreateParams Objects

class BaseCreateParams(TypedDict)

[view_source]

Base class for all create parameters.

Attributes:

  • name - str: The name of the resource.

BareCreateParams Objects

class BareCreateParams(BaseCreateParams)

[view_source]

Default implementation of create parameters.

BareListParams Objects

class BareListParams(BaseListParams)

[view_source]

Default implementation of list parameters.

BareGetParams Objects

class BareGetParams(BaseGetParams)

[view_source]

Default implementation of get parameters.

Page Objects

class Page(Generic[R])

[view_source]

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])

[view_source]

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]

[view_source]

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])

[view_source]

Mixin for getting a resource.

get

@classmethod
def get(cls: Type[R], id: Any, **kwargs: Unpack[G]) -> R

[view_source]

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])

[view_source]

Mixin for creating a resource.

create

@classmethod
def create(cls, *args, **kwargs: Unpack[C]) -> R

[view_source]

Create a resource.

Arguments:

  • kwargs - Unpack[C]: The keyword arguments.

Returns:

  • BaseResource - The created resource.