Skip to content
MACHHUB MACHHUB MACHHUB
Contribute to this page

Authoring Processes

A Process is a serverless function that runs on MACHHUB. You write the function body; the platform handles scheduling, input resolution, execution in an isolated worker, and applying outputs. (Processes are a different feature from Flows, which are Node-RED.)

flowchart LR
  T["Trigger"] --> I["Inputs resolved"]
  I --> E["execute(context)"]
  E --> O["Outputs applied"]

A process is defined by:

  • Triggers — what causes it to run.
  • Inputs — data resolved before your code runs and handed to it.
  • Code — your execute body, in Python or TypeScript.
  • Outputs — what is done with the result after your code runs.
TriggerRuns when…
crona cron schedule fires
intervala fixed interval elapses
tag_changea subscribed tag changes
httpan HTTP request hits the process endpoint
manualyou run it explicitly (console / SDK)
  • Inputs: tag (a tag’s value) or sql (the result of a query). Resolved and passed in as context.inputs.
  • Outputs: sql (write to the database) or tag_write (publish to a tag). Output templating uses {{output.field}} for SQL and dot-notation for tag writes.

The SDK is injected as a global sdk — no import, no initialization:

async function execute(context: ProcessContext): Promise<any> {
const { inputs, trigger } = context;
const readings = await sdk.collection('myapp.readings').getAll();
const avg = readings.reduce((s, r) => s + r.value, 0) / readings.length;
return { avg };
}

Python processes receive a context dict. (The injected SDK is available in TypeScript processes; in Python, use SQL inputs/outputs to read and write data.)

def execute(context):
inputs = context['inputs']
# ...your logic...
return { 'ok': True }

You author and deploy processes with the MACHHUB Designer VS Code extension, which sends your code to the platform. Each domain gets its own isolated worker with its own dependencies (pip / npm), and the process version auto-increments on each deploy.

From an app, call it through the SDK:

const result = await sdk.processes.execute('computeAverage', { window: '1h' });

A process with an HTTP trigger also exposes an endpoint at POST /process/<slug>, where the JSON body is merged into context.inputs. See SDK → Processes and the API Reference for the exact calls.

  • Logs stream while a process runs (handy during development).
  • Packages are managed per domain — add the pip/npm dependencies your code needs.