Skip to main content

A framework for creating and importing plugins

Project description

.. start-badges

.. raw:: html

<a href="">
<img src="" alt="Packaging status" align="right">

| |docs| |travis| |codecov|
| |pypi| |supported-versions| |supported-implementations|

.. |docs| image::
:alt: Documentation Status
.. |travis| image::
:alt: Travis-CI Build Status
.. |codecov| image::
:alt: Coverage Status
.. |pypi| image::
:alt: PyPI Package latest release
.. |supported-versions| image::
:alt: Supported versions
.. |supported-implementations| image::
:alt: Supported implementations

.. end-badges


Pluginlib makes creating plugins for your project simple.

Step 1: Define plugin parent classes

All plugins are subclasses of parent classes. To create a parent class, use the
@Parent_ decorator.

The @Parent_ decorator can take a plugin type for accessing child plugins
of the parent. If a plugin type isn't given, the class name will be used.

The @Parent_ decorator can also take a ``group`` keyword which
restricts plugins to a specific plugin group. ``group`` should be specified if plugins for
different projects could be accessed in an single program, such as with libraries and frameworks.
For more information, see the `Plugin Groups`_ section.

Methods required in child plugins should be labeled as abstract methods.
Plugins without these methods or with parameters
that don't match, will not be loaded.
For more information, see the `Abstract Methods`_ section.

.. code-block:: python

import pluginlib

class Parser(object):

def parse(self, string):

Step 2: Define plugin classes

To create a plugin, subclass a parent class and include any required methods.

Plugins can be customized through optional class attributes:

Changes the name of the plugin which defaults to the class name.

Sets the version of the plugin. Defaults to the module ``__version__`` or ``None``
If multiple plugins with the same type and name are loaded, the plugin with
the highest version is used. For more information, see the Versions_ section.

Specifies the plugin should not be loaded. This is useful when a plugin is a parent class
for additional plugins or when a plugin should only be loaded under certain conditions.
For more information see the `Conditional Loading`_ section.

.. code-block:: python

import json
import sample

class JSON(sample.Parser):

_alias_ = 'json'

def parse(self, string):
return json.loads(string)

Step 3: Load plugins

Plugins are loaded when the module they are in is imported. PluginLoader_
will load modules from specified locations and provides access to them.

PluginLoader_ can load plugins from several locations.
- A program's standard library
- `Entry points`_
- A list of modules
- A list of filesystem paths

Plugins can also be blacklisted. See the Blacklists_ section for more information.

Plugins are accessible through the PluginLoader.plugins_ property,
a nested dictionary accessible through dot notation.

.. code-block:: python

import pluginlib
import sample

loader = pluginlib.PluginLoader(modules=['sample_plugins'])
plugins = loader.plugins
parser = plugins.parser.json()
print(parser.parse('{"json": "test"}'))

.. _Entry points:

.. _PluginLoader:
.. _PluginLoader.plugins:
.. _@Parent:
.. _\_alias\_:
.. _\_version\_:
.. _\_skipload\_:

.. _Versions:
.. _Blacklists:
.. _Abstract Methods:
.. _Conditional Loading:
.. _Plugin Groups:

Project details

Download files

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

Files for pluginlib, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size pluginlib-0.5.0-py2.py3-none-any.whl (24.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pluginlib-0.5.0.tar.gz (124.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page