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
Install Flask-Plugin using pip:
pip install flask-plugin
Quick Start
-
Entering the
example
directory, you will find the following directory structure, the pluginhello
insideplugins
directory:example ├── app.py └── plugins └── hello ├── __init__.py └── plugin.json
-
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_='962e3b6cd8b74d02a5a02f1e3651ef87') if plugin: manager.load(plugin) manager.start(plugin) ... # API Management code here app.run()
-
Define plugin info in
SayHello/plugin.json
file:{ "id": "962e3b6cd8b74d02a5a02f1e3651ef87", "domain": "hello", "plugin": { "name": "Greeting", "author": "Doge", "summary": "Hello Flask-Plugin." }, "releases": [] }
-
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() ... # Other routes defined here @plugin.route('/say/<string:name>', methods=['GET']) def say(name: str): return 'Hello ' + name
-
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 Distribution
File details
Details for the file Flask_Plugin-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_Plugin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62d7efa7e49b9a599592ecaa204943f72114f83ae9ee1f2b119cbbd6a349f4a6 |
|
MD5 | 06ce8b333f4de69cd7210f51fbb078b8 |
|
BLAKE2b-256 | 85fd95bcc642aad65dc344b9d297302ad8142330ababd034d1be0c6ca3d59e23 |