You can use the standard pkgutil module to get a top-level import list, for example:
import pkgutil list(pkgutil.iter_modules())
It will only search for modules that live in regular files, zip files or another bootloader that support enumeration of modules. Most of them should be on a standard system.
The result is a list of 3 tuples with a loader, the name of the module and whether it is a single module or package. If you are only interested in the module name, just do:
list(item[1] for item in pkgutil.iter_modules())
spectras
source share