staugur / Flask-PluginKit

Web program plugin development kit based on Flask.

Home Page:https://flask-pluginkit.rtfd.vip

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Utilizing code from main app within plugin

blitzmann opened this issue · comments

Hi there,

I'm looking at this project to possibly use for integrating with an existing Flask application. It seems pretty robust, but I do have a question tho.

It's going to be a bit difficult to explain as it's mostly theoretical, just thinking about ways I can utilize this. Lets say that the main program has a service that plugins should be able to access. For example, a background task runner. The main Flask application can, on startup, spin up a background task service (a singleton), and accept request to run tasks. A plugin could then send data to this background task runner.

This could be fairly easy with local plugins, since you can import directly from the parent application and module. What I'm interested in learning more about is how one might do this for a third party plugin that is on pypi. How would that plugin, which is more or less isolated from the main application, access things from the main application? Is having a third party plugin not feasible in this situation, and a local plugin should be pursued?

Sorry if this doesn't make any sense. If not, let me know, maybe I can stand up a simple example :)
Thanks!

Hi there.

I probably understand what you mean, but it may not be very accurate (from China, English is not good).

The core of my analysis of your question is: how do third-party plugins import local modules?

If this is the problem, maybe I have tried, like this plugin: flask-pluginkit-isso,
the code is:

from __future__ import absolute_import
try:
    from config import PLUGINS
except ImportError:
    PLUGINS = {}

When I use it, there is a config.py locally in the project.

Hi, if the problem is solved, please tell me to close this issue.