23

Can anyone provide a minimal working example using the Yapsy plugin framework?

1 Answer 1

46

Here's a very simple example. It has three files:

  • plugins\plugin1.py - the plugin. This has to contain a class inherited from IPlugin.
  • plugins\plugin1.yapsy-plugin - information about the plugin.
  • yapsy-example.py - the main script. This just loads all the plugins it can find in the "plugins" directory, and calls a method on them to prove that they work.

You could add more plugins to the plugins directory, and this script would loop around them all.

There's another more complicated example at http://lateral.netmanagers.com.ar/weblog/posts/BB923.html (archived).

yapsy-example.py

from yapsy.PluginManager import PluginManager

def main():   
    # Load the plugins from the plugin directory.
    manager = PluginManager()
    manager.setPluginPlaces(["plugins"])
    manager.collectPlugins()

    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        plugin.plugin_object.print_name()

if __name__ == "__main__":
    main()

plugins\plugin1.py

from yapsy.IPlugin import IPlugin

class PluginOne(IPlugin):
    def print_name(self):
        print "This is plugin 1"

plugins\plugin1.yapsy-plugin

[Core]
Name = Plugin 1
Module = plugin1

[Documentation]
Author = John Smith
Version = 0.1
Website = http://lotsofplugins.com
Description = My first plugin
8
  • Hmmm, that suggests that your plugins aren't being found. Are they in the plugins\ subdirectory of the directory that contains yapsy-example.py? Are you running yapsy-example.py from that directory? Mar 17, 2011 at 21:39
  • 1
    One other thing to try - turn on debug logging by adding the following to yapsy-example.py (after the other imports): import logging logging.basicConfig(level=logging.DEBUG) That should give you some output, which will be helpful for debugging this. Mar 17, 2011 at 21:41
  • I realized I was missing the from yapsy.IPlugin import IPlugin line
    – Sergio
    Jul 4, 2011 at 21:03
  • 1
    thanks for this nice example. I found a nice tutorial with small example codes here: link
    – otterb
    Dec 4, 2011 at 23:09
  • 1
    I don't see mention in this answer of activatePluginByName which is present in the yapsy Getting Started docs. Is activatePluginByName optional or just missing from this answer?
    – gene_wood
    Oct 30, 2017 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.