Skip to content

Commit

Permalink
doc: update python-sdk use in README to v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdickinson committed Jan 28, 2024
1 parent eebc8f8 commit e75d2e3
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,40 +268,26 @@ We can't really test this from the Extism CLI as something must provide the impl
write out the Python side here. Check out the [docs for Host SDKs](https://extism.org/docs/concepts/host-sdk) to implement a host function in a language of your choice.

```python
from extism import host_fn, Function, ValType

@host_fn
def a_python_func(plugin, input_, output, _user_data):
# The plug-in is passing us a string
input_str = plugin.input_string(input_[0])
from extism import host_fn, Plugin

@host_fn()
def a_python_func(input: str) -> str:
# just printing this out to prove we're in Python land
print("Hello from Python!")

# let's just add "!" to the input string
# but you could imagine here we could add some
# applicaiton code like query or manipulate the database
# or our application APIs
input_str += "!"

# set the new string as the return value to the plug-in
plugin.return_string(output[0], input_str)
return input + "!"
```

Now when we load the plug-in we pass the host function:

```python
functions = [
Function(
"a_python_func",
[ValType.I64],
[ValType.I64],
a_python_func,
)
]

plugin = Plugin(manifest, functions=functions)
result = plugin.call('hello_from_python')
manifest = {"wasm": [{"path": "/path/to/plugin.wasm"}]}
plugin = Plugin(manifest, functions=[a_python_func], wasi=True)
result = plugin.call('hello_from_python', b'').decode('utf-8')
print(result)
```

Expand Down

0 comments on commit e75d2e3

Please sign in to comment.