Python
Python Runtime
The PythonRuntime allows you to run short-lived code on a Python virtual machine.
# my_typegraph.py
from typegraph import typegraph, Policy, t, Graph
from typegraph.runtimes.deno import PythonRuntime
@typegraph()
def example_python(g: Graph):
public = Policy.public()
python = PythonRuntime()
g.expose(
public,
add=t.func(
t.struct({"a": t.integer(), "b": t.integer()}),
t.integer(),
# we can provide the code inline using lambdas
python.from_lambda(lambda x: x["a"] + x["b"]),
),
sayHello=python.import_(
t.struct({"name": t.string()}),
t.string(),
# point to pythoin a file on disc
module="hello.py",
name="say_hello"
),
)
# hello.py
def say_hello(x: any):
return f"Hello {x["name"]}"