top of page
Creating a Node

How to create a new node in STREMECODER

StremeCoderFlat.png

What is a node?

A node in STREMECODER is a snippet of code designed to perform a specific function. The node can contain as many or as few lines of code as you need. A node can also reference another .koi so that you can minimize your code. This is a more advanced use case and will not be discussed in this tutorial. It is best to minimize the number of functions that a given node performs so that it is easier to reuse in the future.

The advantage to using STREMECODER's node based coding is that you can divide your code into small, easily digestible functions that are easy to reuse which saves so much time when creating new programs.

Click here if you prefer to watch a video on how to create a new node.

What is a node?

Adding a node to your project

The first step to creating a new node is to add the node to your project. There are 3 mains ways to add a new node:

1. Select node from the file menu then select new node. You can also use the hot keys command (Ctrl, ⌘) + shift + n.

Add a node
Adding a New Node to StremeCoder Canvas

2. Alternatively, you can select the new node button from the purple nav bar.

Adding a New Node to your StremeCoder Canvas from the Nav Bar

3. The final method is to click the action button in the upper left hand corner which will open a menu of nodes that you can add to your project's canvas.

Action Button Icon

Then find the blank node item and drag and drop it onto your project's canvas.

Adding a Blank Node from the Menu

Note: The first two methods for adding a node results in the same layout for creating a new node. This display is meant to walk you through creating your first node. We will begin this tutorial with a walk-through of the layout using the first two methods. At the end of this tutorial, we will discuss the layout using the third method.

Once you've added your new node, you will be presented with a window to start editing your node. The first section you will see is titled "Description."

Node Description Section

This section provides you with a video walk-through of creating a new node if you prefer a video format. You can also view this video at the bottom of this tutorial.

The next section you will see is titled "Node Data." This is where you will edit the contents of your node.

Node Data Section

Naming your new node

The first section under "Node Data" is where you can name your node. Here you want to write a descriptive name for your node so that both coders and non-coders would be able to understand the purpose of your node. This will be the name that is displayed project canvas and will be the major indicator for you or others viewing you program as to the function of your code. The title of your node does not need to follow normal programming schemes, so you can include spaces, numbers, and symbols in the node title. The title will always be displayed in all caps, so you do not need to worry about capitalization.

 

For this example, we are going to make a simple node that takes in two numbers from the user and adds them together. Let's name our node, Add Two Numbers.

If you are just sketching out a program and not planning on coding just yet, you can stop here. Save your node and continue making new nodes with new names without worrying about adding any code.

Name your new node
Naming your Node

Categorizing your node

The next section titled "Category" contains a drop down menu that allows you to categorize your node. This feature will be used more in future versions of STREMECODER. For now, it doesn't matter what category you select, so we will keep it at "function."

Selecting the Category of your Node
Categorize your node

Documenting your node

After category, you will see a section titled "Node Description." This section is meant for you to document your node. This section uses markdown which allows you to add text, code blocks, images, videos, gifs, hyperlinks, etc. to your code documentation to fully explain the function of your node. We encourage you to include YouTube videos where you demonstrate the use of your node. The new node provides you with a template to help you document your node, but feel free to document it however you prefer. Keep in mind that the template ends with a note providing the node under the MIT licence. If you do not want to follow this license, ensure that you at least edit that line of the description.

Documente your node

Adding imports for you node

If your node requires the import of any python libraries, you can add the imports here. Our simple node does not require any imports, but for demonstration purposes, we will import numpy by adding:

import numpy as np

Add imports
Importing Python Libraries into your node

Adding your python code

The next section, "Python Function Code," is where you write all of your python code. Since you added your imports in the import section, you do not include any imports in this section of your code. You will see the following in the "Python Function Code" section:

Add python code
Python function code

The first line in the "Python Function Code" section is:

@on_start

This line is necessary for your node to function so you should not edit this line.

Define your function

The next line defines your function. This is where you want to name your function. The name of your function needs to follow normal python function rules and does not need to match the name of your node that you set earlier.

NoteSTREMECODER uses special characters, |||, to insure that you can have duplicate functions that share the same python function name, but may have slight differences in code. ||| is an enumerator that assigns a distinct number to every node that uses ||| such that a node that is repeated in your program will run as a completely distinct function.

