py_compile.compile('/path/to/main.py')
print([key for key in list(locals().keys()) if isinstance(locals()[key], type(sys
    )) and not key.startswith('__')])
How can I check on runtime that a python module is valid without importing it?