Skip to main content

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.

Not everything in a Python module is a function. Module-level variables — strings, numbers, booleans, dicts, lists, and None — are exposed on the module proxy as awaitable properties. Each access triggers a get_attr RPC call to the Python worker, which reads the attribute value, serializes it, and returns it to JavaScript. The result is deserialized automatically into the equivalent native JS type.

Defining constants in Python

# config.py
VERSION = "1.0.0"
SETTINGS = {
    "debug": True,
    "ports": [3000, 3001],
}

Reading constants from JavaScript

Await the property access on the module proxy to retrieve the value:
import { python } from "esem-bridge";

const config = await python("./config.py");

console.log(await config.VERSION);  // "1.0.0"
console.log(await config.SETTINGS); // { debug: true, ports: [3000, 3001] }

Destructuring constants

When you destructure a non-callable export, the destructured binding itself is a Promise. Await it when you need the value:
const { VERSION } = await python("./config.py");

console.log(await VERSION); // "1.0.0"
Each property access on a non-callable attribute sends a fresh get_attr RPC to the Python worker. If you read the same constant multiple times, store the resolved value in a local JS variable instead of awaiting the property repeatedly.
const version = await config.VERSION; // one RPC
console.log(version);                 // no RPC — just a local variable
console.log(version);

Type mapping reference

The test fixture (test/fixture.py) covers all supported constant types. The table below shows what each Python value becomes in JavaScript:
Python constantPython typeJavaScript valueJavaScript type
VERSION = "0.1.2"str"0.1.2"string
ENABLED = Truebooltrueboolean
RETRY_COUNT = 3int3number
NOTHING = NoneNoneTypenullnull
SETTINGS = {...}dict{ debug: true, ports: [...] }object
These are verified by the integration test suite:
const fixture = await python("./test/fixture.py");

assert.equal(await fixture.VERSION, "0.1.2");
assert.equal(await fixture.ENABLED, true);
assert.equal(await fixture.RETRY_COUNT, 3);
assert.equal(await fixture.NOTHING, null);
assert.deepEqual(await fixture.SETTINGS, {
  debug: true,
  ports: [3000, 3001],
});
Functions and classes are not accessed this way. When the bridge loads a module it inspects every public attribute: callables become async JS functions (or class proxies), and only non-callable values become awaitable properties. If you try to await a function proxy as though it were a plain value, you will receive the function itself, not a return value.

Build docs developers (and LLMs) love