Skip to content

aea.configurations.data_types

Base config data types.

JSONSerializable Objects

class JSONSerializable(ABC)

Interface for JSON-serializable objects.

json

@property
@abstractmethod
def json() -> Dict

Compute the JSON representation.

from_json

@classmethod
@abstractmethod
def from_json(cls, obj: Dict) -> "JSONSerializable"

Build from a JSON object.

PackageVersion Objects

@functools.total_ordering
class PackageVersion()

A package version.

__init__

def __init__(version_like: PackageVersionLike) -> None

Initialize a package version.

Arguments:

  • version_like: a string, os a semver.VersionInfo object.

is_any

@property
def is_any() -> bool

Check whether the version is 'any'.

is_latest

@property
def is_latest() -> bool

Check whether the version is 'latest'.

__str__

def __str__() -> str

Get the string representation.

__eq__

def __eq__(other: Any) -> bool

Check equality.

__lt__

def __lt__(other: Any) -> bool

Compare with another object.

PackageType Objects

class PackageType(Enum)

Package types.

to_plural

def to_plural() -> str

Get the plural name.

PackageType.AGENT.to_plural() 'agents' PackageType.PROTOCOL.to_plural() 'protocols' PackageType.CONNECTION.to_plural() 'connections' PackageType.SKILL.to_plural() 'skills' PackageType.CONTRACT.to_plural() 'contracts'

Returns:

pluralised package type

__str__

def __str__() -> str

Convert to string.

ComponentType Objects

class ComponentType(Enum)

Enum of component types supported.

to_package_type

def to_package_type() -> PackageType

Get package type for component type.

plurals

@staticmethod
def plurals() -> Collection[str]

Get the collection of type names, plural.

ComponentType.plurals() ['protocols', 'connections', 'skills', 'contracts', 'customs']

Returns:

list of all pluralised component types

to_plural

def to_plural() -> str

Get the plural version of the component type.

ComponentType.PROTOCOL.to_plural() 'protocols' ComponentType.CONNECTION.to_plural() 'connections' ComponentType.SKILL.to_plural() 'skills' ComponentType.CONTRACT.to_plural() 'contracts'

Returns:

pluralised component type

__str__

def __str__() -> str

Get the string representation.

PublicId Objects

@functools.total_ordering
class PublicId(JSONSerializable)

This class implement a public identifier.

A public identifier is composed of three elements: - author - name - version

The concatenation of those three elements gives the public identifier:

author/name:version

public_id = PublicId("author", "my_package", "0.1.0") assert public_id.author == "author" assert public_id.name == "my_package" assert public_id.version == "0.1.0" another_public_id = PublicId("author", "my_package", "0.1.0") assert hash(public_id) == hash(another_public_id) assert public_id == another_public_id latest_public_id = PublicId("author", "my_package", "latest") latest_public_id latest_public_id.package_version.is_latest True

__init__

def __init__(author: SimpleIdOrStr,
             name: SimpleIdOrStr,
             version: Optional[PackageVersionLike] = None,
             package_hash: Optional[IPFSHashOrStr] = None) -> None

Initialize the public identifier.

is_package_name_valid

@classmethod
def is_package_name_valid(cls, name: SimpleIdOrStr) -> bool

Check is package name valid.

Arguments:

  • name: str or SimpleID

Returns:

bool

is_author_name_valid

@classmethod
def is_author_name_valid(cls, name: SimpleIdOrStr) -> bool

Check is author name valid.

Arguments:

  • name: str or SimpleID

Returns:

bool

author

@property
def author() -> str

Get the author.

name

@property
def name() -> str

Get the name.

version

@property
def version() -> str

Get the version string.

package_version

@property
def package_version() -> PackageVersion

Get the package version object.

hash

@property
def hash() -> str

Returns the hash for the package.

same_prefix

def same_prefix(other: "PublicId") -> bool

Check if the other public id has the same author and name of this.

to_any

def to_any() -> "PublicId"

Return the same public id, but with any version.

to_latest

def to_latest() -> "PublicId"

Return the same public id, but with latest version.

is_valid_str

@classmethod
def is_valid_str(cls, public_id_string: str) -> bool

Check if a string is a public id.

Arguments:

  • public_id_string: the public id in string format.

Returns:

bool indicating validity

from_str

@classmethod
def from_str(cls, public_id_string: str) -> "PublicId"

Initialize the public id from the string.

str(PublicId.from_str("author/package_name:0.1.0")) 'author/package_name:0.1.0'

str(PublicId.from_str("author/package_name:0.1.0:QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH")) 'author/package_name:0.1.0:QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH'

