Skip to main content

A framework for creating and importing plugins

Project description

Documentation Status Travis-CI Build Status Coverage Status
PyPI Package latest release Supported versions Supported implementations
Fedora version support EPEL version support

Overview

Pluginlib makes creating plugins for your project simple.

Features

  • Plugins are validated when they are imported

  • Plugins can be loaded through different mechanisms (modules, filesystem paths, entry points)

  • Multiple versions of the same plugin are supported (The newest one is used by default)

  • Plugins can be blacklisted by type, name, or version

  • Multiple plugin groups are supported so one program can use multiple sets of plugins that won’t conflict

  • Plugins support conditional loading (examples: os, version, installed software, etc)

  • Once loaded, plugins can be accessed through dictionary or dot notation

Installation

PIP

$ pip install pluginlib

EL6 and EL7 (RHEL/CentOS/Scientific)

(EPEL repositories must be configured)

$ yum install python-pluginlib
$ yum install python34-pluginlib

Fedora

$ dnf install python2-pluginlib
$ dnf install python3-pluginlib

Usage

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.

"""
sample.py
"""
import pluginlib

@pluginlib.Parent('parser')
class Parser(object):

    @pluginlib.abstractmethod
    def parse(self, string):
        pass

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:

_alias_

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

_version_

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.

_skipload_

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.

"""
sample_plugins.py
"""
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 filtered through blacklists and type filters. See the Blacklists and Type Filters sections for more information.

Plugins are accessible through the PluginLoader.plugins property, a nested dictionary accessible through dot notation. For other ways to access plugins, see the Accessing Plugins section.

import pluginlib
import sample

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

Project details


Download files

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

Source Distribution

pluginlib-0.8.0.tar.gz (202.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pluginlib-0.8.0-py2.py3-none-any.whl (25.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pluginlib-0.8.0.tar.gz.

File metadata

  • Download URL: pluginlib-0.8.0.tar.gz
  • Upload date:
  • Size: 202.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

File hashes

Hashes for pluginlib-0.8.0.tar.gz
Algorithm Hash digest
SHA256 37db0a16141c09db24443f992cd7aef6566f102f22500e958358b75c9b5417c1
MD5 4e4aa7e4dfd13fe7919c11e945593348
BLAKE2b-256 7e09cf1eb098b81b8f814cdec2955a8e4a269e0293ec2e474c59b8b64e61a8a9

See more details on using hashes here.

File details

Details for the file pluginlib-0.8.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pluginlib-0.8.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

File hashes

Hashes for pluginlib-0.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1904a3800426ae1cecb8dbb476b1a24d6f511619e97ada2c5c06519e7e378538
MD5 f2490277e1d63239b1e6270de6d8ae73
BLAKE2b-256 a1ca1aadaf9402a3fefefecd573970bdf2d6f67f82d9c01841bc5efc7b67b3cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page