Types
Useful Python types used in pydeno.
Bases: Exception
Raised when JavaScript code running in the runtime throws an exception.
The runtime surfaces JavaScript exceptions as JavaScriptError instances
that preserve structured metadata from V8, giving callers access to the
original error class, message, stack trace, and individual frames.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
JavaScript error class name (e.g. |
message |
str | None
|
Error message string when available. |
stack |
str | None
|
V8 formatted stack trace string if provided. |
frames |
list[JsFrame]
|
Parsed stack frames populated with optional |
Example
Bases: RuntimeTerminated
Raised when a runtime never acknowledged a termination and was abandoned.
Only possible when RuntimeConfig.force_kill_grace is set. Unlike
RuntimeTerminated -- which means the isolate acknowledged the kill and
shut down cleanly -- this means it never did: the runtime thread has been
given up on rather than reclaimed, so the Runtime that raised this is
permanently unusable and a replacement must be created. Bound host
functions, module state and globals do not carry over.
Subclasses RuntimeTerminated, so existing handlers keep working.
Bases: RuntimeError
Raised when an operation exceeded its timeout.
Subclasses RuntimeError, which is what every timeout raised through
0.4.0 was, so except RuntimeError keeps catching it. Before this type
existed the only way to tell a timeout from an internal failure was to
match "timed out" in the message.
Named RuntimeTimeout rather than TimeoutError because Python's
builtin of that name derives from OSError, not RuntimeError.
Added in 0.4.1.
Proxy for a JavaScript function returned from the runtime.
Instances execute on the underlying V8 isolate. Calling the proxy returns either a direct value (for synchronous JavaScript functions) or an awaitable object when the JavaScript side returns a pending Promise.
__call__
__call__(*args: Any, timeout: float | int | timedelta | None = ...) -> Any | Coroutine[Any, Any, Any]
Invoke the JavaScript function with the provided arguments. If the JS function finishes synchronously, its return value is produced directly. Otherwise, the result is a coroutine and must be awaited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Arguments forwarded into JavaScript |
()
|
timeout
|
float | int | timedelta | None
|
Optional timeout (seconds as float/int, or datetime.timedelta) |
...
|
Returns:
| Type | Description |
|---|---|
Any | Coroutine[Any, Any, Any]
|
Either the JavaScript return value or a coroutine resolving to it. |
call_async
Always invoke the JavaScript function asynchronously, returning a coroutine regardless of whether the underlying JS completes synchronously.
The work starts on the runtime thread as soon as this is called, not on
first await. The return type is a coroutine rather than an
asyncio.Future so that asyncio.create_task accepts it -- running two
JS calls concurrently is the main reason to reach for this method, and
create_task on a bare Future raises
TypeError: a coroutine was expected. Changed in 0.3.0.
Async iterator proxy for a JavaScript ReadableStream returned from the runtime.
__anext__
Await and return the next chunk yielded by the underlying JS stream.
Raises:
| Type | Description |
|---|---|
StopAsyncIteration
|
When the stream finishes. |
JavaScriptError
|
If the stream reader errors. |
Structured snapshot of runtime resource usage and execution counters.
Instances are returned from Runtime.get_stats() and provide
read-only insight into the V8 heap, total execution time, and active
resources currently managed by the runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
heap_total_bytes |
int
|
Total heap size in bytes allocated by V8 |
heap_used_bytes |
int
|
Currently used heap memory in bytes |
external_memory_bytes |
int
|
External memory tracked by V8 (e.g., ArrayBuffers) |
physical_total_bytes |
int
|
Physical memory in bytes (RSS) |
total_execution_time_ms |
int
|
Cumulative execution time in milliseconds |
last_execution_time_ms |
int
|
Duration of the most recent execution in milliseconds |
last_execution_kind |
str | None
|
Type of last operation (e.g., "eval_async", "call_function_sync") |
eval_sync_count |
int
|
Number of synchronous eval operations |
eval_async_count |
int
|
Number of asynchronous eval operations |
eval_module_sync_count |
int
|
Number of synchronous module evaluations |
eval_module_async_count |
int
|
Number of asynchronous module evaluations |
call_function_async_count |
int
|
Number of asynchronous function calls |
call_function_sync_count |
int
|
Number of synchronous function calls |
active_async_ops |
int
|
Currently active async operations |
open_resources |
int
|
Number of open resources (timers, streams, etc.) |
active_timers |
int
|
Active setTimeout timers |
active_intervals |
int
|
Active setInterval timers |
active_js_streams |
int
|
Active JavaScript ReadableStreams exposed to Python |
active_py_streams |
int
|
Active Python async iterables exposed to JavaScript |
total_js_streams |
int
|
Total JavaScript streams created |
total_py_streams |
int
|
Total Python streams created |
bytes_streamed_js_to_py |
int
|
Total bytes transferred from JavaScript to Python |
bytes_streamed_py_to_js |
int
|
Total bytes transferred from Python to JavaScript |
external_memory_bytes
property
External memory tracked by V8 (e.g., ArrayBuffers).
total_execution_time_ms
property
Cumulative execution time in milliseconds.
last_execution_time_ms
property
Duration of the most recent execution in milliseconds.
last_execution_kind
property
Type of last operation (e.g., "eval_async", "call_function_sync").
eval_module_sync_count
property
Number of synchronous module evaluations.
eval_module_async_count
property
Number of asynchronous module evaluations.
call_function_async_count
property
Number of asynchronous function calls.
call_function_sync_count
property
Number of synchronous function calls.
active_js_streams
property
Active JavaScript ReadableStreams exposed to Python.
active_py_streams
property
Active Python async iterables exposed to JavaScript.
bytes_streamed_js_to_py
property
Total bytes transferred from JavaScript to Python.
Configuration for enabling the Chrome DevTools inspector.
__init__
__init__(host: str = '127.0.0.1', port: int = 9229, *, wait_for_connection: bool = False, break_on_next_statement: bool = False, target_url: str | None = None, display_name: str | None = None) -> None
Create a new inspector configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Host interface to bind (defaults to |
'127.0.0.1'
|
port
|
int
|
TCP port for the DevTools server |
9229
|
wait_for_connection
|
bool
|
Block execution until a debugger connects |
False
|
break_on_next_statement
|
bool
|
Pause on the first statement after a debugger attaches |
False
|
target_url
|
str | None
|
Optional string reported to DevTools for the inspected target |
None
|
display_name
|
str | None
|
Optional display title surfaced in |
None
|
Runtime inspector metadata exposing DevTools URLs.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the inspector session |
websocket_url |
str
|
WebSocket URL for the Chrome DevTools Protocol |
devtools_frontend_url |
str
|
DevTools frontend URL to open in Chrome |
title |
str
|
Display title for the inspector target |
description |
str
|
Description of the inspector target |
target_url |
str
|
URL of the target being inspected |
favicon_url |
str
|
Favicon URL for the inspector target |
host |
str
|
Host address where the inspector is listening |
Build a V8 snapshot covering a custom bootstrap script.
Use execute_script() to run multiple scripts before calling
build() to produce the serialized bytes.
Snapshot scripts are not sandboxed
A snapshot is built in a plain deno_core isolate that pydeno's
guest bridge has not been installed into. Code passed to
bootstrap= or execute_script()
therefore runs with Deno.core.ops fully reachable -- the raw,
unmetered, untimed op table, which includes direct writes to the
host process's stdout/stderr. There is also no timeout and no
serialization limit applied while the snapshot is being built.
Snapshot input is host code, at the same trust level as the Python that calls this. Never feed it JavaScript from an untrusted source.
The snapshot contents are safe to hand to
Runtime: the bridge deletes Deno, __bootstrap
and __infra when a runtime starts from a snapshot, exactly as it
does for a fresh one (pinned by tests/test_guest_globals.py).
__init__
Create a snapshot builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bootstrap
|
str | None
|
Optional JavaScript source run before any scripts added via |
None
|
enable_console
|
bool | None
|
Whether |
False
|
execute_script
Run a JavaScript script inside the snapshot builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identifier used in stack traces / debugging. |
required |
source
|
str
|
Source text to compile and execute. The code is executed as a
classic script (not an ES module), so |
required |