For our example node, we are going to define our function as:

addTwoNums|||

setting the function name in your python function

After the name of the function, you can see the node takes in the arguments args and kwargs. We do not recommend you change the input arguments unless absolutely necessary. We use kwargs as the variable to pass data between nodes. We will get into more detail on the uses of kwargs later in this tutorial.

Now we are ready to add in the python code. This node is going to take in two values from the user and add them together. We'll set the first number, num1, equal to a variable user input. We use curly brackets, {}, around our user input variable name. Whatever is entered into the user dialog will be put in place of the curly brackets.

num1 = {userInputNum1}

userInputNum2 will be defined in a later section, so do not worry about that here. Now let's add the remainder of the code to add two numbers together:

num2 = {userInputNum2}

addedNum = num1 + num2

Finally, let's print the output of our function to the terminal:

print (str(num1) + " + " + str(num2) + " = " + str(addedNum))

Our entire block of code should look like this:

num1 = {userInputNum1}
num2 = {userInputNum2}
    
addedNum = num1 + num2
    
print (str(num1) + " + " + str(num2) + " = " + str(addedNum))

adding python code to your function

Finally you'll see that the function returns kwargs. As previously mentioned, kwargs is designed to pass data between nodes. We intend kwargs['Data'] to store data that you will manipulate in future nodes and kwargs['Settings'] to store data that will need to be accessed from multiple nodes.

For this example, we are only making one node so we do not need to pass data to another node. However, if you wanted to pass the output to another node to manipulate, you could add the following:

kwargs['Data'] = addedNums

This completes the body of our function.

Creating your code execution string

The next section labelled "Python Code Execution String" is where you define the string that will be used to execute your node. Typically this will be the same name as your function, but it can be different if you've defined multiple functions in your node.

For our node, we are going to make the code execution string the same as the name of our node function:

addTwoNums|||

Code execution string
execution string to execute your function

Editing node input pins

This is a more advanced feature and will not be used in this example, but STREMECODER gives you the option of adding new input pins to your node. By default, your node has a "start" input pin and a "pass" output pin.

image of a node in StremeCoder
Input pins

Both start and pass are necessary for your code to run properly, but you can add new input pins by adding new key and value combinations to the "in" key of the pin dictionary. 

editing pins in your node

Editing user input dialog boxes

The final section is labelled "Settings." This is the section where we can define variables that will take in user inputs. The user input dialog boxes are a powerful tool to allow users of your node to edit the value variables without needing to touch your code. The values could be different file names for importing or exporting data, altering user specific settings such as data thresholds, or collecting user data. A new node comes with a template for creating a user dialog.

User input dialog boxes
creating user input dialog boxes for your node

The user input dialog boxes are structured with a key, the variable name, and a label, a title for the dialog box. For our example, we want to have two user dialog boxes so the user can enter two values to add.

The parts of the code that you want to edit are shown in red. The key is going to be the variable name we used in our python code: userInputNum1 and userInputNum2.

The label should be some explanatory text such that the user knows what they are supposed to put in the dialog box. For our example, we will use: "Type the first number you want to add" and "Type the second number you want to add." We will keep these inputs as required by keeping "required" set to true.

So our settings should look like this:

[{"key":"userInputNum1","label":"Example User Input","props":{"required":true}},{"key":"userInputNum2","label":"Example User Input","props":{"required":true}}]

example user dialg box code

Saving your new node

You have now created your new node. To save your node and return to your project canvas, select save at the bottom of the screen.

button to save your node
Save your node

Selecting save should have returned you to the the project canvas and see your newly created node in the upper left hand corner of the canvas.

image of newly created node

Viewing and Editing the contents of your new node

To view and edit the contents of your node, double click on the node. You will notice that the format of the node looks a little bit different. This format is what you would see had you used method 3 of adding a new node and anytime you want to edit previously made nodes.

Edit your node
contents of the new node

You will see the name of your node at the top which you can edit at any point. Below the name, you have the ability to keep track of your node versions. Below that is a number that is assigned to your node. This node number is helpful for debugging your program.

