Documentation 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() is the primary entry point for esem-bridge. It loads a Python module — by file path or pip package name — and returns a JavaScript proxy whose properties mirror the module’s exports. Functions become async callables, classes become async constructors that return instance proxies, and plain values become awaitable properties.
Signature
Parameters
The module to load. Accepted forms:
- Relative file path — e.g.
"./tools.py". Resolved from the current working directory. - Absolute file path — e.g.
"/home/user/scripts/tools.py". - Pip package name — e.g.
"numpy". Any string that does not start with./or/and does not end in.pyis passed directly toimportlib.import_module().
Returns
APromise that resolves to a proxy object representing the loaded Python module. The proxy maps each exported name to one of the following:
- Functions — become async JS functions. Call them with the same positional arguments you would use in Python; return values are deserialized back to native JS types.
- Classes — become async factory functions. Calling (or
new-ing) them constructs a Python instance and returns an instance proxy whose methods are also async. - Plain values (constants, dicts, lists, etc.) — exposed as
asyncgetter properties.awaitthem to retrieve the current value from Python.
Examples
Import styles
Calling a function
Instantiating a class
Calculator(2) constructs a Python Calculator instance with precision=2. The returned calc object is an instance proxy — calling calc.add(...) routes the method call back to the live Python object.
Reading a constant
await. Destructured values work the same way — they are awaitable properties, not plain strings or numbers.
The Python worker is spawned lazily on the very first
python() call and then reused for every subsequent call in the same process. There is no per-call startup cost after the first invocation. See ensureWorker() if you want to pre-warm the worker before the first python() call.If the module cannot be loaded — for example because the file does not exist or the package is not installed — the returned
Promise rejects with a PythonError. Wrap the call in try/catch or .catch() to handle this case.