Iterate over subclasses of a given class in a given module
<p>In Python, given a module X and a class Y, how can I iterate or generate a list of all subclasses of Y that exist in module X?</p>

<p>Although Quamrana's suggestion works fine, there are a couple of possible improvements I'd like to suggest to make it more pythonic. They rely on using the inspect module from the standard library.</p>

<ol>
<li>You can avoid the getattr call by using <code>inspect.getmembers()</code></li>
<li>The try/catch can be avoided by using <code>inspect.isclass()</code></li>
</ol>

<p>With those, you can reduce the whole thing to a single list comprehension if you like:</p>

<pre><code>def find_subclasses(module, clazz):
    return [
        cls
            for name, cls in inspect.getmembers(module)
                if inspect.isclass(cls) and issubclass(cls, clazz)
    ]
</code></pre>
