A plugin's source is ordinary Python; the bundler flattens it¶
A plugin folder is written as an ordinary Python project. Every file imports what it uses, so it reads, lints, type-checks and tests on its own. Bundling is a mechanical step that turns that project into the single string Open-WebUI stores. Until now it was the other way round: function.py and tool.py had no imports of their own. They relied on shared.py and the libraries being pasted in above them, so an editor showed undefined names, ruff had to skip examples/, and an "organize imports" on shared.py could remove imports that only the next file used.
What this means:
- Ordinary imports stay where they are used. Standard-library and third-party imports go in each file. Repeating one in the bundle costs nothing, because Python looks a module up in
sys.modulesthe second time. - Imports of the plugin's own code are resolved by the bundler.
function.pyandtool.pywritefrom shared import NAME, which the editor and the tests can resolve. The bundler inlinesshared.pyonce and removes the line. Only top-levelfrom shared import NAMEandfrom owpp.lib import NAMElines are allowed. An alias (as), a plainimport sharedorimport owpp.lib, or either import inside a function body is an error, because removing the line would leave the name undefined, and so is a name defined both inshared.pyand in the file that imports it, because after flattening they would share one namespace. - Libraries are a real package, imported from one flat module. A plugin writes
from owpp.lib import PluginAssets, plugin_config. The bundler inlines the libraries in library order and removes the import. Each exported name belongs to one library, soowpp checkreports a name whose library is not ininclude:. The libraries import each other from their sibling modules (from .plugin_events import PluginEvents), which avoids circular imports through the package's__init__, and the bundler removes those imports too.shared_assetsandlive_reloadare Classic298's code, kept unmodified, so they are reached through thin wrapper modules. The wrappers say how to upgrade the vendored file. owpp is already a development dependency of any repository that tests its plugins, so editors there resolveowpp.lib. - The function and its tool are separate modules.
tool.pyis bundled on its own, with its own copy ofshared.py, and embedded in the function bundle as data, which the runtime installs as a separate tool. Sotool.pyandfunction.pycannot import from each other, and the bundler rejects that with a message pointing toshared.py. A module-level value inshared.pyexists once per module. State the two really share still goes throughsys.modules, the way thechat_datalibrary does. open_webui.*is what the mock provides. Open-WebUI is not installed for development. The mock Open-WebUI (owpp/testing/mock.py) has to cover everyopen_webuiname a plugin in this repository uses, and it is published as type stubs so an editor resolves the same names the tests run against. Its catch-all for missing names stays only for upstream code taken from git.- A file taken from git is not touched.
function: {file}andtool: {file}are bundled as they are, andowpp migrateleaves them alone. The files of a plugin folder, whether written here or taken whole from git withsource: {path}, are bundled as described above. - The new format is protocol 0.5 (owpp 0.5), with no compatibility period. owpp is still alpha, so the bundler does not support plugins without imports alongside the new ones.
owpp migrate's 0.3 → 0.5 step (there is no 0.4: owpp 0.4 left the format unchanged) upgrades them instead, and is the first step that rewrites Python files as well asplugin.yaml. For each offunction.pyandtool.pyit finds the names used but not defined there, and resolves them in this order: a nameshared.pydefines becomesfrom shared import ..., a library name becomesfrom owpp.lib import ..., and a nameshared.pyimports from elsewhere has that import copied over. It then removes the importsshared.pyno longer uses itself, and reports any name it cannot resolve instead of guessing. An older owpp refuses a 0.5 plugin instead of producing a broken bundle. {{file:NAME}}is deprecated, because it substitutes text into the source: use the templates library'splugin_template_text.
Considered Options¶
- Keep concatenation and document it: no tooling change, but the editor stays blind to the shared code, the libraries and their base classes, and the unused-import hazard remains.
- Embed modules and install an import hook (stickytape, pinliner, tsutsumu): keeps real module boundaries at run time, but
sys.modulesis shared by the whole Open-WebUI process, so two plugins'sharedmodules would collide. The deployed code would also be loader plumbing with the source held in strings, which an admin cannot easily review in Open-WebUI. - One module per library (
from owpp.lib.assets import PluginAssets): would letinclude:be worked out from the imports, but a plugin would need a line per library. The flat module keeps the import to one line, and the check againstinclude:works by name instead. from .shared import NAMEwith the folder as a package: scales better past one shared file, but adds an__init__.pyto every plugin and import ordering to the bundler. It can be added later if a plugin needs more than one shared module.