Building a minimal plugin architecture in Python

dF. picture dF. · May 31, 2009 · Viewed 92.9k times · Source

I have an application, written in Python, which is used by a fairly technical audience (scientists).

I'm looking for a good way to make the application extensible by the users, i.e. a scripting/plugin architecture.

I am looking for something extremely lightweight. Most scripts, or plugins, are not going to be developed and distributed by a third-party and installed, but are going to be something whipped up by a user in a few minutes to automate a repeating task, add support for a file format, etc. So plugins should have the absolute minimum boilerplate code, and require no 'installation' other than copying to a folder (so something like setuptools entry points, or the Zope plugin architecture seems like too much.)

Are there any systems like this already out there, or any projects that implement a similar scheme that I should look at for ideas / inspiration?

Answer

TJG picture TJG · May 31, 2009

Mine is, basically, a directory called "plugins" which the main app can poll and then use imp.load_module to pick up files, look for a well-known entry point possibly with module-level config params, and go from there. I use file-monitoring stuff for a certain amount of dynamism in which plugins are active, but that's a nice-to-have.

Of course, any requirement that comes along saying "I don't need [big, complicated thing] X; I just want something lightweight" runs the risk of re-implementing X one discovered requirement at a time. But that's not to say you can't have some fun doing it anyway :)