def load(root_import_path, is_valid=lambda entity: True):
    """Returns modules in ``root_import_path`` that satisfy the ``is_valid`` test
    :param root_import_path: An string name for importing (i.e. "myapp").
    :param is_valid: A callable that takes a variable and returns ``True``
                     if it is of interest to us."""
prefix = root_import_path + '.'
modules = []
for _, name, is_pkg in walk_packages(root_import_path, prefix=prefix):
    if is_pkg:
        continue
module_code = __import__(name)
contents = dir(module_code)
for thing in contents:
    if is_valid(thing):
        modules.append(thing)
return modules
How do you dynamically load python classes from a given directory?