Below the node number, you will see the 2 user input dialog boxes that we created. This is where the user can modify the user inputs. Let's input in two numbers to add. For the first number, we will use 581, and for the second number, we will use 349. If we were entering strings, such as the name of a file, we would need to include " " around the string.

example user dialog boxes in the node

Below the user dialog boxes, you will see three buttons where you can edit: the description of your node, the user dialogs, or pins.

At the top of your window, you will notice multiple tabs you can use to edit the other components of your node. The imports tab allows you to change the imported libraries. The function node allows you to view and edit your python code, and the execution tab allows you to change the execution string for your node.

Compiling and running your new node

If you'd like to test out your new node, you can connect the start node to your new node. You may need to move the stop node to be able to connect the start node. Click and drag the start pin of the start node to the start pin of the new "Add Two Numbers" node.

Execute your node
connecting your nodes to run your program

Using the same method, connect the pass pin of the "Add Two Numbers" node to the start pin of the "stop" node.

Finally hit the Compile & Run button in the upper right hand corner or use the hotkeys command (Ctrl, ⌘) + enter.

compile and run your program icon

You will be prompted to enter the file name for the compiled .py file and select the location to save the file. Keep in mind that saving the .py file means you are saving the compiled version of your node graph (.koi). This does not mean you are saving your Koi. Visit the FAQ page for more details on the difference between the .py and .koi files. 

After you've save the compiled .py file, a terminal will pop up showing your program running. You should see something similar to this:

program output

Our program shows that 581 + 349 = 930.

You should now be able to create and edit your nodes. Below we have some more tips to keep in mind when you are creating your new nodes and STREMECODER programs. You can also watch a video on how to create a new node below.

 

If you have further questions, please feel free to reach out to us. We are always available to chat in Discord if you have any questions about changing your python binary or anything else. You can also contact us through e-mail at contact@pluricorp.com. If there are any other tutorials you would like to see us make, please let us know!

STREMECODER TIPS

StremeCoder is meant to make your Python algorithms readable to anyone. You should keep in mind these guidelines when you are designing and sharing your algorithms:

  • Generate Descriptive Node Names. The name of the node is what will be displayed on the StremeCoder canvas so you want the node name to explain to coders and non-coders the main function of your node. 

  • Document Each Node as you begin to use it. Each node in StremeCoder has a fully markdown capable description area where you can describe the functionality of your node and everything required to get it to work for future developers who might use your node. 

  • Make your code modular. A Node that can be used by ANYONE is significantly more valuable than a Node that can only be used in your algorithm

  • A Beautiful Koi (Node Graph) is elegant and can be read like a story of reasonable functions

  • Maintain, when possible, the functional flow of StremeCoder. That is avoid placing functions and classes outside of your node functions unless no other solution is possible.

  • When adding to kwargs[Settings] enclosing your dictionary items inside a very specific subname will avoid collisions with other nodes you may download on the internet or if you choose to make your node available to others, like in the example below:

    • kwargs[Settings][LabNameNumber][SettingVariable]

Use The StremeCoder Canvas To Your Best Advantage

  • We intend for you to use the Canvas as real workspace.

  • You can zoom out of the canvas (CTRL +/- and CTRL Mouse wheel) and hide nodes you want to use later. Don't worry about a messy canvas when you are working. Having extra parts is useful when you are editing and duplicating nodes.

 

Our recommended workflow for sharing algorithms

  • Generate a Sketch of different nodes that take you from an input through analysis to a final output.

  • Export that sketch to your client/team members as either a Koi or as an image in an email.

  • Once everyone is in agreement with the flow of the algorithm, code the algorithm in StremeCoder.

  • Update the descriptions by filling out the documentation template.

  • You can also upload your nodes to github, sending your koi or python files to your client/other team members

Resources To Help You Along:

YouTube Channel

Subscribe to our YouTube channel for more videos on StremeCoder.

Talk to the Developers on Discord

Join our discord community to talk directly with the developers of StremeCoder.

The StremeCoder sub-reddit

Join the community, see examples, post any questions or exciting projects you've been working on! 

Dave Peña's GitHub Page

The GitHub page from the creator of StremeCoder contains programs written in StremeCoder for you to try and nodes you can download and use for your own programs.

Need help getting started?
Just talk to us. We'll be happy to help you.

bottom of page