Metadata

class hugr.metadata.Metadata(*args, **kwargs)[source]

Bases: Protocol[Meta]

Metadata for a HUGR node.

This is a protocol for metadata entries that defines a unique key to identify the entry, and the type of the value.

Values in a hugr are encoded using json. When the value type is not a primitive type, to_json and from_json must be implemented to serialize and deserialize the value.

Parameters:

value – The value of the metadata.

Methods

from_json

Deserialize the metadata value from the stored json value.

to_json

Serialize the metadata value to a json value.

Attributes

KEY

classmethod from_json(value: str | int | float | bool | None | Mapping[str, JsonType] | list[JsonType]) Meta[source]

Deserialize the metadata value from the stored json value.

classmethod to_json(value: Meta) str | int | float | bool | None | Mapping[str, JsonType] | list[JsonType][source]

Serialize the metadata value to a json value.