How do I call an external function from a stackstorm custom python action?

I have the following structure inside my actions pack:

actions/
         __init__.py
          acl.run.py
          acl.run.yaml
          lib/
             __init__.py
             utils.py

And inside the acl.run.py script there is this import:

from actions.lib.utils import create_device

But when I try to call the acl.run.py actions I get this error:

ImportError: No module named 'actions'

I have also tried to use the relative path ( .lib.utils), but in that case I’ve got:

SystemError: Parent module 'acl' not loaded, cannot perform relative import

If i remove the acl part from the name I have:

SystemError: Parent module '' not loaded, cannot perform relative import

Since I don’t know how exactly Stackstorm loads the script can someone write here and also in the documentation how to link the lib folder (named as best practice in the documentation( to the actions scripts?

Here is an example: stackstorm-ansible/actions at master · StackStorm-Exchange/stackstorm-ansible · GitHub with lib inside actions.

1 Like