ExamplesExample

Example: hello, with an input

Every script has the same shape: an entry point whose parameters become the run’s inputs, output printed to the logs, and a value returned as the result. This example is that shape and nothing else, in Python, TypeScript, JavaScript, C and C++.

What you will learn
  • Declare an input with a type and a default
  • Tell logs apart from the result

Inputs in, result out

The editor reads the parameters of main and draws a field for each one in the Inputs card. What you print lands in Logs; what you return lands in Output, and it is also what an API call or the next step of a flow receives. In C and C++, a // @param line declares each input and waiso_set_result declares the result.

Run fills the Output tab with the returned value; the printed line is in Logs.

The code

hello.py
def main(name: str = "world"):
    print(f"saying hello to {name}")
    return {"message": f"Hello, {name}!"}
  1. Create a script in your language, paste the code and press Run: it answers Hello, world!.
  2. Type Ana in the name field and run again.

Take it further

  • Publish it and call it over HTTP — see Your first API.
  • Add more inputs: numbers, booleans, dates and lists each get their own control — see Script inputs.

Nothing in the code changes between the ways it is started. Run from the editor, fired by a schedule, called over the API with {"name": "Ana"} or used as a flow step, the same parameter receives the value and the same returned object is the answer, so what you test here is exactly what callers get.