TotalFusionFOR TOTAL.JS AND NODE.JS

Version 0.1.1 · MIT license

Extend Total.js with Python, Rust, Go and WebAssembly.

Call functions written in other languages from Total.js and Node.js as plain async functions. Turn them into actions, API endpoints and MCP tools for AI agents, without leaving JavaScript.

$npm install totalfusion
# python/sentiment.py
from totalfusion import action

@action(summary='Detects the sentiment of a text',
        input='*text:String', output='label:String', mcp=True)
def analyze(data):
    return { 'label': 'POSITIVE' if 'love' in data['text'] else 'NEGATIVE' }
// Total.js application
const fusion = REQUIRE('totalfusion');

fusion.register({ python: { path: PATH.root('python') } });

// An action, an API route and an MCP tool
const result = await ACTION('sentiment/analyze', { text: 'I love it' }).promise();

Four runtimes, one way to call them

Pick the language that fits the work. The call from JavaScript is always the same.

From zero to a first call in a minute

Node.js 20 or newer, and Python 3.9 or newer for the Python runtime. TotalFusion never installs, downloads or compiles anything for you.

Install it

npm install totalfusion
npx totalfusion doctor --path ./python

The doctor tells you what is missing, and the exact command to fix it, before anything runs.

Write the function

# python/hello.py
def greet(data):
    return {'message': 'Hello ' + data['name']}

A plain function in a plain file. No server, no protocol.

Call it from Node.js

const fusion = require('totalfusion');

fusion.configure({
    python: { path: './python' }
});

const result = await fusion.python(
    'hello.greet', { name: 'world' });
// { message: 'Hello world' }

A pool of workers starts on the first call and stays alive.

Keep going in Getting started: it covers Total.js 5 actions, Rust, Go and the doctor.

Why not just child_process?

A process per call costs time and gives you nothing to build on. A worker that is already running answers at once, and keeps your model in memory.

17.6 msto start a process for every call
0.07 msfor a small call to a Python worker that is running
0.03 msfor a small call to a Rust or Go worker
43 msfor a 100 MB buffer to make the round trip, without base64

Beyond speed you get what you would otherwise write yourself: a pool, a bounded queue, timeouts, cancellation, restart of workers that die, memory limits, streaming and the contracts that make a function an action. Use cases has the numbers, and where it does not fit says when not to use it.

What you get

Learn by building

Every tutorial has an application that you can run and a test that runs it on every change, so the commands and the answers on the page are the ones that work.