A bad formatted input raises value error:

PublicId.from_str("bad/formatted:input") Traceback (most recent call last): ... ValueError: Input 'bad/formatted:input' is not well formatted.

PublicId.from_str("bad/formatted:0.1.0:Qmbadhash") Traceback (most recent call last): ... ValueError: Input 'bad/formatted:0.1.0:Qmbadhash' is not well formatted.

Arguments:

  • public_id_string: the public id in string format.

Raises:

  • ValueError: if the string in input is not well formatted.

Returns:

the public id object.

try_from_str

@classmethod
def try_from_str(cls, public_id_string: str) -> Optional["PublicId"]

Safely try to get public id from string.

Arguments:

  • public_id_string: the public id in string format.

Returns:

the public id object or None

from_uri_path

@classmethod
def from_uri_path(cls, public_id_uri_path: str) -> "PublicId"

Initialize the public id from the string.

str(PublicId.from_uri_path("author/package_name/0.1.0")) 'author/package_name:0.1.0'

A bad formatted input raises value error:

PublicId.from_uri_path("bad/formatted:input") Traceback (most recent call last): ... ValueError: Input 'bad/formatted:input' is not well formatted.

Arguments:

  • public_id_uri_path: the public id in uri path string format.

Raises:

  • ValueError: if the string in input is not well formatted.

Returns:

the public id object.

to_uri_path

@property
def to_uri_path() -> str

Turn the public id into a uri path string.

Returns:

uri path string

json

@property
def json() -> Dict

Compute the JSON representation.

from_json

@classmethod
def from_json(cls, obj: Dict) -> "PublicId"

Build from a JSON object.

__hash__

def __hash__() -> int

Get the hash.

__repr__

def __repr__() -> str

Get the representation.

__eq__

def __eq__(other: Any) -> bool

Check equality.

__lt__

def __lt__(other: Any) -> bool

Compare with another object.

without_hash

def without_hash() -> "PublicId"

Returns a PublicId object with same parameters.

with_hash

def with_hash(package_hash: str) -> "PublicId"

Returns a PublicId object with same parameters.

__str__

def __str__() -> str

Get the string representation.

PackageId Objects

@functools.total_ordering
class PackageId()

A package identifier.

__init__

def __init__(package_type: Union[PackageType, str],
             public_id: PublicId) -> None

Initialize the package id.

Arguments:

  • package_type: the package type.
  • public_id: the public id.

package_type

@property
def package_type() -> PackageType

Get the package type.

public_id

@property
def public_id() -> PublicId

Get the public id.

author

@property
def author() -> str

Get the author of the package.

name

@property
def name() -> str

Get the name of the package.

version

@property
def version() -> str

Get the version of the package.

package_hash

@property
def package_hash() -> str

Get the version of the package.

package_prefix

@property
def package_prefix() -> Tuple[PackageType, str, str]

Get the package identifier without the version.

from_uri_path

@classmethod
def from_uri_path(cls, package_id_uri_path: str) -> "PackageId"

Initialize the package id from the string.

str(PackageId.from_uri_path("skill/author/package_name/0.1.0")) '(skill, author/package_name:0.1.0)'

A bad formatted input raises value error:

PackageId.from_uri_path("very/bad/formatted:input") Traceback (most recent call last): ... ValueError: Input 'very/bad/formatted:input' is not well formatted.

Arguments:

  • package_id_uri_path: the package id in uri path string format.

Raises:

  • ValueError: if the string in input is not well formatted.

Returns:

the package id object.

to_uri_path

@property
def to_uri_path() -> str

Turn the package id into a uri path string.

Returns:

uri path string

without_hash

def without_hash() -> "PackageId"

Returns PackageId object without hash

with_hash

def with_hash(package_hash: str) -> "PackageId"

Returns PackageId object without hash

__hash__

def __hash__() -> int

Get the hash.

__str__

def __str__() -> str

Get the string representation.

__repr__

def __repr__() -> str

Get the object representation in string.

__eq__

def __eq__(other: Any) -> bool

Check equality.

__lt__

def __lt__(other: Any) -> bool

Compare two public ids.

ComponentId Objects

class ComponentId(PackageId)

Class to represent a component identifier.

A component id is a package id, but excludes the case when the package is an agent.

pacakge_id = PackageId(PackageType.PROTOCOL, PublicId("author", "name", "0.1.0")) component_id = ComponentId(ComponentType.PROTOCOL, PublicId("author", "name", "0.1.0")) pacakge_id == component_id True

