Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Plugin, dynamic loading and factory utility library

Project Description

Pluggage

A Utility library for using plugins with python There are two ways to use this library to dynamically load objects, a lightweight load-on-demand via a dictionary interface and a heavier factory pattern using a base class to register objects with a factory.

Lightweight Plugins

The lightweight plugin system uses a dictionary API to load dot-delimited names and either return the object or optionally call it.

from pluggage.plugins import Plugins
loader = Plugins()

# load references to objects
func_ref = loader['some_module.some_submodule.some_function']
cls_ref = loader['some_module.some_submodule.SomeClass']

# call the objects and get the results
func_result = loader('some_module.some_submodule.some_function', *func_args, **func_kwargs)
someclass_instance = loader('some_module.some_submodule.SomeClass', *ctor_args, **ctor_kwargs)

Heavyweight Plugins

The Heavyweight Plugins are implemented via a metaclass registry that allows classes to be registered as plugins on import, and then accessed via a named factory. Classes inheriting from the base plugin class specify which factory they will be registered with and by default will register under that factory with their class name, or that can also be overridden by inheritance. The plugins can be accessed using a get_factory call provided in the pluggage.registry module.

factory = get_factory('my_factory')
some_class_instance = factory('SomeClass', *ctor_args, **ctor_kwargs)

To register a class with a factory, inherit from the PluggagePlugin class and set the PLUGGAGE_FACTORY_NAME class attribute:

from pluggage.factory_plugin import PluggagePlugin

class SomeClass(PluggagePlugin):
    """
    sample plugin
    """
    PLUGGAGE_FACTORY_NAME = 'my_factory'
    def __init__(self, value):
        self.value = value
    def __call__(self):
        print(value)

factory = get_factory('my_factory')
some_class_instance = factory('SomeClass', 'abc')
some_class_instance()  # prints 'abc'
Release History

Release History

This version
History Node

0.0.4

History Node

0.0.2

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pluggage-0.0.4.tar.gz (5.0 kB) Copy SHA256 Checksum SHA256 Source Oct 20, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting