pyodide.ffi
pyodide.ffi#
Exceptions:
An error thrown when conversion between JavaScript and Python fails. |
|
A wrapper around a JavaScript Error to allow it to be thrown in Python. |
Classes:
|
A JsProxy of an array, node list, or typed array |
A JavaScript async generator |
|
A JavaScript async iterable object |
|
|
A JsProxy of an array buffer or array buffer view |
A double proxy created with |
|
A JavaScript generator |
|
A JavaScript iterable object |
|
A JsProxy of a JavaScript iterator. |
|
|
A JavaScript Map |
A JavaScript mutable map |
|
A JsProxy of a promise (or some other awaitable JavaScript object). |
|
|
A proxy to make a JavaScript object behave like a Python object |
Functions:
|
Wrap a Python callable in a JavaScript function that can be called once. |
|
Create a |
|
Destroy all PyProxies in a JavaScript array. |
|
Registers |
|
Convert the object to JavaScript. |
|
Unregisters a JavaScript module with given name that has been previously registered with |
- exception pyodide.ffi.ConversionError#
Bases:
Exception
An error thrown when conversion between JavaScript and Python fails.
- class pyodide.ffi.JsArray#
Bases:
pyodide.ffi.JsProxy
,Generic
[T
]A JsProxy of an array, node list, or typed array
- append(object: .T) None #
Append object to the end of the list.
- count(x: .T) int #
Return the number of times x appears in the list.
- extend(other: collections.abc.Iterable[.T]) None #
Extend array by appending elements from the iterable.
- index(value: .T, start: int = 0, stop: int = 9223372036854775807) int #
Return first index of value.
Raises ValueError if the value is not present.
- pop(index: int = - 1) T #
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- reverse() None #
Reverse the array in place.
Present only if the wrapped Javascript object is an array.
- to_py(*, depth: int = - 1, default_converter: Optional[collections.abc.Callable[[JsProxy, collections.abc.Callable[[JsProxy], Any], collections.abc.Callable[[JsProxy, Any], None]], Any]] = None) list[Any] #
Convert the
JsProxy
to a native Python object as best as possible.By default, does a deep conversion, if a shallow conversion is desired, you can use
proxy.to_py(depth=1)
. See JavaScript to Python for more information.default_converter
if present will be invoked whenever Pyodide does not have some built in conversion for the object. Ifdefault_converter
raises an error, the error will be allowed to propagate. Otherwise, the object returned will be used as the conversion.default_converter
takes three arguments. The first argument is the value to be converted.Here are a couple examples of converter functions. In addition to the normal conversions, convert
Date
todatetime
:from datetime import datetime def default_converter(value, _ignored1, _ignored2): if value.constructor.name == "Date": return datetime.fromtimestamp(d.valueOf()/1000) return value
Don’t create any JsProxies, require a complete conversion or raise an error:
def default_converter(_value, _ignored1, _ignored2): raise Exception("Failed to completely convert object")
The second and third arguments are only needed for converting containers. The second argument is a conversion function which is used to convert the elements of the container with the same settings. The third argument is a “cache” function which is needed to handle self referential containers. Consider the following example. Suppose we have a Javascript
Pair
class:class Pair { constructor(first, second){ this.first = first; this.second = second; } }
We can use the following
default_converter
to convertPair
tolist
:def default_converter(value, convert, cache): if value.constructor.name != "Pair": return value result = [] cache(value, result); result.append(convert(value.first)) result.append(convert(value.second)) return result
Note that we have to cache the conversion of
value
before convertingvalue.first
andvalue.second
. To see why, consider a self referential pair:let p = new Pair(0, 0); p.first = p;
Without
cache(value, result);
, convertingp
would lead to an infinite recurse. With it, we can successfully convertp
to a list such thatl[0] is l
.
- class pyodide.ffi.JsAsyncGenerator#
Bases:
pyodide.ffi.JsAsyncIterable
[Tco
],Generic
[Tco
,Tcontra
,Vco
]A JavaScript async generator
A JavaScript object is treated as an async generator if it’s
Symbol.typeTag
isAsyncGenerator
. Most likely this will be because it is a true async generator produced by the JavaScript runtime, but it may be a custom object trying hard to pretend to be an async generator. It should havenext
,return
, andthrow
methods.- aclose() Awaitable[None] #
Raises a GeneratorExit at the point where the generator function was paused.
If the generator function then exits gracefully, is already closed, or raises GeneratorExit (by not catching the exception), close returns to its caller. If the generator yields a value, a RuntimeError is raised. If the generator raises any other exception, it is propagated to the caller. close() does nothing if the generator has already exited due to an exception or normal exit.
- asend(value: .Tcontra) Awaitable[.Tco] #
Resumes the execution and “sends” a value into the async generator function.
The
value
argument becomes the result of the current yield expression. The awaitable returned by the asend() method will return the next value yielded by the generator or raisesStopAsyncIteration
if the asynchronous generator returns. If the generator returned a value, this value is discarded (because in Python async generators cannot return a value).When
asend()
is called to start the generator, the argument will be ignored. Unlike in Python, we cannot detect that the generator hasn’t started yet, and no error will be thrown if the argument of a not-started generator is notNone
.
- athrow(type, value, traceback)#
Resumes the execution and raises an exception at the point where the generator was paused.
The awaitable returned by the asend() method will return the next value yielded by the generator or raises
StopAsyncIteration
if the asynchronous generator returns. If the generator returned a value, this value is discarded (because in Python async generators cannot return a value). If the generator function does not catch the passed-in exception, or raises a different exception, then that exception propagates to the caller.
- class pyodide.ffi.JsAsyncIterable#
Bases:
pyodide.ffi.JsProxy
,Generic
[Tco
]A JavaScript async iterable object
A JavaScript object is async iterable if it has a
Symbol.asyncIterator
method.
- class pyodide.ffi.JsBuffer#
Bases:
pyodide.ffi.JsProxy
A JsProxy of an array buffer or array buffer view
- assign(rhs: Any, /) None #
Assign from a Python buffer into the JavaScript buffer.
- assign_to(to: Any, /) None #
Assign to a Python buffer from the JavaScript buffer.
- from_file(file: Union[IO[bytes], IO[str]], /) None #
Reads from a file into a buffer.
Will try to read a chunk of data the same size as the buffer from the current position of the file.
Example
>>> import pytest; pytest.skip() >>> from js import Uint8Array >>> # the JsProxy need to be pre-allocated >>> x = Uint8Array.new(range(10)) >>> with open('file.bin', 'rb') as fh: ... x.read_file(fh) which is equivalent to >>> x = Uint8Array.new(range(10)) >>> with open('file.bin', 'rb') as fh: ... chunk = fh.read(size=x.byteLength) ... x.assign(chunk) but the latter copies the data twice whereas the former only copies the data once.
- to_bytes() bytes #
Convert a buffer to a bytes object.
Copies the data once.
- to_file(file: Union[IO[bytes], IO[str]], /) None #
Writes a buffer to a file.
Will write the entire contents of the buffer to the current position of the file.
Example
>>> import pytest; pytest.skip() >>> from js import Uint8Array >>> x = Uint8Array.new(range(10)) >>> with open('file.bin', 'wb') as fh: ... x.to_file(fh) which is equivalent to, >>> with open('file.bin', 'wb') as fh: ... data = x.to_bytes() ... fh.write(data) but the latter copies the data twice whereas the former only copies the data once.
- to_memoryview() memoryview #
Convert a buffer to a memoryview.
Copies the data once. This currently has the same effect as
to_py
.
- to_string(encoding: Optional[str] = None) str #
Convert a buffer to a string object.
Copies the data twice.
The encoding argument will be passed to the Javascript [
TextDecoder
](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder) constructor. It should be one of the encodings listed in the table here: https://encoding.spec.whatwg.org/#names-and-labels. The default encoding is utf8.
- class pyodide.ffi.JsDoubleProxy#
Bases:
pyodide.ffi.JsProxy
A double proxy created with
create_proxy
.- unwrap() Any #
Unwrap a double proxy created with
create_proxy
into the wrapped Python object.
- exception pyodide.ffi.JsException#
Bases:
Exception
A wrapper around a JavaScript Error to allow it to be thrown in Python. See Errors.
- property js_error: pyodide.ffi.JsRawException#
The original JavaScript error
- class pyodide.ffi.JsFetchResponse#
Bases:
pyodide.ffi.JsProxy
- class pyodide.ffi.JsGenerator#
Bases:
pyodide.ffi.JsIterable
[Tco
],Generic
[Tco
,Tcontra
,Vco
]A JavaScript generator
A JavaScript object is treated as a generator if it’s
Symbol.typeTag
isGenerator
. Most likely this will be because it is a true generator produced by the JavaScript runtime, but it may be a custom object trying hard to pretend to be a generator. It should havenext
,return
, andthrow
methods.- close() None #
Raises a GeneratorExit at the point where the generator function was paused.
If the generator function then exits gracefully, is already closed, or raises GeneratorExit (by not catching the exception), close returns to its caller. If the generator yields a value, a RuntimeError is raised. If the generator raises any other exception, it is propagated to the caller. close() does nothing if the generator has already exited due to an exception or normal exit.
- send(value: .Tcontra) Tco #
Resumes the execution and “sends” a value into the generator function.
The
value
argument becomes the result of the current yield expression. Thesend()
method returns the next value yielded by the generator, or raisesStopIteration
if the generator exits without yielding another value. Whensend()
is called to start the generator, the argument will be ignored. Unlike in Python, we cannot detect that the generator hasn’t started yet, and no error will be thrown if the argument of a not-started generator is notNone
.
- throw(type, value, traceback)#
Raises an exception at the point where the generator was paused, and returns the next value yielded by the generator function.
If the generator exits without yielding another value, a StopIteration exception is raised. If the generator function does not catch the passed-in exception, or raises a different exception, then that exception propagates to the caller.
In typical use, this is called with a single exception instance similar to the way the raise keyword is used.
For backwards compatibility, however, the second signature is supported, following a convention from older versions of Python. The type argument should be an exception class, and value should be an exception instance. If the value is not provided, the type constructor is called to get an instance. If traceback is provided, it is set on the exception, otherwise any existing __traceback__ attribute stored in value may be cleared.
- class pyodide.ffi.JsIterable#
Bases:
pyodide.ffi.JsProxy
,Generic
[Tco
]A JavaScript iterable object
A JavaScript object is iterable if it has a
Symbol.iterator
method.
- class pyodide.ffi.JsIterator#
Bases:
pyodide.ffi.JsProxy
,Generic
[Tco
]A JsProxy of a JavaScript iterator.
An object is a JsIterator if it has a next method and either has a Symbol.iterator or has no Symbol.asyncIterator.
- class pyodide.ffi.JsMap#
Bases:
pyodide.ffi.JsProxy
,Generic
[KT
,VTco
]A JavaScript Map
To be considered a map, a JavaScript object must have a
.get
method, it must have a.size
or a.length
property which is a number (idiomatically it should be called.size
) and it must be iterable.- get(key, default=None)#
If key in self, returns self[key]. Otherwise returns default.
Present if the wrapped JavaScript object is a Mapping (i.e., has
get
,has
,size
, andkeys
methods).
- items() collections.abc.ItemsView[.KT, .VTco] #
Return a ItemsView for the map.
Present if the wrapped JavaScript object is a Mapping (i.e., has
get
,has
,size
, andkeys
methods).
- keys() collections.abc.KeysView[.KT] #
Return a KeysView for the map.
Present if the wrapped JavaScript object is a Mapping (i.e., has
get
,has
,size
, andkeys
methods).
- values() collections.abc.ValuesView[.VTco] #
Return a ValuesView for the map.
Present if the wrapped JavaScript object is a Mapping (i.e., has
get
,has
,size
, andkeys
methods).
- class pyodide.ffi.JsMutableMap#
Bases:
pyodide.ffi.JsMap
[KT
,VT
],Generic
[KT
,VT
]A JavaScript mutable map
To be considered a mutable map, a JavaScript object must have a
.get
method, a.has
method, a.size
or a.length
property which is a number (idiomatically it should be called.size
) and it must be iterable.Instances of the JavaScript builtin
Map
class areJsMutableMap
s. Also proxies returned byJsProxy.as_object_map
are instances ofJsMap
.- clear() None #
Empty out the map entirely.
Present if the wrapped JavaScript object is a MutableMapping (i.e., has
get
,has
,size
,keys
,set
, anddelete
methods).
- pop(key, default=None)#
If key in self, return self[key] and remove key from self. Otherwise returns default.
Present if the wrapped JavaScript object is a MutableMapping (i.e., has
get
,has
,size
,keys
,set
, anddelete
methods).
- popitem() tuple[KT, KT] #
Remove some arbitrary key, value pair from the map and returns the (key, value) tuple.
Present if the wrapped JavaScript object is a MutableMapping (i.e., has
get
,has
,size
,keys
,set
, anddelete
methods).
- setdefault(key: .KT, default: typing.Optional[.VT] = None) VT #
If key in self, return self[key]. Otherwise sets self[key] = default and returns default.
Present if the wrapped JavaScript object is a MutableMapping (i.e., has
get
,has
,size
,keys
,set
, anddelete
methods).
- update(other, **kwargs)#
Updates self from other and kwargs.
If
other
is present and is a Mapping or has akeys
method, doesfor k in other: self[k] = other[k]
If
other
is present and lacks akeys
method, doesfor (k, v) in other: self[k] = v
In all cases this is followed by:
for (k, v) in kwargs.items(): self[k] = v
Present if the wrapped JavaScript object is a MutableMapping (i.e., has
get
,has
,size
,keys
,set
, anddelete
methods).
- class pyodide.ffi.JsPromise#
Bases:
pyodide.ffi.JsProxy
A JsProxy of a promise (or some other awaitable JavaScript object).
A JavaScript object is considered to be a Promise if it has a “then” method.
- catch(onrejected: collections.abc.Callable[[Any], Any], /) pyodide.ffi.JsPromise #
The
Promise.catch
API, wrapped to manage the lifetimes of the handler.Pyodide will automatically release the references to the handler when the promise resolves.
- finally_(onfinally: collections.abc.Callable[[Any], Any], /) pyodide.ffi.JsPromise #
The
Promise.finally
API, wrapped to manage the lifetimes of the handler.Pyodide will automatically release the references to the handler when the promise resolves. Note the trailing underscore in the name; this is needed because
finally
is a reserved keyword in Python.
- then(onfulfilled: collections.abc.Callable[[Any], Any], onrejected: collections.abc.Callable[[Any], Any]) pyodide.ffi.JsPromise #
The
Promise.then
API, wrapped to manage the lifetimes of the handlers.Pyodide will automatically release the references to the handlers when the promise resolves.
- class pyodide.ffi.JsProxy#
Bases:
object
A proxy to make a JavaScript object behave like a Python object
For more information see the Type translations documentation. In particular, see the list of __dunder__ methods that are (conditionally) implemented on
JsProxy
.- as_object_map() pyodide.ffi.JsMutableMap[str, Any] #
Returns a new JsProxy that treats the object as a map.
The methods
__getitem__
,__setitem__
,__contains__
,__len__
, etc will perform lookups viaobject[key]
or similar.Note that
len(x.as_object_map())
evaluates in O(n) time (it iterates over the object and counts how many ownKeys it has). If you need to compute the length in O(1) time, use a realMap
instead.
- property js_id: int#
An id number which can be used as a dictionary/set key if you want to key on JavaScript object identity.
If two JsProxy are made with the same backing JavaScript object, they will have the same js_id. The reault is a “pseudorandom” 32 bit integer.
- new(*args: Any, **kwargs: Any) pyodide.ffi.JsProxy #
Construct a new instance of the JavaScript object
- object_entries() pyodide.ffi.JsProxy #
The JavaScript API
Object.entries(object)
- object_keys() pyodide.ffi.JsProxy #
The JavaScript API
Object.keys(object)
- object_values() pyodide.ffi.JsProxy #
The JavaScript API
Object.values(object)
- to_py(*, depth: int = - 1, default_converter: Optional[collections.abc.Callable[[JsProxy, collections.abc.Callable[[JsProxy], Any], collections.abc.Callable[[JsProxy, Any], None]], Any]] = None) Any #
Convert the
JsProxy
to a native Python object as best as possible.By default, does a deep conversion, if a shallow conversion is desired, you can use
proxy.to_py(depth=1)
. See JavaScript to Python for more information.default_converter
if present will be invoked whenever Pyodide does not have some built in conversion for the object. Ifdefault_converter
raises an error, the error will be allowed to propagate. Otherwise, the object returned will be used as the conversion.default_converter
takes three arguments. The first argument is the value to be converted.Here are a couple examples of converter functions. In addition to the normal conversions, convert
Date
todatetime
:from datetime import datetime def default_converter(value, _ignored1, _ignored2): if value.constructor.name == "Date": return datetime.fromtimestamp(d.valueOf()/1000) return value
Don’t create any JsProxies, require a complete conversion or raise an error:
def default_converter(_value, _ignored1, _ignored2): raise Exception("Failed to completely convert object")
The second and third arguments are only needed for converting containers. The second argument is a conversion function which is used to convert the elements of the container with the same settings. The third argument is a “cache” function which is needed to handle self referential containers. Consider the following example. Suppose we have a Javascript
Pair
class:class Pair { constructor(first, second){ this.first = first; this.second = second; } }
We can use the following
default_converter
to convertPair
tolist
:def default_converter(value, convert, cache): if value.constructor.name != "Pair": return value result = [] cache(value, result); result.append(convert(value.first)) result.append(convert(value.second)) return result
Note that we have to cache the conversion of
value
before convertingvalue.first
andvalue.second
. To see why, consider a self referential pair:let p = new Pair(0, 0); p.first = p;
Without
cache(value, result);
, convertingp
would lead to an infinite recurse. With it, we can successfully convertp
to a list such thatl[0] is l
.
- property typeof: str#
Returns the JavaScript type of the JsProxy.
Corresponds to typeof obj; in JavaScript. You may also be interested in the constuctor attribute which returns the type as an object.
- class pyodide.ffi.JsTypedArray#
Bases:
pyodide.ffi.JsBuffer
,pyodide.ffi.JsArray
[int
]
- pyodide.ffi.create_once_callable(obj: collections.abc.Callable[[...], Any], /) pyodide.ffi.JsOnceCallable #
Wrap a Python callable in a JavaScript function that can be called once.
After being called the proxy will decrement the reference count of the Callable. The JavaScript function also has a
destroy
API that can be used to release the proxy without calling it.
- pyodide.ffi.create_proxy(obj: Any, /, *, capture_this: bool = False, roundtrip: bool = True) pyodide.ffi.JsDoubleProxy #
Create a
JsProxy
of aPyProxy
.This allows explicit control over the lifetime of the
PyProxy
from Python: call thedestroy
API when done.- Parameters
obj (any) – The object to wrap.
capture_this (bool, default=False) – If the object is callable, should this be passed as the first argument when calling it from JavaScript.
roundtrip (bool, default=True) –
When the proxy is converted back from JavaScript to Python, if this is
True
it is converted into a double proxy. IfFalse
, it is unwrapped into a Python object. In the case thatroundtrip
isTrue
it is possible to unwrap a double proxy with theunwrap
method. This is useful to allow easier control of lifetimes from Python:from js import o d = {} o.d = create_proxy(d, roundtrip=True) o.d.destroy() # Destroys the proxy created with create_proxy
With
roundtrip=False
this would be an error.
- pyodide.ffi.destroy_proxies(pyproxies: pyodide.ffi.JsArray[Any], /) None #
Destroy all PyProxies in a JavaScript array.
pyproxies must be a JsProxy of type PyProxy[]. Intended for use with the arrays created from the “pyproxies” argument of
PyProxy.toJs
andto_js
. This method is necessary because indexing the Array from Python automatically unwraps the PyProxy into the wrapped Python object.
- pyodide.ffi.register_js_module(name: str, jsproxy: Any) None #
Registers
jsproxy
as a JavaScript module namedname
. The module can then be imported from Python using the standard Python import system. If another module by the same name has already been imported, this won’t have much effect unless you also delete the imported module fromsys.modules
. This is called by the JavaScript APIpyodide.registerJsModule
.- Parameters
name (str) – Name of js module
jsproxy (JsProxy) – JavaScript object backing the module
- pyodide.ffi.to_js(obj: Any, /, *, depth: int = - 1, pyproxies: Optional[pyodide.ffi.JsProxy] = None, create_pyproxies: bool = True, dict_converter: Optional[collections.abc.Callable[[collections.abc.Iterable[pyodide.ffi.JsArray[Any]]], pyodide.ffi.JsProxy]] = None, default_converter: Optional[collections.abc.Callable[[Any, collections.abc.Callable[[Any], pyodide.ffi.JsProxy], collections.abc.Callable[[Any, pyodide.ffi.JsProxy], None]], pyodide.ffi.JsProxy]] = None) Any #
Convert the object to JavaScript.
This is similar to
PyProxy.toJs
, but for use from Python. If the object can be implicitly translated to JavaScript, it will be returned unchanged. If the object cannot be converted into JavaScript, this method will return aJsProxy
of aPyProxy
, as if you had usedpyodide.ffi.create_proxy
.See Python to JavaScript for more information.
- Parameters
obj (Any) – The Python object to convert
depth (int, default=-1) – The maximum depth to do the conversion. Negative numbers are treated as infinite. Set this to 1 to do a shallow conversion.
pyproxies (JsProxy, default = None) – Should be a JavaScript
Array
. If provided, anyPyProxies
generated will be stored here. You can later usedestroy_proxies
if you want to destroy the proxies from Python (or from JavaScript you can just iterate over theArray
and destroy the proxies).create_pyproxies (bool, default=True) – If you set this to False,
to_js
will raise an errordict_converter (Callable[[Iterable[JsProxy]], JsProxy], default = None) –
This converter if provided receives a (JavaScript) iterable of (JavaScript) pairs [key, value]. It is expected to return the desired result of the dict conversion. Some suggested values for this argument:
js.Map.new – similar to the default behavior js.Array.from – convert to an array of entries js.Object.fromEntries – convert to a JavaScript object
default_converter (Callable[[Any, Callable[[Any], JsProxy], Callable[[Any, JsProxy], None]], JsProxy], default=None) –
If present will be invoked whenever Pyodide does not have some built in conversion for the object. If
default_converter
raises an error, the error will be allowed to propagate. Otherwise, the object returned will be used as the conversion.default_converter
takes three arguments. The first argument is the value to be converted.Here are a couple examples of converter functions. In addition to the normal conversions, convert
Date
todatetime
:from datetime import datetime from js import Date def default_converter(value, _ignored1, _ignored2): if isinstance(value, datetime): return Date.new(value.timestamp() * 1000) return value
Don’t create any PyProxies, require a complete conversion or raise an error:
def default_converter(_value, _ignored1, _ignored2): raise Exception("Failed to completely convert object")
The second and third arguments are only needed for converting containers. The second argument is a conversion function which is used to convert the elements of the container with the same settings. The third argument is a “cache” function which is needed to handle self referential containers. Consider the following example. Suppose we have a Python
Pair
class:class Pair: def __init__(self, first, second): self.first = first self.second = second
We can use the following
default_converter
to convertPair
toArray
:from js import Array def default_converter(value, convert, cache): if not isinstance(value, Pair): return value result = Array.new() cache(value, result); result.push(convert(value.first)) result.push(convert(value.second)) return result
Note that we have to cache the conversion of
value
before convertingvalue.first
andvalue.second
. To see why, consider a self referential pair:p = Pair(0, 0); p.first = p;
Without
cache(value, result);
, convertingp
would lead to an infinite recurse. With it, we can successfully convertp
to an Array such thatl[0] === l
.
- pyodide.ffi.unregister_js_module(name: str) None #
Unregisters a JavaScript module with given name that has been previously registered with
pyodide.registerJsModule
orpyodide.ffi.register_js_module
. If a JavaScript module with that name does not already exist, will raise an error. If the module has already been imported, this won’t have much effect unless you also delete the imported module fromsys.modules
. This is called by the JavaScript APIpyodide.unregisterJsModule
.- Parameters
name (str) – Name of js module
Classes:
|
Functions:
|
Wrapper for JavaScript's addEventListener() which automatically manages the lifetime of a JsProxy corresponding to the listener param. |
|
Wrapper for JavaScript's clearInterval() which automatically manages the lifetime of a JsProxy corresponding to the callback param. |
|
Wrapper for JavaScript's clearTimeout() which automatically manages the lifetime of a JsProxy corresponding to the callback param. |
|
Wrapper for JavaScript's removeEventListener() which automatically manages the lifetime of a JsProxy corresponding to the listener param. |
|
Wrapper for JavaScript's setInterval() which automatically manages the lifetime of a JsProxy corresponding to the callback param. |
|
Wrapper for JavaScript's setTimeout() which automatically manages the lifetime of a JsProxy corresponding to the callback param. |
- class pyodide.ffi.wrappers.Destroyable(*args, **kwargs)#
- pyodide.ffi.wrappers.add_event_listener(elt: pyodide.ffi.JsDomElement, event: str, listener: collections.abc.Callable[[Any], None]) None #
Wrapper for JavaScript’s addEventListener() which automatically manages the lifetime of a JsProxy corresponding to the listener param.
- pyodide.ffi.wrappers.clear_interval(interval_retval: int | pyodide.ffi.JsProxy) None #
Wrapper for JavaScript’s clearInterval() which automatically manages the lifetime of a JsProxy corresponding to the callback param.
- pyodide.ffi.wrappers.clear_timeout(timeout_retval: int | pyodide.ffi.JsProxy) None #
Wrapper for JavaScript’s clearTimeout() which automatically manages the lifetime of a JsProxy corresponding to the callback param.
- pyodide.ffi.wrappers.remove_event_listener(elt: pyodide.ffi.JsDomElement, event: str, listener: collections.abc.Callable[[Any], None]) None #
Wrapper for JavaScript’s removeEventListener() which automatically manages the lifetime of a JsProxy corresponding to the listener param.
- pyodide.ffi.wrappers.set_interval(callback: collections.abc.Callable[[], None], interval: int) int | pyodide.ffi.JsProxy #
Wrapper for JavaScript’s setInterval() which automatically manages the lifetime of a JsProxy corresponding to the callback param.
- pyodide.ffi.wrappers.set_timeout(callback: collections.abc.Callable[[], None], timeout: int) int | pyodide.ffi.JsProxy #
Wrapper for JavaScript’s setTimeout() which automatically manages the lifetime of a JsProxy corresponding to the callback param.