component_id2 = ComponentId(ComponentType.PROTOCOL, PublicId("author", "name", "0.1.1")) pacakge_id == component_id2 False

__init__

def __init__(component_type: Union[ComponentType, str],
             public_id: PublicId) -> None

Initialize the component id.

Arguments:

  • component_type: the component type.
  • public_id: the public id.

component_type

@property
def component_type() -> ComponentType

Get the component type.

component_prefix

@property
def component_prefix() -> PackageIdPrefix

Get the component identifier without the version.

same_prefix

def same_prefix(other: "ComponentId") -> bool

Check if the other component id has the same type, author and name of this.

prefix_import_path

@property
def prefix_import_path() -> str

Get the prefix import path for this component.

json

@property
def json() -> Dict

Get the JSON representation.

from_json

@classmethod
def from_json(cls, json_data: Dict) -> "ComponentId"

Create component id from json data.

without_hash

def without_hash() -> "ComponentId"

Returns PackageId object without hash

PyPIPackageName Objects

class PyPIPackageName(RegexConstrainedString)

A PyPI Package name.

GitRef Objects

class GitRef(RegexConstrainedString)

A Git reference.

It can be a branch name, a commit hash or a tag.

Dependency Objects

class Dependency()

This class represents a PyPI dependency.

It contains the following information: - version: a version specifier(s) (e.g. '==0.1.0'). - index: the PyPI index where to download the package from (default: https://pypi.org) - git: the URL to the Git repository (e.g. https://github.com/fetchai/agents-aea.git) - ref: either the branch name, the tag, the commit number or a Git reference (default: 'master'.)

If the 'git' field is set, the 'version' field will be ignored. These fields will be forwarded to the 'pip' command.

__init__

def __init__(name: Union[PyPIPackageName, str],
             version: Union[str, SpecifierSet] = "",
             index: Optional[str] = None,
             git: Optional[str] = None,
             ref: Optional[Union[GitRef, str]] = None,
             extras: Optional[List[str]] = None) -> None

Initialize a PyPI dependency.

Arguments:

  • name: the package name.
  • version: the specifier set object
  • index: the URL to the PyPI server.
  • git: the URL to a git repository.
  • ref: the Git reference (branch/commit/tag).
  • extras: Include extras section for the dependency.

name

@property
def name() -> str

Get the name.

version

@property
def version() -> str

Get the version.

index

@property
def index() -> Optional[str]

Get the index.

git

@property
def git() -> Optional[str]

Get the git.

ref

@property
def ref() -> Optional[str]

Get the ref.

extras

@property
def extras() -> List[str]

Get the ref.

from_pipfile_string

@classmethod
def from_pipfile_string(cls, string: str) -> "Dependency"

Parse from Pipfile version specifier.

from_string

@classmethod
def from_string(cls, string: str) -> "Dependency"

Parse from string.

from_json

@classmethod
def from_json(cls, obj: Dict[str, Dict[str, str]]) -> "Dependency"

Parse a dependency object from a dictionary.

to_json

def to_json() -> Dict[str, Dict[str, str]]

Transform the object to JSON.

to_pip_string

def to_pip_string() -> str

To pip specifier.

to_pipfile_string

def to_pipfile_string() -> str

To Pipfile specifier.

get_pip_install_args

def get_pip_install_args() -> List[str]

Get 'pip install' arguments.

__str__

def __str__() -> str

Get the string representation.

__eq__

def __eq__(other: Any) -> bool

Check equality.

Dependencies

A dictionary from package name to dependency data structure (see above). The package name must satisfy the constraints on Python packages names.

The main advantage of having a dictionary is that we implicitly filter out dependency duplicates. We cannot have two items with the same package name since the keys of a YAML object form a set.

CRUDCollection Objects

class CRUDCollection(Generic[T])

Interface of a CRUD collection.

__init__

def __init__() -> None

Instantiate a CRUD collection.

create

def create(item_id: str, item: T) -> None

Add an item.

Arguments:

  • item_id: the item id.
  • item: the item to be added.

Raises:

  • ValueError: if the item with the same id is already in the collection.

read

def read(item_id: str) -> Optional[T]

Get an item by its name.

Arguments:

  • item_id: the item id.

Returns:

the associated item, or None if the item id is not present.

update

def update(item_id: str, item: T) -> None

Update an existing item.

Arguments:

  • item_id: the item id.
  • item: the item to be added.

delete

def delete(item_id: str) -> None

Delete an item.

read_all

def read_all() -> List[Tuple[str, T]]

Read all the items.

keys

def keys() -> Set[str]

Get the set of keys.