Skip to content

jsrun

The top-level package provides convenience functions that automatically manage a context-local Runtime instance for you. Each asyncio task or thread gets its own isolated runtime, created lazily and cleaned up automatically.

eval

eval(code: str) -> Any

Synchronously evaluate JavaScript using the default runtime.

eval_async async

eval_async(code: str, **kwargs: Any) -> Any

Evaluate JavaScript asynchronously using the default runtime.

bind_function

bind_function(name: str, handler: Callable[..., Any]) -> None

Expose a Python callable on globalThis.

bind_object

bind_object(name: str, obj: Mapping[str, Any]) -> None

Expose a Python mapping as a JavaScript object.

get_default_runtime

get_default_runtime() -> Runtime

Return a runtime tied to the current asyncio task or thread.

close_default_runtime

close_default_runtime() -> None

Close the current context-local runtime, if one exists.