In the context of a complex application, I need to import user-supplied \'scripts\'. Ideally, a script would have
def init():
blah
def execute():
mo
I'd first of all not require some functions, but a class that conforms to a specified interface, using either the abc module, or zope.interface. This forces the maker of the module to supply the functions you want.
Secondly, I would not bother looking for module-level code. It's the module-makers problem if he does this. It's too much work with no actual benefit.
If you are worried about security issues, you need to sandbox the code somehow anyway.