def find_name(package, name):
    if hasattr(package, name):
        return package
for modulename, submodule in inspect.getmembers(package, inspect.ismodule):
    result = find_name(submodule, name)
if result:
    return result
How to locate a function in a Python module tree?