extender: A simple plug-in/extension system on Python
Project description
extender
========
A simple plug-in/extension system on Python inspired by Sentry project.
[![Build Status](https://travis-ci.org/messense/extender.svg)](https://travis-ci.org/messense/extender)
[![Coverage Status](https://coveralls.io/repos/messense/extender/badge.png)](https://coveralls.io/r/messense/extender)
## Installation
In your terminal run
```bash
pip install https://github.com/messense/extender/archive/master.zip
```
Or simply install it from PyPi by executing `pip install extender`
## How to write a plugin
A plugins layout generally looks like the following:
setup.py
pluginname/
pluginname/__init__.py
pluginname/plugin.py
The __init__.py file should contain no plugin logic, and at most, a `__version__ = ‘x.x.x’` line.
For example, if you want to pull the version using pkg_resources (which is what we recommend), your file might contain:
```python
try:
__version__ = __import__('pkg_resources') \
.get_distribution(__name__).version
except Exception:
__version__ = 'unknown'
```
Inside of plugin.py, you’ll declare your Plugin class:
```python
# -*- coding: utf-8 -*-
from extender import Plugin
import plugin1
class PluginName(Plugin):
title = 'Plugin Name'
slug = 'pluginname'
description = 'My awesome plugin!'
version = plugin1.__version__
author = 'Your Name'
author_url = 'https://github.com/yourname/pluginname'
def test_func(self, msg):
return msg
```
And you’ll register it via entry_points in your setup.py:
```python
# -*- coding: utf-8 -*-
from setuptools import setup
setup(
name='pluginname',
version='0.0.1',
author='Your name',
author_email='Your Email address',
url='https://github.com/yourname/pluginname',
packages=[
'pluginname'
],
description='plugin description',
install_requires=[
'extender',
],
include_package_data=True,
entry_points={
'extender.plugins': [
'pluginname = pluginname.plugin:PluginName',
]
},
)
```
You can change entry_points key `extender.plugins` to whatever you want.
That’s it! Users will be able to install your plugin via `pip install <package name>`.
## How to install plugins in your code
```python
from extender import install_plugins
install_plugins('extender.plugins')
```
The `install_plugins` function takes an argument `entry_point` to install all plugins(just some python package)
registered to that entry_point automatically.
## How to invoke a method of plugins
```python
from extender import plugins
""" invoke func_name(1, 2), return the result of the first called method """
result = plugins.first('func_name', 1, 2)
""" invoke func_name(1, msg='hello'), no return """
plugins.call('func_name', 1, msg='hello')
```
## LICENSE
The MIT License (MIT)
Copyright (c) 2014 messense
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
========
A simple plug-in/extension system on Python inspired by Sentry project.
[![Build Status](https://travis-ci.org/messense/extender.svg)](https://travis-ci.org/messense/extender)
[![Coverage Status](https://coveralls.io/repos/messense/extender/badge.png)](https://coveralls.io/r/messense/extender)
## Installation
In your terminal run
```bash
pip install https://github.com/messense/extender/archive/master.zip
```
Or simply install it from PyPi by executing `pip install extender`
## How to write a plugin
A plugins layout generally looks like the following:
setup.py
pluginname/
pluginname/__init__.py
pluginname/plugin.py
The __init__.py file should contain no plugin logic, and at most, a `__version__ = ‘x.x.x’` line.
For example, if you want to pull the version using pkg_resources (which is what we recommend), your file might contain:
```python
try:
__version__ = __import__('pkg_resources') \
.get_distribution(__name__).version
except Exception:
__version__ = 'unknown'
```
Inside of plugin.py, you’ll declare your Plugin class:
```python
# -*- coding: utf-8 -*-
from extender import Plugin
import plugin1
class PluginName(Plugin):
title = 'Plugin Name'
slug = 'pluginname'
description = 'My awesome plugin!'
version = plugin1.__version__
author = 'Your Name'
author_url = 'https://github.com/yourname/pluginname'
def test_func(self, msg):
return msg
```
And you’ll register it via entry_points in your setup.py:
```python
# -*- coding: utf-8 -*-
from setuptools import setup
setup(
name='pluginname',
version='0.0.1',
author='Your name',
author_email='Your Email address',
url='https://github.com/yourname/pluginname',
packages=[
'pluginname'
],
description='plugin description',
install_requires=[
'extender',
],
include_package_data=True,
entry_points={
'extender.plugins': [
'pluginname = pluginname.plugin:PluginName',
]
},
)
```
You can change entry_points key `extender.plugins` to whatever you want.
That’s it! Users will be able to install your plugin via `pip install <package name>`.
## How to install plugins in your code
```python
from extender import install_plugins
install_plugins('extender.plugins')
```
The `install_plugins` function takes an argument `entry_point` to install all plugins(just some python package)
registered to that entry_point automatically.
## How to invoke a method of plugins
```python
from extender import plugins
""" invoke func_name(1, 2), return the result of the first called method """
result = plugins.first('func_name', 1, 2)
""" invoke func_name(1, msg='hello'), no return """
plugins.call('func_name', 1, msg='hello')
```
## LICENSE
The MIT License (MIT)
Copyright (c) 2014 messense
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
extender-0.0.2.zip
(16.7 kB
view details)
extender-0.0.2.tar.gz
(8.2 kB
view details)
File details
Details for the file extender-0.0.2.zip
.
File metadata
- Download URL: extender-0.0.2.zip
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba36e586594d2d47d3c2b73ceb2c6e8886eb652fa73def161e4121e10831f2e5 |
|
MD5 | 52f56ce8edd653c5d9553cd4606617ca |
|
BLAKE2b-256 | f41295e5e61c9619d3179e4dc0e3d985c5cee5eae8ce1cc9e55bf7ce96fc97f5 |
File details
Details for the file extender-0.0.2.tar.gz
.
File metadata
- Download URL: extender-0.0.2.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7658ab6dfa0091437f2ae47310d6dc671edb05c1e6d1111d13a0f10f89885c5e |
|
MD5 | 8d5d169daf575eb07582730d0452d070 |
|
BLAKE2b-256 | ddea89b4c7e197010f6b6dc301e288d68cee6278d6ebe0a44da968cb574ebda0 |