Registry / ai-ml / node-calls-python

node-calls-python

JSON →
library1.11.1jsnpmunverified

Node.js addon that embeds Python using N-API and Python C API, allowing direct in-process execution of Python code without spawning child processes. Version 1.11.1 ships TypeScript types and supports Python 3.x. Unlike child_process or socket-based approaches, it keeps data in shared memory and avoids IPC overhead, making it suitable for rapid ML/DL model inference or small NumPy operations. Release cadence is moderate; requires node-gyp for native compilation. Better than python-shell for latency-sensitive scenarios but limited to Python 3 and may need platform-specific build setup.

ai-ml
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM import since v1.11.0; CommonJS still works but prefer ESM for type safety.

import { interpreter } from 'node-calls-python'

Only exported as named type; cannot instantiate directly. Use interpreter singleton.

import { PythonInterpreter } from 'node-calls-python'

TypeScript users should import the Interpreter type to type-check callbacks or custom wrappers.

import type { Interpreter } from 'node-calls-python'

Shows async/sync calling, class instantiation, and memory management with node-calls-python.

import { interpreter } from 'node-calls-python'; async function main() { // Import a Python module const pymodule = await interpreter.import('test'); // assumes test.py in cwd // Call a Python function asynchronously const result = await interpreter.call(pymodule, 'add', 3, 4); console.log('add result:', result); // 7 // Create a Python object const calc = await interpreter.create(pymodule, 'Calculator', [5, 6, 7]); // Call a method on the object synchronously const sum = interpreter.callSync(calc, 'sum_vector'); console.log('vector sum:', sum); // 18 // Destroy object to free memory await interpreter.destroy(calc); } main().catch(console.error);
Debug
Known footguns
gotchaNative build requires Python 3.x headers and node-gyp; missing python3-dev on Linux or windows-build-tools on Windows causes installation failure.
breakingVersion 1.11.0 switched to ESM-first exports. Dynamic require() may fail in pure ESM projects or when `type: module` is set in package.json.
gotchaPython objects must be cleaned up with interpreter.destroy() to prevent memory leaks; failure to do so may cause gradual memory growth in long-running processes.
gotchaOnly Python 3 is supported; Python 2 usage will fail during build.
gotchaOn ARM macOS (M1/M2), default npm install may fail because of architecture mismatch in native addon.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources