Skip to content

Commit 6e7ff40

Browse files
doc: update python-sdk example in README to v1.0.0 api (#29)
1 parent d48f368 commit 6e7ff40

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

README.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -281,42 +281,26 @@ We can't really test this from the Extism CLI as something must provide the impl
281281
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.
282282

283283
```python
284-
from extism import host_fn, Function, ValType, Plugin
285-
286-
@host_fn
287-
def a_python_func(plugin, input_, output, _user_data):
288-
# The plug-in is passing us a string
289-
input_str = plugin.input_string(input_[0])
284+
from extism import host_fn, Plugin
290285

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

294291
# let's just add "!" to the input string
295292
# but you could imagine here we could add some
296293
# applicaiton code like query or manipulate the database
297294
# or our application APIs
298-
input_str += "!"
299-
300-
# set the new string as the return value to the plug-in
301-
plugin.return_string(output[0], input_str)
295+
return input + "!"
302296
```
303297

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

306300
```python
307-
functions = [
308-
Function(
309-
"a_python_func",
310-
[ValType.I64],
311-
[ValType.I64],
312-
a_python_func,
313-
None
314-
)
315-
]
316-
317301
manifest = {"wasm": [{"path": "/path/to/plugin.wasm"}]}
318-
plugin = Plugin(manifest, functions=functions, wasi=True)
319-
result = plugin.call('hello_from_python').decode('utf-8')
302+
plugin = Plugin(manifest, functions=[a_python_func], wasi=True)
303+
result = plugin.call('hello_from_python', b'').decode('utf-8')
320304
print(result)
321305
```
322306

0 commit comments

Comments
 (0)