Skip to content

plugin_fn function parameters api #29

@fliepeltje

Description

@fliepeltje

This is more of a discussion/question topic, but I was wondering how difficult/desireable it would be to leverage python function params/annotations in the plugin_fn decorator.

The most straightforward application would be to get rid of the extism.input(...) calls for me, so instead of:

@plugin_fn
def do_it():
  data = extism.input(SomeClass)

You would do something like:

@plugin_fn
def do_it(data: SomeClass):
  ...

Extending that further I could imagine accessing things like config (and other APIs like filesystem operations or host functions):

@plugin_fn
def do_multiple_inputs(input_a: A, input_b: B): 
  ...

@plugin_fn
def do_http_stuff(http: extism.Http, ...): 
  ...

@plugin_fn
def do_with_config(input_a: A, input_b: B, config: extism.Config): 
  ...

@plugin_fn
def do_it(input_a: A, input_b: B, config: extism.Config, http: extism.Http, ...): 
  ...

I'd feel pretty confident implementing something like that in python, but I am not so familiar with pyo3 and how to formulate this in Rust, so I don't know if it is just a massive effort. I think the thing that I'd like to emulate is what axum achieves with extractors: https://docs.rs/axum/latest/axum/index.html#extractors

Ofcourse I understand if there are good reasons for the current API, but I think if you were to say that this is somewhat doable and maybe point me in the right direction, I could explore the API in a fork and we can see how it feels

Looking around I feel I could get quite a way towards making a proof of concept by just messing around in the prelude.py - I just don't know too well how to actually build/test this project. I am able to run ./build.py but I'm unsure what to do next to actually use the compiled library in a test project. From what I can tell there is some import from extism_sys in the sdk that probably (?) is what I want to somehow patch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions