Skip to main content

About

A simple plugin framework inspired by the work of Marty Alchin.

Continuous integration is powered by Jenkins.

http://ci.petarmaric.com/job/simple_plugins/badge/icon

Installation

To install simple_plugins run:

$ pip install simple_plugins

Usage examples

Quick start:

>>> from simple_plugins import PluginMount

>>> class BaseHttpResponse(object):
...     """Mount point is not registered as a plugin"""
...
...     status_code = None
...
...     __metaclass__ = PluginMount
...
...     class Meta:
...         id_field = 'status_code'
...
...     def __repr__(self):
...         return "<%s: %s>" % (self.__class__.__name__, self.status_code)
...

>>> class OK(BaseHttpResponse):
...     status_code = 200
...

>>> class BaseRedirection(BaseHttpResponse):
...     """'Base*' classes are not registered as plugins"""
...     pass
...

>>> class MovedPermanently(BaseRedirection):
...     status_code = 301
...

>>> class NotModified(BaseRedirection):
...     status_code = 304
...

>>> class BadRequest(BaseHttpResponse):
...     status_code = 400
...

>>> class NotFound(BaseHttpResponse):
...     status_code = 404
...

# All plugin info
>>> BaseHttpResponse.plugins.keys()
['valid_ids', 'instances_sorted_by_id', 'id_to_class', 'instances',
 'classes', 'class_to_id', 'id_to_instance']

# Plugin info can be accessed using either dict...
>>> BaseHttpResponse.plugins['valid_ids']
set([304, 400, 404, 200, 301])

# ... or object notation
>>> BaseHttpResponse.plugins.valid_ids
set([304, 400, 404, 200, 301])

>>> BaseHttpResponse.plugins.classes
set([<class '__main__.NotFound'>, <class '__main__.OK'>,
     <class '__main__.NotModified'>, <class '__main__.BadRequest'>,
     <class '__main__.MovedPermanently'>])

>>> BaseHttpResponse.plugins.id_to_class[200]
<class '__main__.OK'>

>>> BaseHttpResponse.plugins.id_to_instance[200]
<OK: 200>

>>> BaseHttpResponse.plugins.instances_sorted_by_id
[<OK: 200>, <MovedPermanently: 301>, <NotModified: 304>, <BadRequest: 400>, <NotFound: 404>]

# Unregister the `NotFound` plugin
>>> NotFound._unregister_plugin()
>>> BaseHttpResponse.plugins.instances_sorted_by_id
[<OK: 200>, <MovedPermanently: 301>, <NotModified: 304>, <BadRequest: 400>]

# Coerce the passed value into the right instance
>>> BaseHttpResponse.coerce(200)
<OK: 200>

Please see the tests and beam_integrals source code for more examples.

Contribute

If you find any bugs, or wish to propose new features please let me know.

If you’d like to contribute, simply fork the repository, commit your changes and send a pull request. Make sure you add yourself to AUTHORS.

Metadata

Release files for simple_plugins 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple_plugins 1.0.3
File Size Uploaded
simple_plugins-1.0.3.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple_plugins 1.0.3
File Interpreter ABI Platform
simple_plugins-1.0.3-py2-none-any.whl Python 2 none any Details

Total release size: 12.1 kB

Release files / simple_plugins-1.0.3.tar.gz

Download URL simple_plugins-1.0.3.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
16c86f86fafbf14af3a19b967ec4fb4f10f93bfcc1b69ba8fada2bc6908b10e2
BLAKE2b-256 checksum
How to use checksums
fb7a45c44084e1c2c4c480e3db570f0cab8f90f8328d59cec05174b13a6545a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release files / simple_plugins-1.0.3-py2-none-any.whl

Download URL simple_plugins-1.0.3-py2-none-any.whl
Size 5.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
d024360881c7487702dacec5bc31ef7bf0e3a71c3d156dcd1067aa586676d2fd
BLAKE2b-256 checksum
How to use checksums
60d79242be3c284c5ed87deb31ba9a9c4ca6597e78e855f694227600e97688a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page