Bundling¶
Open-WebUI keeps a function or tool as one string of code, so the deploy turns a plugin folder into one file per function and per tool.
Order¶
A bundle is always, in this order, with no numbering or naming scheme to maintain:
- Docstring header, generated from the manifest's
function:(ortool:) keys. (Withfunction: {file}the upstream file's own header is kept.) from __future__lines found anywhere below, hoisted here (they are a SyntaxError after other code).- Libraries from
include:, in the library order (live_reload,shared_assets,core,routes,jobs,chat_data,static,templates,assets,config;assetsaddsshared_assetsandcore). A library is skipped if its end marker is already in the code (an upstream function that ships its own copy). shared.py, if present.function.py(ortool.py).- The plugin runtime, when the plugin has a tool or skills, with the tools and skills embedded as a JSON literal.
A function bundle and a tool bundle are separate Open-WebUI modules. They share code through shared.py (each gets a copy) and, where state must be shared, through sys.modules (the chat_data library does this for temporary chats).
Imports between the files¶
Each file imports what it uses, as in any Python project, so it reads, lints and type-checks on its own (why). That includes the plugin's own code:
# function.py
import json
from shared import PREFIX, _load
from shared import ... resolves in an editor and in tests. The bundle has no shared module: shared.py is already above the file, so the bundler removes the line. The same goes for from owpp.lib import ...: the libraries are inlined above, and Open-WebUI has no owpp (libraries). Removing an import is only safe for some forms, and the bundler refuses the others, naming the line:
- Only a top-level
from shared import NAMEorfrom owpp.lib import NAME. Notimport sharedorimport owpp.lib, not*, and not an import inside a function. - No
as. Once the line is gone, an alias would be undefined. - The name must be defined in shared.py, or be one owpp.lib exports. A library name also needs its library in the bundle (
include:, ortool.includefor the tool), and a name from the runtime needs a tool or skills. - No name both in shared.py and in the file. They become one namespace, so one would replace the other. Importing the same module in both (
import json) is fine. function.pyandtool.pycannot import each other. They are bundled into separate modules. Move what both need into shared.py.
{{file:NAME}} (deprecated)¶
In function.py or tool.py, {{file:NAME}} is replaced by the text of the sibling file NAME. It still works, but owpp check warns about it: it substitutes text into the source, so the file does not read as the Python that runs. Put the file in templates/ and read it with plugin_template_text("NAME") instead (templates); a tool adds include: [templates] under tool:. Files served over HTTP go in static/.
Tool bundles carry the runtime too¶
A tool bundle includes the runtime with only the ids to remove, so a tool that loads after a restart can notice its parent function was disabled while Open-WebUI was down, and remove itself.
Git sources¶
source: { git: https://github.com/owner/repo.git, ref: <40-char SHA>, path: dir }
gitis an https URL, an ssh URL oruser@host:path, read with thegitCLI (so any host works and ssh deploy keys need no new secret). Only thehttpsandsshprotocols are allowed.refmust be a full commit SHA. A branch or tag can move, and this code runs with admin rights, so anything else is refused. Upgrading is a reviewed change of the SHA:owpp pullmakes it, and lists the files that changed.- The files are fetched before bundling by a shallow fetch of that exact commit into a scratch repository, then embedded, so the deployed bundle is reproducible from the repo, the pinned commit and the owpp version that bundles it.
- With
plugin: truethe whole folder atpathis fetched and bundled as a local plugin would be, by the owpp reading the manifest. See a whole plugin from git. - Directory entries (
dir:) list the directory in that commit and take every regular file. Symlinks and submodules are skipped. Limits: 1000 files per skill, 2 MB per file. A file that is not UTF-8 is embedded as base64.
Different plugins may pin different commits of the same repo; one fetch is made per git#sha.
Skills¶
A skill is installed as its whole folder, as Open-WebUI stores it (a files list: SKILL.md plus references, templates, examples). SKILL.md is stored verbatim, front matter included; name and description come from that front matter. An update sends the whole file set with the skill's current version (expected_version_id); a skill whose files and name already match is left alone.
Assets¶
assets/loader.js and assets/custom.css are this plugin's fragments of the Shared Assets Protocol's two shared files. They are embedded in the function bundle as a JSON literal (__ASSETS_DATA__), together with the settings from the manifest's assets: key, and published by the assets library. The protocol block (shared_assets) and core are added with it; live_reload is opt-in. A plugin with an assets/ folder and no function.py gets a generated Event(PluginAssets).
Config¶
config.yaml is parsed during bundling (a YAML or shape error stops the bundle) and embedded as a JSON literal (__CONFIG_DATA__). The config library reads it with plugin_config().
Static files and templates¶
Files under static/ are embedded in the function bundle as a JSON literal (__STATIC_DATA__, with the prefix and the access level from static:) and served by the static library. Files under templates/ are embedded the same way (__TEMPLATES_DATA__) and read back with plugin_template_text(); nothing serves them.
What the deploy script does with a bundle¶
For each plugin function: not present is created, activated, and made global if it is a filter; present with different code is updated (comparison ignores line endings and trailing whitespace, and applies Open-WebUI's own import rewriting to the local copy first); identical is left alone. Valves stored in the database are never overwritten except for keys the manifest declares. See what a deploy does.