polywrap_wasm.wasm_wrapper module

This module contains the WasmWrapper class for invoking Wasm wrappers.

class polywrap_wasm.wasm_wrapper.WasmWrapper(file_reader: FileReader, wasm_module: bytes, manifest: WrapManifest)[source]

Bases: Wrapper

WasmWrapper implements the Wrapper protocol for Wasm wrappers.

Parameters:
  • file_reader (FileReader) – The file reader used to read the wrapper files.

  • wasm_module (bytes) – The Wasm module file of the wrapper.

  • manifest (AnyWrapManifest) – The manifest of the wrapper.

create_wasm_instance(store: Store, state: State, client: Invoker | None) Instance[source]

Create a new Wasm instance for the wrapper.

Parameters:
  • store (Store) – The Wasm store to use when creating the instance.

  • state (State) – The Wasm wrapper state to use when creating the instance.

  • client (Optional[Invoker]) – The client to use when creating the instance.

Returns:

The Wasm instance of the wrapper Wasm module.

file_reader: FileReader
get_file(path: str, encoding: str | None = 'utf-8') str | bytes[source]

Get a file from the wrapper.

Parameters:
  • path (str) – The path of the file to get.

  • encoding (Optional[str]) – The encoding to use when reading the file.

Returns:

The file contents as string or bytes according to encoding or an error.

get_manifest() WrapManifest[source]

Get the manifest of the wrapper.

get_wasm_module() bytes[source]

Get the Wasm module of the wrapper.

invoke(uri: Uri, method: str, args: Dict[str, Any] | None = None, env: Dict[str, Any] | None = None, resolution_context: UriResolutionContext | None = None, client: Invoker | None = None) InvocableResult[source]

Invoke the wrapper.

Parameters:
  • uri (Uri) – The Wasm wrapper uri.

  • method (str) – The method to invoke.

  • args (Optional[Dict[str, Any]]) – The args to invoke with.

  • env (Optional[Dict[str, Any]]) – The env to use when invoking.

  • resolution_context (Optional[UriResolutionContext]) – The URI resolution context to use during invocation.

  • client (Optional[Invoker]) – The invoker to use during invocation.

Raises:
  • WrapError – If the invocation uri or method are not defined.

  • MsgpackError – If failed to encode/decode data to/from msgpack.

Returns:

The result of the invocation or an error.

manifest: WrapManifest
wasm_module: bytes