An extension to add support of Plugin in Flask.
Project description
Flask-Plugin
An extension to add support of Plugin in Flask.
Features:
- Define plugin routes in the same way as Application, Blueprint, while providing all the Flask features (Template rendering, url_for, message flashing, signals, etc.)
- Each plugin can be started, stopped, reloaded while Flask is running.
- Configured with Flask, no need to configure separately.
- Auto-discovery and management for plugins.
Install
Download from git repo and install:
git clone https://github.com/guiqiqi/flask-plugin
python3 flask-plugin/setup.py install
Or download Wheel package from releases and install using pip:
pip install flask_plugin-{{ VERSION }}-py3-none-any.whl
which {{ VERSION }}
is release version.
Quick Start
-
Entering the
example
directory, you will find the following directory structure, the pluginhello
insideplugins
directory:example ├── app.py └── plugins └── hello ├── __init__.py ├── static │ └── test.txt └── templates └── index.html
-
The plugin manager is loaded in the
app.py
file, and the hello plugin is started:from flask import Flask from flask_plugin import PluginManager app = Flask(__name__) manager = PluginManager(app) plugin = manager.find(id_='347336b4fcdd447985aec57f2bc5793c') if plugin: manager.load(plugin) manager.start(plugin) ... # API Management code here app.run()
-
Instantiated the
Plugin
inSayHello/__init__.py
and define the route as you did inFlask
:from flask_plugin import Plugin from flask import redirect, url_for plugin = Plugin( id_ = '347336b4fcdd447985aec57f2bc5793c', domain='hello', name='Greeting', static_folder='static', template_folder='templates' ) ... # Other routes defined here @plugin.route('/', methods=['GET']) def index(): return render_template('index.html', name='Anonymous')
-
Accessing
/plugins/hello/
and see the greeting:Hello Anonymous!
Stop the plugin with accessing
/api/stop/347336b4fcdd447985aec57f2bc5793c
, check url above again, and get aHTTP 404
error.
Documentation for Flask-Plugin avaliable on: Flask-Plugin Documentation
Thanks
This project is based on many open source projects of the Pallets group, and I would like to express my thanks here.
Also thanks to my family and friends.
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
Built Distributions
Hashes for Flask_Plugin-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9297bc616061f41a11ef35e64e3f6c7dde79bac6e2cca9a7a8e76b1783c371fc |
|
MD5 | e3b5dc4ab5d9115caf82a71b30a25665 |
|
BLAKE2b-256 | 7ba2a4108c0e6eec5cad86a314a7bc5ebc932a4b8f425c018195d6b09e4940aa |