When esem-bridge loads a Python module, class constructors are exposed as async factory functions. Calling one sends aDocumentation 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.
construct RPC to the Python worker, which instantiates the real Python object and registers it in an in-process object registry. Back on the JavaScript side you receive a lightweight proxy bound to that live Python instance — every public method on the instance becomes an async JS function you can call directly.
Defining the Python class
Here is a simpleCalculator class:
Instantiating and calling methods
Destructure the class from the module proxy, then call it — with or withoutnew — to get a proxy bound to the Python instance:
Stateful classes
Instance state lives entirely in Python. Multiple JS calls to the same proxy all operate on the same underlying Python object, so state accumulates as you’d expect. TheCounter class from the playground demonstrates this:
How the object proxy works
When youawait a class call, the bridge receives the instance’s ref_id (e.g. "py_obj_1") and the full list of public methods discovered at construction time. The JS side builds a proxy object with one async function per method.
If you access a method that was not listed at construction (for example a dynamically added attribute), the Proxy intercepts the property lookup and dispatches a method_call RPC on the fly — so you are never blocked by a missing method on the JS side.
Releasing instances
Every Python instance the bridge creates is stored in an in-process registry so the worker can look it up byref_id on each method call. When you are done with an instance, call release() to remove it from the registry:
Passing a proxy back to Python
If you have a JS proxy for a Python object and need to pass it as an argument to another Python function or method, the bridge recognizes it automatically. The serialize step checks for
__esem_ref_id on the value and sends a { type: "proxy", ref_id: "..." } wire message. Python then looks up the original object from the registry and passes it directly — no re-serialization required.