How to develop custom Python actions with `lib` AND no `lib`-related import errors

If you’re developing custom Python actions and use a lib directory in actions, you may have seen that all imports related to lib start with from lib.<submodule> import <something> or import lib.
a) your IDE is likely to report this import statement as invalid.
b) (afaik) you can’t test the code outside of StackStorm.
The proposed solution:

  • add a file to the actions directory with the following content:
from setuptools import setup, find_packages


  • add this file to .gitignore
  • open a terminal (if you haven’t already :slight_smile:) and go into the actions directory
  • run either pip install -e ./ or python develop
  • ATTENTION: if you’re deducing your requirements.txt via pip freeze, exclude the line corresponding to lib (it’s a line starting with -e, and containing a reference to the git repo)
  • maybe restart the IDE if the IDE still reports the lib import statements as wrong

Done :slight_smile:
Now your lib imports should “work”, and also your IDE’s autocomplete/inspection features. Furthermore, you can now test your library code with ease :slight_smile:

If you’re wondering what this was all about, check out Python Packaging. It’s straightforward and powerful.

Feedback, questions and comments on this procedure are very welcome.