pyscript.util
This module contains general-purpose utility functions that don't fit into more specific modules. These utilities handle cross-platform compatibility between Pyodide and MicroPython, feature detection, and common type conversions:
as_bytearray: Convert JavaScriptArrayBufferto Pythonbytearray.NotSupported: Placeholder for unavailable features in specific contexts.is_awaitable: Detectasyncfunctions across Python implementations.
These utilities are primarily used internally by PyScript but are available for use in application code when needed.
NotSupported
Small helper that raises exceptions if you try to get/set any attribute on it.
Source code in pyscript/util.py
as_bytearray(buffer)
Given a JavaScript ArrayBuffer, convert it to a Python bytearray in a
MicroPython friendly manner.
Source code in pyscript/util.py
is_awaitable(obj)
Returns a boolean indication if the passed in obj is an awaitable function. This is interpreter agnostic.
Info
MicroPython treats awaitables as generator functions, and if the object is a closure containing an async function or a bound method we need to work carefully.