Plugins / Modularity

Robin Kåveland kaaveland at
Wed Oct 10 20:30:12 CEST 2007

Hi there. I'm basically in the process of writing my first substantial
application in Python, and I've made a couple of (I'd like to say)
design decisions so it won't just be a jumble. So, I've divided my
program into three sub-packages, core, plugins and utilities.

The core will be needed for the program to be run, but I've put it in
a package by itself to make things more tidy.
The utilities will be things that are handy to have (I'm thinking
packages written by others that will make my work easier), but aren't
necessary for the program to run. I'm not sure if this is needed yet,
but I want to have the option in case it turns out to be useful.

The plugins will basically be a package with modules adding
functionality to the program, so to make it more extensible, and let
others have a very simple way of extending the functionality without
having to read a lot of source code and documentation. Adding a plugin
should be really simple, preferrably you shouldn't have to modify any
existing source, just put a .py file into the directory. This is where
I'm sort of stuck. Does anyone know a way I can achieve this?

This poses a couple of challenges for me, given the structure of my
project and that I have no clue about how to do it. I'm thinking here
that every plugin will have a main callable, which will recieve a
Request object which can be queried for information, and an Action
object which can be used to affect the state of the program to some
degree. These will ideally be very simple (And for the moment, they
obviously are).

What I want, is a moment to 'contact' every module in the plugins
package, and send these two objects to it's main callable. I also want
to add a way for the program to load and reload plugin modules on the
fly, so I can modify them without having to shut it down.

Does anyone have some links for me? Alternatively any ideas?

Thanks in advance.

More information about the Python-list mailing list