extism / python-pdk

Write Extism plugins in Python
https://extism.org
BSD 3-Clause "New" or "Revised" License
14 stars 4 forks source link

Docs around using `import_fn` and`host_fn` #26

Closed fliepeltje closed 3 days ago

fliepeltje commented 4 days ago

As I understand it, you use import_fn to defer some operation from a plugin to the host by means of defining a host_fn, but I cannot seem to get this to work - I'd love to experiment a bit more with this and I'd really appreciate some docs or an example that combines the use of import_fn and host_fn - the way I imagine this to work:

plugin code:

import extism

@extism.import_fn("app", "some_host_op")
def some_host_op(): ...

@extism.plugin_fn
def some_fn():
    some_host_op()

app code:

import extism

@extism.host_fn
def some_host_op():
    print("...")

manifest = ...
with extism.Plugin(manifest, wasi=True) as plugin:
    plugin.call("some_fn", "")
zshipko commented 4 days ago

Thanks, decorator usage could definitely be documented better.

It looks like your example above would work if you switch import_fn to import_fn("extism:host/user","some_host_op") instead.