Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import pathlib

sys.path.append(".")
from extism import Function, host_fn, ValType, Plugin, set_log_file
from extism import Function, host_fn, ValType, Plugin, set_log_file, Json
from typing import Annotated

set_log_file("stderr", "trace")


@host_fn
def hello_world(plugin, input_, output, a_string):
@host_fn(user_data=b"Hello again!")
def hello_world(inp: Annotated[dict, Json], *a_string) -> Annotated[dict, Json]:
print("Hello from Python!")
print(a_string)
print(input_)
print(plugin.input_string(input_[0]))
output[0] = input_[0]
inp["roundtrip"] = 1
return inp


# Compare against Python implementation.
Expand All @@ -36,16 +36,7 @@ def main(args):
hash = hashlib.sha256(wasm).hexdigest()
manifest = {"wasm": [{"data": wasm, "hash": hash}]}

functions = [
Function(
"hello_world",
[ValType.I64],
[ValType.I64],
hello_world,
"Hello again!",
)
]
plugin = Plugin(manifest, wasi=True, functions=functions)
plugin = Plugin(manifest, wasi=True)
print(plugin.id)
# Call `count_vowels`
wasm_vowel_count = plugin.call("count_vowels", data)
Expand All @@ -55,6 +46,7 @@ def main(args):
print("Number of vowels:", j["count"])

assert j["count"] == count_vowels(data)
assert j["roundtrip"] == 1


if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions extism/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
ValType,
Val,
CurrentPlugin,
Codec,
Json,
Pickle,
)

__all__ = [
Expand All @@ -28,4 +31,7 @@
"Function",
"ValType",
"Val",
"Codec",
"Json",
"Pickle",
]
Loading