Skip to content

Loader

amltk.store.loader #

Module containing the base protocol of a loader.

For concrete implementations based on the key being a Path see the path_loaders module.

Loader #

Bases: ABC, Generic[KeyT_contra, T]

The base definition of a Loader.

A Loader is a class that can save and load objects to and from a bucket. The Loader is responsible for knowing how to save and load objects of a particular type at a given key.

name class-attribute #

name: str

The name of the loader.

can_load abstractmethod classmethod #

can_load(
    key: KeyT_contra, /, *, check: type[T] | None = None
) -> bool

Return True if this loader supports the resource at key.

This is used to determine which loader to use when loading a resource from a key.

PARAMETER DESCRIPTION
key

The key used to identify the resource

TYPE: KeyT_contra

check

If the loader can support loading a specific type of object.

TYPE: type[T] | None DEFAULT: None

Source code in src/amltk/store/loader.py
@classmethod
@abstractmethod
def can_load(cls, key: KeyT_contra, /, *, check: type[T] | None = None) -> bool:
    """Return True if this loader supports the resource at key.

    This is used to determine which loader to use when loading a
    resource from a key.

    Args:
        key: The key used to identify the resource
        check: If the loader can support loading a specific type
            of object.
    """
    ...

can_save abstractmethod classmethod #

can_save(obj: Any, key: KeyT_contra) -> bool

Return True if this loader can save this object.

This is used to determine which loader to use when loading a resource from a key.

PARAMETER DESCRIPTION
obj

The object to save.

TYPE: Any

key

The key used to identify the resource

TYPE: KeyT_contra

Source code in src/amltk/store/loader.py
@classmethod
@abstractmethod
def can_save(cls, obj: Any, key: KeyT_contra, /) -> bool:
    """Return True if this loader can save this object.

    This is used to determine which loader to use when loading a
    resource from a key.

    Args:
        obj: The object to save.
        key: The key used to identify the resource
    """
    ...

load abstractmethod classmethod #

load(key: KeyT_contra) -> T

Load an object from the given key.

PARAMETER DESCRIPTION
key

The key to load the object from.

TYPE: KeyT_contra

RETURNS DESCRIPTION
T

The loaded object.

Source code in src/amltk/store/loader.py
@classmethod
@abstractmethod
def load(cls, key: KeyT_contra, /) -> T:
    """Load an object from the given key.

    Args:
        key: The key to load the object from.

    Returns:
        The loaded object.
    """
    ...

save abstractmethod classmethod #

save(obj: Any, key: KeyT_contra) -> Stored[T]

Save an object to under the given key.

PARAMETER DESCRIPTION
obj

The object to save.

TYPE: Any

key

The key to save the object under.

TYPE: KeyT_contra

Source code in src/amltk/store/loader.py
@classmethod
@abstractmethod
def save(cls, obj: Any, key: KeyT_contra, /) -> Stored[T]:
    """Save an object to under the given key.

    Args:
        obj: The object to save.
        key: The key to save the object under.
    """
    ...