How to create reusable nodes

Follow these simple guidelines to make sure that your node is as reusable as possible.

  • Break down the task into the smallest parts that are useful by themselves and write nodes for each of those, instead of writing one monolithic “fix everything” node. Take some inspiration from the Unix philosophy; every node should “do only one thing, and do it well”.
  • Try to work on the most natural data type for the problem that you are trying to solve. When in doubt go with Table since it is the simplest and most widely applicable data type.
  • Do not hard code site specific stuff into your nodes. Instead add preprocessing steps or configuration options as needed.
  • Add documentation for your node, describing what the node does, what the configuration options are, and whether there any constraints on the input data.
  • When you write the code for your node, remember that how you write it can make a huge difference. If others can read and easily understand what your code does it can continue to be developed by others. As a starting point you should try to follow the Python style guide (PEP8) as much as possible.

If your nodes are very useful and do not include any secrets you may be able to donate it to SysESS for inclusion in the standard library. This is only possible if the node is considered reusable.

Add extra modules to your library

If your node code is starting to become too big to keep it all in a single file or if you created some nice utility functions that you want to use in several different node files you can place them in the subfolder to the folder Common that we created way back in Creating a library structure. But first we need to make a package out of that subfolder by placing an empty file in it:

> touch boblib/Common/boblib/

Now you can add modules to the package by adding the python files to the folder:

> spyder boblib/Common/boblib/

The Common folder will automatically be added to sys.path so you will now be able to import modules from that package in your node code:

from boblib import mymodule