First, the requirements. The code cannot have knowledge of how the plugins are named (.so files, .py, package dirs, etc.). I don't want to hard-code the list of plugins, as this defeats its dynamic nature altogether. I have to be able to iterate across all plugins. Any user should be able to use the module without knowing that it's got plugins. Finally, it's got to be as simple as possible.
First up, we have whatever/__init__.py:
plugin_path = [os.path.join(__path__, "plugins/")]
for loader, name, ispkg in pkgutil.iter_modules(plugin_path):
file, pathname, desc = imp.find_module(name, plugin_path)
imp.load_module(name, file, pathname, desc)
This basically uses Python's module search to find all contents of the plugins sub-directory and load them. Now we have some more scaffolding in the same directory, as whatever/whatever.py:
plugins = 
"""Abstract plugin base class."""
plugins += [ plugin ]
# utility functions to iterate across and use plugins...
Finally, each plugin looks something like this, in plugins/foo.py:
from whatever/whatever import *
"""Concrete class for foo plugin."""
Simple enough, but it took a while to work it out. Unfortunately, it doesn't seem possible to merge whatever.py into __init__.py as we have a recursive import problem.