Skip to content

hololinked.injection.MetadataFormats

Bases: Registry

A singleton registry of the metadata formats, or device description languages, a Thing can be described in.

All members are class attributes and settings are applied process-wide (python process).

A format is a bundle of five classes. Each class is a generator of the metadata from the component (which are 5 in number) - for the Thing, Property, Action, Event and a base format class for all of property, action and event since they share some metadata.

from hololinked import MetadataFormats

MetadataFormats.register(
    MetadataFormat(thing=MyThingModel, property=..., action=..., event=..., interaction=...),
    "my_format",
)

from hololinked.core import Thing

thing = Thing()
thing.get_thing_model(format="my_format")  # generated by MyThingModel

Source code in repo/hololinked/hololinked/injection.py
class MetadataFormats(Registry):
    """
    A singleton registry of the metadata formats, or device description languages, a `Thing` can be described in.

    All members are class attributes and settings are applied process-wide (python process).

    A format is a bundle of five classes. Each class is a generator of the metadata from the component (which
    are 5 in number) - for the `Thing`, `Property`, `Action`, `Event` and a base format class for
    all of property, action and event since they share some metadata.
    ```python
    from hololinked import MetadataFormats

    MetadataFormats.register(
        MetadataFormat(thing=MyThingModel, property=..., action=..., event=..., interaction=...),
        "my_format",
    )

    from hololinked.core import Thing

    thing = Thing()
    thing.get_thing_model(format="my_format")  # generated by MyThingModel
    ```
    """

    adapter_kind: ClassVar[str] = "metadata format"
    package: ClassVar[str] = "hololinked.metadata"
    tables: ClassVar[tuple[str, ...]] = ("modules",)

    modules: ClassVar[dict[str, str | tuple[str, str]]] = {
        "wot": "WoTMetadata",
    }

    wot: MetadataFormat
    """The metadata classes of the W3C Web of Things Thing Description and Thing Model."""

    @classmethod
    def register(cls, metadata_format: MetadataFormat, name: str) -> None:
        """
        Register a bundle of metadata classes under a given name, overriding any format already using that name.

        Parameters
        ----------
        metadata_format: MetadataFormat
            the metadata classes of the format, one for the `Thing` itself and one per interaction affordance
        name: str
            the name to register the format under, for example 'wot'

        Raises
        ------
        TypeError
            if the bundle is not a `MetadataFormat`
        """
        if not isinstance(metadata_format, MetadataFormat):
            raise TypeError(f"metadata_format must be a MetadataFormat, given : {metadata_format}")
        cls.install(name, metadata_format)

    @classmethod
    def get(cls, format: str) -> MetadataFormat:
        """
        Get the MetadataFormat for a given format.

        Returns
        -------
        MetadataFormat
            The metadata classes for the given format, containing the thing, property, action and event classes.
        """
        return getattr(cls, format.lower())

    @classmethod
    def reset(cls) -> None:
        """Reset the metadata format registry."""
        cls.forget_adapters()

Attributes

wot instance-attribute

wot: MetadataFormat

The metadata classes of the W3C Web of Things Thing Description and Thing Model.

modules class-attribute

modules: dict[str, str | tuple[str, str]] = {'wot': 'WoTMetadata'}

Functions

get classmethod

get(format: str) -> MetadataFormat

Get the MetadataFormat for a given format.

Returns:

Type Description
MetadataFormat

The metadata classes for the given format, containing the thing, property, action and event classes.

Source code in repo/hololinked/hololinked/injection.py
@classmethod
def get(cls, format: str) -> MetadataFormat:
    """
    Get the MetadataFormat for a given format.

    Returns
    -------
    MetadataFormat
        The metadata classes for the given format, containing the thing, property, action and event classes.
    """
    return getattr(cls, format.lower())

register classmethod

register(metadata_format: MetadataFormat, name: str) -> None

Register a bundle of metadata classes under a given name, overriding any format already using that name.

Parameters:

Name Type Description Default

metadata_format

MetadataFormat

the metadata classes of the format, one for the Thing itself and one per interaction affordance

required

name

str

the name to register the format under, for example 'wot'

required

Raises:

Type Description
TypeError

if the bundle is not a MetadataFormat

Source code in repo/hololinked/hololinked/injection.py
@classmethod
def register(cls, metadata_format: MetadataFormat, name: str) -> None:
    """
    Register a bundle of metadata classes under a given name, overriding any format already using that name.

    Parameters
    ----------
    metadata_format: MetadataFormat
        the metadata classes of the format, one for the `Thing` itself and one per interaction affordance
    name: str
        the name to register the format under, for example 'wot'

    Raises
    ------
    TypeError
        if the bundle is not a `MetadataFormat`
    """
    if not isinstance(metadata_format, MetadataFormat):
        raise TypeError(f"metadata_format must be a MetadataFormat, given : {metadata_format}")
    cls.install(name, metadata_format)

reset classmethod

reset() -> None

Reset the metadata format registry.

Source code in repo/hololinked/hololinked/injection.py
@classmethod
def reset(cls) -> None:
    """Reset the metadata format registry."""
    cls.forget_adapters()