The only issue I can see is if the package you're trying to import isn't available in the JVM where the interpreter is running. For instance a package available in Gateway Scope may not be available in Client Scope, or a Package may not be available to all clients. If the code will always be running in the same JVM and you know the package will be available, then it should work just fine.
I would still wrap it in a try/except block with logging to indicate if something goes wrong trying to import the package.
You certainly should never import any Ignition project library script. Never. (Ignition uses its own "import" machinery.)
Sure, as long as the ultimate origin of the call stack is in project Final.
Such a function in Global would depend on the ultimate caller's context to have an implementation of the named function. Different leaf projects could have different implementations.
Edit: This long-standing script library bug in Ignition's "auto import" behavior is relevant here:
Thanks for the reply
"Ignition uses its own "import" machinery."
That's exactly why I'm not very confident to use importlib...
The caller context, the final project has an implementation of the named function.
The use case was to create a generic perspective page message handler with in the message payload the module name, fonction name and args (handler in the global project). Action of the page message handler would be to dynamically import the module name provided and call the function with args.
(probably influenced by the function pointers in the C language...)
Don't import. Don't do function lookup. Simply have the caller supply the function. Not the function name, but the function object. Named functions, without the parentheses, are function pointers in python. They are first-class objects.
Consider re-architecting your global functionality as decorators, and simply annotate the leaf project's library functions with the desired common behavior. Then the message handler simply delegates (one-liners of course) to a project library script function as usual.