Package#

class hugr.package.Package(modules: list[Hugr], extensions: list[Extension] = <factory>)[source]#

Bases: object

A package of HUGR modules and extensions.

The HUGRs may refer to the included extensions or those not included.

Methods

from_bytes

Deserialize a byte string to a Package object.

from_json

Deserialize a JSON string to a Package object.

from_str

Deserialize a string to a Package object.

to_bytes

Serialize the package to a HUGR envelope byte string.

to_json

Serialize the package to a printable HUGR envelope string.

to_model

Export the package as its hugr model representation.

to_str

Serialize the package to a HUGR envelope string.

Attributes

modules

HUGR modules in the package.

extensions

Extensions included in the package.

extensions: list[Extension]#

Extensions included in the package.

static from_bytes(envelope: bytes) Package[source]#

Deserialize a byte string to a Package object.

Some envelope formats can be read from a string. See from_str().

Parameters:

envelope – The byte string representing a Package.

Returns:

The deserialized Package object.

classmethod from_json(json_str: str) Package[source]#

Deserialize a JSON string to a Package object.

Parameters:

json_str – The JSON string representing a Package.

Returns:

The deserialized Package object.

static from_str(envelope: str) Package[source]#

Deserialize a string to a Package object.

Not all envelope formats can be read from a string. See from_bytes() for a more general method.

Parameters:

envelope – The string representing a Package.

Returns:

The deserialized Package object.

modules: list[Hugr]#

HUGR modules in the package.

to_bytes(config: EnvelopeConfig | None = None) bytes[source]#

Serialize the package to a HUGR envelope byte string.

Some envelope formats can be encoded into a string. See to_str().

to_json() str[source]#

Serialize the package to a printable HUGR envelope string.

to_model() Package[source]#

Export the package as its hugr model representation.

At the moment this does not yet contain the extensions.

to_str(config: EnvelopeConfig | None = None) str[source]#

Serialize the package to a HUGR envelope string.

Not all envelope formats can be encoded into a string. See to_bytes() for a more general method.