Polywrap Wasm
Project description
This package contains the runtime for executing Wasm wrappers.
Quickstart
The following code snippet demonstrates how to use the runtime to execute a Wasm wrapper.
Imports
>>> import os >>> from typing import cast >>> from polywrap_core import Uri, FileReader, InvokerClient >>> from polywrap_wasm import WasmWrapper >>> from polywrap_msgpack import msgpack_decode >>> from polywrap_manifest import deserialize_wrap_manifest, AnyWrapManifest
Create a Wasm wrapper
>>> path_to_wrapper = os.path.join(os.path.dirname(__file__), "..", "tests", "cases", "simple") >>> assert os.path.exists(path_to_wrapper) >>> with open(os.path.join(path_to_wrapper, "wrap.wasm"), "rb") as f: ... wasm_module = f.read() >>> assert isinstance(wasm_module, bytes) >>> with open(os.path.join(path_to_wrapper, "wrap.info"), "rb") as f: ... manifest = deserialize_wrap_manifest(f.read()) >>> assert isinstance(manifest, AnyWrapManifest) >>> wrapper = WasmWrapper( ... cast(FileReader, NotImplemented), ... wasm_module, ... manifest ... ) >>> assert isinstance(wrapper, WasmWrapper)
Invocation
>>> message = "Hello, World!" >>> args = {"arg": message} >>> result = wrapper.invoke( ... uri=Uri.from_str("wrap://authority/path"), ... method="simpleMethod", ... args=args, ... client=cast(InvokerClient, NotImplemented), ... ) >>> assert result.encoded is True >>> assert msgpack_decode(cast(bytes, result.result)) == message
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
polywrap_wasm-0.1.0b8.tar.gz
(13.4 kB
view hashes)
Built Distribution
Close
Hashes for polywrap_wasm-0.1.0b8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dac8431308fc42c874b40d7fccf9a3df3519bea395e90b7329119185a1cc1037 |
|
MD5 | 22c4b769f6258f3cd997344fd0418f7a |
|
BLAKE2b-256 | 555907bd76510e2ac2e4a63f51ce52c1d4627b956a9db2d6626f3571e94f3ac6 |