Skip to content

Host APIs

Installable host-side APIs for browser-like globals and V8 embedder features.

HostAPI

Base class for host-side APIs that can be installed into a BaseProfile.

Timer

Bases: HostAPI

Installs browser-style timer globals backed by the Rust host task queue.

__new__() -> Timer

Create a timer HostAPI that installs setTimeout, clearTimeout, setInterval, and clearInterval.

MicrotaskQueue

Bases: HostAPI

Installs queueMicrotask into the JavaScript global object.

__new__() -> MicrotaskQueue

Create a HostAPI that installs queueMicrotask.

ModuleLoader

Bases: HostAPI

Installs host-backed static and dynamic ECMAScript module resolution.

__new__(resolver: Mapping[str, str | Module] | Callable[[str, str | None, dict[str, str]], str | Module | None] | None = None, *, import_meta: Mapping[str, object] | Callable[[str], Mapping[str, object] | None] | None = None) -> ModuleLoader

Create a module loader from a mapping or resolver callback.

PromiseRejectionTracker

Bases: HostAPI

Installs V8 promise rejection tracking with an optional Python callback.

__new__(policy: Literal[ignore, warn] = 'warn', *, callback: Callable[[str, str | None], object] | None = None) -> PromiseRejectionTracker

Create a promise rejection tracker HostAPI.

Console

Bases: HostAPI

Installs console methods that forward to a Python Logger.

logger: Logger property

Return the Python logger used by installed console methods.

__new__(logger: Logger | None = None, *, name: str = 'console') -> Console

Create a console HostAPI backed by a Python logger.

DynamicCodePolicy

Bases: HostAPI

Controls whether dynamic JavaScript code generation is allowed.

allow_eval: bool property

Return whether eval and Function-style dynamic code generation are allowed.

__new__(allow_eval: bool = False) -> DynamicCodePolicy

Create a dynamic code policy HostAPI.

WebAssembly

Bases: HostAPI

Installs WebAssembly streaming helpers and configures Wasm code generation.

allow_code_generation: bool property

Return whether WebAssembly code generation is allowed.

cache: WasmModuleCache | None property

Return the optional compiled Wasm module cache.

loader: _WebAssemblyLoaderLike | None property

Return the Python streaming loader, if one was configured.

__new__(loader: _WebAssemblyLoaderLike | None = None, *, allow_code_generation: bool = True, cache: WasmModuleCache | None = None) -> WebAssembly

Create a WebAssembly HostAPI configuration.

SharedArrayBuffer

Bases: HostAPI

Enables SharedArrayBuffer construction in contexts that install this HostAPI.

__new__() -> SharedArrayBuffer

Create a HostAPI that installs the SharedArrayBuffer constructor.

Atomics

Bases: HostAPI

Configures V8 Atomics support, including whether blocking waits are allowed.

allow_wait: bool property

Return whether Atomics.wait is allowed to block.

__new__(allow_wait: bool = True) -> Atomics

Create an Atomics HostAPI configuration.

ShadowRealm

Bases: HostAPI

Enables V8's ShadowRealm support for contexts that install this HostAPI.

__new__() -> ShadowRealm

Create a HostAPI that enables and installs ShadowRealm support.

Inspector

Bases: HostAPI

Installs V8 Inspector support for a context.

aux_data: str | None property

Return auxiliary inspector context data.

context_group_id: int property

Return the inspector context group id.

name: str property

Return the inspector context name.

__new__(name: str = 'v8-python', *, context_group_id: int = 1, aux_data: str | None = None) -> Inspector

Create an Inspector HostAPI configuration.