TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Crane04/esem/llms.txt
Use this file to discover all available pages before exploring further.
python() helper loads a Python module and returns a proxy object where every callable is wrapped as an async JavaScript function. You can destructure individual functions from the proxy or use the module object directly — either way, each call is a Promise that resolves to the Python return value, fully deserialized into native JavaScript types.
Basic usage
Importpython from esem-bridge, pass a file path, and call functions as you would any async JS function:
Passing objects to Python functions
Python functions that accept a dict can be called by passing a plain JavaScript object as an argument. The bridge serializes it as a Pythondict, and Python receives it as a positional argument — your Python function can then read its keys directly:
Using the module proxy directly
You don’t have to destructure. You can hold a reference to the module proxy and call functions through it:python: import syntax
As an alternative to the python() helper, esem-bridge supports a custom python: URL scheme that lets you use standard ES import statements:
The
python: import syntax requires the esem-bridge loader hook. Run your file with the CLI — npx esem run yourfile.js — or pass the loader flag manually: node --experimental-loader esem-bridge/loader yourfile.js.Always await function calls
Every proxied Python function returns a
Promise. You must await each call — calling without await gives you an unresolved Promise, not the Python return value.Real-world example: Next.js API route
A common pattern is calling Python pricing, ML, or data-processing logic from a Next.js route handler. Becausepython() is async and the worker is reused across requests, this is efficient for server-side use:
Type mapping
Values are automatically serialized on the way to Python and deserialized on the way back. The table below shows the mapping for all supported primitive types:| Python type | JavaScript type |
|---|---|
None | null |
bool | boolean |
int | number |
float | number |
str | string |
list | Array |
tuple | Array |
dict | object |
| class instance | proxy object |