Skip to content

aea.crypto.registries.base

This module implements the base registry.

ItemId Objects

class ItemId(RegexConstrainedString)

The identifier of an item class.

name

@property
def name() -> str

Get the id name.

EntryPoint Objects

class EntryPoint(Generic[ItemType], RegexConstrainedString)

The entry point for a resource.

The regular expression matches the strings in the following format:

path.to.module:className

__init__

def __init__(seq: Union["EntryPoint", str]) -> None

Initialize the entrypoint.

import_path

@property
def import_path() -> str

Get the import path.

class_name

@property
def class_name() -> str

Get the class name.

load

def load() -> Type[ItemType]

Load the item object.

Returns:

the crypto object, loaded following the spec.

ItemSpec Objects

class ItemSpec(Generic[ItemType])

A specification for a particular instance of an object.

__init__

def __init__(id_: ItemId,
             entry_point: EntryPoint[ItemType],
             class_kwargs: Optional[Dict[str, Any]] = None,
             **kwargs: Dict) -> None

Initialize an item specification.

Arguments:

  • id_: the id associated to this specification
  • entry_point: The Python entry_point of the environment class (e.g. module.name:Class).
  • class_kwargs: keyword arguments to be attached on the class as class variables.
  • kwargs: other custom keyword arguments.

make

def make(**kwargs: Any) -> ItemType

Instantiate an instance of the item object with appropriate arguments.

Arguments:

  • kwargs: the key word arguments

Returns:

an item

get_class

def get_class() -> Type[ItemType]

Get the class of the item with class variables instantiated.

Returns:

an item class

Registry Objects

class Registry(Generic[ItemType])

Registry for generic classes.

__init__

def __init__() -> None

Initialize the registry.

supported_ids

@property
def supported_ids() -> Set[str]

Get the supported item ids.

register

def register(id_: Union[ItemId, str],
             entry_point: Union[EntryPoint[ItemType], str],
             class_kwargs: Optional[Dict[str, Any]] = None,
             **kwargs: Any) -> None

Register an item type.

Arguments:

  • id_: the identifier for the crypto type.
  • entry_point: the entry point to load the crypto object.
  • class_kwargs: keyword arguments to be attached on the class as class variables.
  • kwargs: arguments to provide to the crypto class.

make

def make(id_: Union[ItemId, str],
         module: Optional[str] = None,
         **kwargs: Any) -> ItemType

Create an instance of the associated type item id.

Arguments:

  • id_: the id of the item class. Make sure it has been registered earlier before calling this function.
  • module: dotted path to a module. whether a module should be loaded before creating the object. this argument is useful when the item might not be registered beforehand, and loading the specified module will make the registration. E.g. suppose the call to 'register' for a custom object is located in some_package/init.py. By providing module="some_package", the call to 'register' in such module gets triggered and the make can then find the identifier.
  • kwargs: keyword arguments to be forwarded to the object.

Returns:

the new item instance.

make_cls

def make_cls(id_: Union[ItemId, str],
             module: Optional[str] = None) -> Type[ItemType]

Load a class of the associated type item id.

Arguments:

  • id_: the id of the item class. Make sure it has been registered earlier before calling this function.
  • module: dotted path to a module. whether a module should be loaded before creating the object. this argument is useful when the item might not be registered beforehand, and loading the specified module will make the registration. E.g. suppose the call to 'register' for a custom object is located in some_package/init.py. By providing module="some_package", the call to 'register' in such module gets triggered and the make can then find the identifier.

Returns:

the new item class.

has_spec

def has_spec(item_id: ItemId) -> bool

Check whether there exist a spec associated with an item id.

Arguments:

  • item_id: the item identifier.

Returns:

True if it is registered, False otherwise.