Creating simple dynamic loading Python plugin model

plugin_sliderTo create a simple plugin framework in python we will be using the following features in Python

  • Abstract Base Class : abc
  • Dynamic module import : __import__

Use case: Create a plugin framework for loading dynamic model classes that will be deployed in a directory while the server is running. Here in the example we have created a standalone module instead of a server for invoking the dynamic models loaded. This kind of dynamic loading is required where the classes are required to be dynamically loaded with out changing your core implementation.

Abstract Class: ModelAbstract.py

This is the Abstract class used for define the structure of your derived model classes. The plugin framework should state the interfaces that needs to be defined by the derived classes which needs to be loaded dynamically. Every derived class should inherit & implement all the abstract methods in Abstract class

Derived Class : modela.py

This is the class which extends & implements all the abstract methods of ModelAbstract class

Derived Class : modelb.py

Dynamic Model Loader : loader.py

This is the dynamic loader module which is used for dynamically loading the modules from the models directory.

Dynamic Model Class Invoker: invoker.py

This is the piece of code which is used for executing the dynamic loader & invoking the methods in the models.